Decode MP3s with Ruby

Posted by – September 21, 2007

Here is an example of decoding mp3s using ruby. First make sure to install icanhasaudio. It should just be a “gem install icanhasaudio”. Here is the code:

require 'rubygems'
require 'icanhasaudio'

reader = Audio::MPEG::Decoder.new
reader.decode(File.open(ARGV[0], 'rb'), $stdout)

icanhasaudio just takes two IO streams, an input and an output. In our case the input is the file provided on the command line, and the output is STDOUT. To use the script, simply do:


$ ruby decoder.rb phil_collins.mp3 > phil_collins.wav
[/sourcecode]

1 Comment on Decode MP3s with Ruby

  1. jax says:

    su su sudeo energy drink!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>