From: John Joyce Date: 2007-12-15T10:48:14+09:00 Subject: Re: Work with Audio Files On Dec 14, 2007, at 7:12 PM, Konrad Meyer wrote: > Quoth Petr Kout: >> Lloyd Linklater wrote: >>> Petr Kout wrote: >>>> Hi, >>>> >>>> I am new to Ruby on Rails and I consider converting my application >>>> written in Java into Ruby. The question is, however, is there >>>> any plugin >>>> or other way to handle MP3 and other audio files? I need to Ruby >>>> to be >>>> able to tell me how long the uploaded MP3 is and ideally, give >>>> me the >>>> possibility to cut the file on the server if it's too long. I >>>> looked all >>>> over Google, nothing found. Thank you very much for any advice. >>> >>> http://www.ruby-forum.com/topic/130804#new >> >> Hi, >> >> thank you for the link, but it's not what I was looking for. I do not >> need to play the mp3 file. I need to be able to analyze it on the >> backend; that is, to get its length in seconds, and possibly >> truncate it >> (not necessary). I was doing it in Java so far. If I can't do this on >> the backend, I can't switch to Ruby, which is what I would love to >> do. >> >> Thanks. >> >> Peter > > There is a great library out in the wild called "metadata" that you > can use to > get information about mp3s (as well as many other filetypes) that I > think is > available in gem form. You might take a look at that. > > If you want to truncate a constant bitrate mp3, AFAIK they are > structured such > that you *could* crudely lop off some bytes from the end (channels * > time_to_clip * bitrate bytes). If not, you'll need to use some sort of > external mp3 library. I don't know of any that exist with ruby > bindings. You > might look at LAME though I'm not sure how much that will do. > > HTH, > -- > Konrad Meyer http://konrad.sobertillnoon.com/ Remember, keyword there was CONSTANT bitrate, variable bitrate might give you more trouble doing that without more care. Be sure any meta data matches changes or some apps might complain about the audio file.