I'm working on a really fun mini-project. Right now breaks in the warehouse at work are signaled by a .wav of a train piped over the PA system. The workers have been bitching about that train, and I decided to do something different. I spent a couple of hours yesterday collecting a few dozen .wav files and storing them on one of the web servers. I've written a hideously simple script to just choose one at random and pipe it out.

What I need, though, is to be able to output in mp3 format. The machine connected to the PA is a Windows box, and the sndrec32 program has no idea what a URL is. I wouldn't mind doing it with Winamp, but Winamp wants mp3s from its URLs. So far, I haven't been able to find a module or script that will easily encode mp3s on the fly, either here or on CPAN. Has anyone come across something that'll work?

Here's the script I hacked up (Yes, I actually get paid to do this!):

#!/usr/bin/perl -w use strict; open LS, "/bin/ls wav/*.wav |"; @::wavs = <LS>; close LS; local $::wav = $::wavs[rand $#::wavs]; spew_wav(); #spew_mp3(); #redir_wav(); sub spew_wav { print "Content-type: audio/x-wav \n\n"; open WAV,"/bin/cat $::wav |"; print while <WAV>; close WAV; } sub spew_mp3 { print "Content-type: audio/mpeg \n\n"; open WAV,"/usr/local/bin/bladeenc $::wav |"; print while <WAV>; close WAV; } sub redir_wav { print "Location: $::wav \n\n"; }

So I've got three ways of spewing out information. Right now, the two wav methods work fine, because it's just read, spew. Bladeenc doesn't work so well for the mp3ing, though, because the wavs have a few different frequencies and bladeenc wants to know what the frequency is. Also, I'd really like to be able to do the encoding using perl, rather than third-party software.


LAI
:eof

In reply to On-the-fly Wav to mp3 encoding by LAI

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.