Click to See Complete Forum and Search --> : Audio Output via CGI
Hey guys, I was just wondering if anyone knew if (1) it was possible to output audio files (e.g., .wav, .au, etc.), and (2) if so, could you point out any resources, articles, tutorials or any code?
Thanks,
[Jona]
jeffmott
06-26-2003, 09:55 PM
Of course it's possible. Most CGI scripts work under the assumption that the user is executing them on behalf of a browser, and thus return HTML. But there is nothing to say a CGI program is restricted to HTML.
For HTML you output the text/html content-type header followed by the HTML data. Just the same you could output an audio/x-wav header followed by wav data.open WAV, 'sound.wav' or die $!;
binmode WAV or die $!;
flock WAV, LOCK_SH or die $!;
binmode STDOUT or die $!; # not entirely sure if this
# is necessary, but couldn't hurt
print "Content-Type: audio/x-wav\n\n";
print while <WAV>;
Originally posted by jeffmott
For HTML you output the text/html content-type header followed by the HTML data. Just the same you could output an audio/x-wav header followed by wav data.
Well I realize that. I knew it was possible. Silly of me. Anyways, I tried your code and apparently it doesn't work...
[Jona]
On line six (the below line), I am getting the error, "Invalid arguments":
flock WAV, LOCK_SH or die $!;
[Jona]
jeffmott
06-26-2003, 11:37 PM
Well you will have to load the Fcntl constants for flock to use them.use Fcntl ':flock';
Oh I see! All right, the only thing I don't see now is two things: One: I don't see any logic involved. :p Two: Do you know how I would go about editing a WAV file? Sorry, but I couldn't find any tutorials online or anything... I need a book. :rolleyes:
[Jona]
jeffmott
06-27-2003, 12:16 AM
One: I don't see any logic involvedWas this a real question?Two: Do you know how I would go about editing a WAV file?I don't believe I've used enough different sound editors to difinitively say which is the best of them all, but from what I have seen Sound Forge (http://www.sonicfoundry.com/Products/showproduct.asp?PID=668) is easily the greatest of them all and is what I use.
Well, no not really.
Um... I wasn't exactly talking about a sound editing program. That has nothing to do with it. lol. I was wondering if you knew how to use CGI to edit the audio file. I don't need anything advanced--just enough to show how to code a few things so that I know how to make different sounds. I know it won't be very simple, but all you have to do is show me the code that does it. :D
(Or actually, you don't have to, but... I was wondering if you would. :rolleyes: )
[Jona]
jeffmott
06-27-2003, 08:16 AM
I've never tried manually defining a sound from within a program, nor will I ever. You would have to manually define 44,100 individual samples just to achieve one second of sound (assuming you wanted CD quality audio). So I would think your only option would be to have an archive of pre-existing sounds, and then your program can piece them together different in whatever way it chooses. For this, though, you will have to be able to encode/decode. You can try searching the modules at CPAN (http://search.cpan.org/) or try to find the specification for whatever audio format you're looking to manipulate.
Originally posted by jeffmott
You can try searching the modules at CPAN (http://search.cpan.org/) or try to find the specification for whatever audio format you're looking to manipulate.
Yes, I've tried and found a few interesting modules, but I can't get any of them to work--because I don't know how to install them. I looked at the "source" of the modules, but it appears to be documentation having nothing to do with the programming. Do you know how I would retreive the source code of the modules?
All of the default modules are installed on the server, but Audio and Midi, for example, are not because they are apparently non-standard modules.
[Jona]
jeffmott
06-27-2003, 02:31 PM
The full source for the MIDI module is there, but is mixed in with the POD so you may have passed over it. Other modules, such as many, if not all, from the Audio:: series have their routines written in C. If in any module you see DynaLoader being imported, this is the case. These modules will have a .dll file with the same name as the module that must go with the .pm
Some modules also require the use of the make utility to install, which are standard on Unix based systems, but not on Windows machines. You'll have to download cygwin (http://www.cygwin.com/) to get the Unix utilities.
My server is Linux based, so it has shell extensions installed--if that is what is needed. How would I "install" the MIDI Perl Module?
[Jona]
jeffmott
06-27-2003, 06:02 PM
The MIDI module is pure Perl, so installing it is as simple as copying the PM files into any directory that your script searches for library files.
All right, I'll take a swing at it and see what I can come up with..
[J]ona
jeffmott
06-27-2003, 06:23 PM
If this is a hosted server and your own on your machine then you can probably make a request to the webmaster there to install any given module on their system. If you pay for the service anyway. If it's a free host it is doubful they'll answer your requests.
Well, I've got a real host for testing right now, but I'll soon purchase a domain. My brother has a big project he wants me to do, so eventually I'll have a dedicated host with tons of bandwidth and stuff. Will probably take two years to complete--he doesn't just want a Web site, he wants a Flash intro, subscriptions, login, register, find-password, forum, PC game programmed in C++, the same game programmed in Flash for online gameplay (but a less enhanced version of course), and each person with an individual character. Oh joy, I will have work to do... But I'm happy to learn! Especially if he is going to pay for the hosting and everything. Hehe.. Now, if only I could get my game published on the Gamecube, PS2 and XBox.. :p
Anyways, though, I think you get the point... A little off topic I was. :rolleyes: I'll send the admin a request or ask him how I would go about installing it on the server I've got.
[J]ona