Code Monkey home page Code Monkey logo

Comments (2)

jstrait avatar jstrait commented on May 30, 2024

Thanks for opening the issue! (And sorry for the delay in responding!)

To get the duration of a file you should be able to do:

Reader.new('file.wav').total_duration

This will return a Duration object. However, the data it returns will be like what you'd see on a stopwatch. E.g. fields for the hours, mintues, seconds, milliseconds equivalent to "01:20:25.543" on a stopwatch. So if you wanted to know the total milliseconds you would have to calculate it manually by multiply the milliseconds x seconds x minutes x hours.

This will give a Format object describing the format of the data being read:

format = WaveFile::Reader.new('file.wav').format
puts format.channels   # For example, '2'
puts format.stereo?     # For example, true
puts format.bits_per_sample   # For example, 16
etc.

However, note that it will return the format the sample data is being read out as, which might be different from the actual format in the file.

For example, this will read that sample data in the same format as what's actually in the file:

Reader.new('file.wav')

While this will read out as mono 16-bit PCM, regardless of the sample format in the file:

Reader.new('file.wav', Format.new(:mono, :pcm_16, 44100))

So in the 2nd case, calling .format would return a Format object that indicates 1 channel, 16 bits per sample, etc.

Hope this helps!

from wavefile.

Phrogz avatar Phrogz commented on May 30, 2024

Oh…how embarrassing. How could I have missed those? While IMHO they might be better served mixed into the top-level class itself, and perhaps Duration could have a method that does the math itself, it seems that my requests are fully handled already. Kudos! :)

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.