Code Monkey home page Code Monkey logo

Comments (5)

movstox avatar movstox commented on May 30, 2024

@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.

jstrait avatar jstrait commented on May 30, 2024

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.

jstrait avatar jstrait commented on May 30, 2024

@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.

jstrait avatar jstrait commented on May 30, 2024

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.

movstox avatar movstox commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.