LAI has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: On-the-fly Wav to mp3 encoding
by theorbtwo (Prior) on Nov 28, 2002 at 18:02 UTC | |
by LAI (Hermit) on Nov 28, 2002 at 22:16 UTC | |
by crenz (Priest) on Nov 28, 2002 at 23:56 UTC | |
|
Re: On-the-fly Wav to mp3 encoding
by hawtin (Prior) on Nov 28, 2002 at 17:37 UTC | |
by LAI (Hermit) on Nov 28, 2002 at 20:45 UTC | |
|
Re: On-the-fly Wav to mp3 encoding
by valdez (Monsignor) on Nov 28, 2002 at 20:56 UTC | |
|
Re: On-the-fly Wav to mp3 encoding
by LAI (Hermit) on Nov 28, 2002 at 15:58 UTC |