freakingwildchild has asked for the wisdom of the Perl Monks concerning the following question:

I've been thinking about using Perl to visualize audio (or in other words "convert" audio to a jpg, png or maybe even svg).
What would be the best way to extract audio from a MP3/WAV or other audio files and convert them into waveforms as graphic?

Converting could be done by FFMPEG, still, the clean export of such waveform seems to be more complicating than I've originally thought.

Any tips from you perlmongers ? Where to start ?
CPAN didn't really cast any light for this one ...
http://www.alharris.com/images/waveform.gif is an example of such waveform..

I'll be dedicating/collecting info towards this thread for any future topics around this since perlmonks seems to be rather poor (yet) around audio/visual processing...

Thanks in advance, Wildchild

Replies are listed 'Best First'.
Re: What about visualizing audio?
by atcroft (Abbot) on Jan 25, 2009 at 21:00 UTC

    A quick search included a link suggesting to someone asking a similar question to look in the Audio modules on CPAN. Looking at some of those in the Audio group, some that looked potentially promising including Audio::Analyzer, Audio::DSP, Audio::File, and Audio::FindChunks. Don't know how many would apply to what you want to do, but hope tat helps a little.

      Audio::Analyzer seems to be most to it's use although it would require lots of reprogramming before getting there because it is PCM based only. Converting to PCM would also loose a lot of the quality of it's original intend, which would make me prefer more towards Audio::FindChunks using RMS which could be use to visualize to waveforms, I'll see if it could fit the purpose soon after testing a bit with it...

      Audio::File and Audio::DSP "could" be used but they would require a lot of programming work before getting to the result.
      These two taste raw and bloody; although not like I like my steak which also needs to be bloody as hell :p

Re: What about visualizing audio?
by GrandFather (Saint) on Jan 25, 2009 at 20:38 UTC

    To what purpose? There is a lot of information in an audio signal and whatever you do to present the signal visually will emphasize some aspects of that information while masking others. There is no "best" solution where the desired result is undefined (unless it is to do nothing - that's often good ;) ).


    Perl's payment curve coincides with its learning curve.
      It's easier for audio pro's to analyze an audio file in advance, like with Cooledit (Audition), Sonic Foundry, Live or any other equivalent to view it's waveform. Out of such waveform you could find the bpm, loop points, how heavy compressed the audio is, even if it's ambient or techno. Examples of such waveform could be found at http://images.google.be/images?q=audio+waveform

      I'd only visualize the waveform as it's pure form in a 400x80.png box for example; although other operations like FFT form etc are always welcome too, for those who need that more...

      I'd say Perl is mature enough to process such information flawless although I'm unable to find any links ...

Re: What about visualizing audio?
by zentara (Cardinal) on Jan 26, 2009 at 15:21 UTC
    Perl itself, is too slow for good audio/visual processing, because of the extra context baggage it places on variables. Your best bet is to use PDL, which will handle the data in Fortran. See PDL::Audio and Manipulating Audio Data in Perl.

    My first thought is to read the audio into a audio piddle, with PDL::Audio, then use something like PDL::IO::Pic; to write it to a graphic file, after you tranform the audio piddle to numbers suitable for graphic display. PDL also will do fast FFT for you.

    The PDL maillist is very active, and I'm sure that is the best place to look for guidance.


    I'm not really a human, but I play one on earth Remember How Lucky You Are