Comments (5)
@jstrait I've also tried same sample but a bit different way. Seems like playback is just accelerated proportionally.
Writer.new("output.wav", Format.new(:stereo, :pcm_16, 44100)) do |writer|
Reader.new("input.wav").each_buffer(4096) do |buffer|
writer.write(buffer.convert!(Format.new(:stereo, :pcm_16, 44100)))
end
end
info('input.wav')
info('output.wav')
Output:
File: input.wav
Audio Format: 1
Channels: 1
Bits per sample: 16
Samples per second: 8000
Bytes per second: 16000
Block align: 2
Sample frame count: 1134880
Play time: 00:02:21:860
File: output.wav
Audio Format: 1
Channels: 2
Bits per sample: 16
Samples per second: 44100
Bytes per second: 176400
Block align: 4
Sample frame count: 1134880
Play time: 00:00:25:734
Btw, conversion worked for me via SoX library sox input.wav -b 32 -r 44100 output.wav
:
File: input.wav
Audio Format: 1
Channels: 1
Bits per sample: 16
Samples per second: 8000
Bytes per second: 16000
Block align: 2
Sample frame count: 1134880
Play time: 00:02:21:860
File: output.wav
Audio Format: 1
Channels: 1
Bits per sample: 16
Samples per second: 44100
Bytes per second: 88200
Block align: 2
Sample frame count: 6256026
Play time: 00:02:21:860
Thank you in advance for any help.
from wavefile.
Hey @dbreaker, do you know what the sample rate of data/twilio_recording.wav
is? Is it 16,000Hz, or something different? The reason I ask is that in your example data/copy.wav
is being written with a sample rate of 16,000Hz (i.e. the 3rd argument to Format.new
):
Writer.new(new_file, Format.new(:mono, :pcm_16, 16000))
If the sample rate of data/twilio_recording.wav
is lower than 16,000Hz, then data/copy.wav
would sound sped up, like you mentioned. Conversely, if data/twilio_recording.wav
has a sample rate higher than 16,000Hz it will sound slowed down.
from wavefile.
@movstox the gem just writes whatever sample rate you give it into the resulting wave file. For example, if you have incoming sample data that had an original sample rate of 44,100Hz, and you write it out to a file using Writer
with a sample rate of 22,050Hz, then the resulting file will have the same sample data as the original, but the sample rate will be set to 22,050Hz. This means that when played back with an audio player it will sound twice as slow with a lower pitch. (Conversely, a sample rate of 88,200Hz would sound twice as fast with a higher pitch). Unlike other parameters like bits per sample or number of channels, the gem won't attempt to convert the sample data so that it sounds the same with the new sample rate.
From your example Sox appears to be re-sampling the file to use the new sample rate (i.e. 44,100Hz instead of 8,000Hz) so that it has the same pitch. I say that because in the original, there are 1,134,880 sample frames, while in the output there are 6,256,026 sample frames. This would be consistent would adding additional samples so that the file sounds the same, even though the sample rate is higher.
from wavefile.
Since I believe that I answered the questions, and there haven't been any follow up comments in several months, closing this out.
from wavefile.
Thanks for your help.
On 31.10.2015 at 19:19 GMT None wrote:
Since I believe that I answered the questions, and there haven't been any follow up comments in several months, closing this out.
—
Reply to this email directly or #15 (comment)<>.
from wavefile.
Related Issues (20)
- Possible bug when no block is given to the writer? HOT 2
- No high-level duration info HOT 2
- fyi: ruby-wavefile now packaged for Debian HOT 1
- support reading from a file or stream HOT 5
- Duration does not override equality HOT 2
- UnsupportedFormatError HOT 8
- Method to obtain markers/cue points HOT 6
- each_buffer causes ReaderClosedError HOT 3
- Reference for older methods HOT 4
- examples: how create reverse file? HOT 2
- Mix 2 wav files. HOT 2
- Rewind the IO object HOT 4
- Format Chunks With Extra Bytes at the End Sometimes Cause `InvalidFormatError` to be Raised HOT 1
- `Reader` instances can be created for WAVE_FORMAT_EXTENSIBLE files that have an incomplete/missing format chunk extension HOT 1
- Bufer from bytes & mulaw HOT 2
- WaveFile::Reader doesn't work with pipe IO HOT 2
- Sample Data Can't Be Read From a WAVE_FORMAT_EXTENSIBLE File With an Oversized Format Chunk Extension HOT 1
- How i can play file HOT 1
- Misleading error message if "fmt " chunk extension is too large to fit into chunk HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wavefile.