Forum Moderators: coopster
To merge two sounds but keep the sound files separated on the server, it's easiest to do it with a client-side player built with Flash. You can use PHP to find and/or choose the two sound files, pass the file names into Flash in the querystring, and have them both load and play (or loop) simultaneously in the Flash player.
There are obvious reasons why mixing sound files is useful, but I can't guess why you're trying to do it with PHP. Perhaps you could reply with a more detailed description of your project.
I have an image with random characters (think Yahoo signup page). But, for obvious reasons I can't put the characters in plain text anywhere (or else I would've used the alt attribute). So, I have made one sound file for each character. Say that the string is "foobar". I need to be able to play f.wav o.wav o.wav b.wav a.wav r.wav as one single sound file. It is not feasible to make one file for each combination (not only because it would be cumbersome, but because there are thousands and thousands of combinations). The Flash idea would be easy, but I can't pass a query string back to the page. The merging has to be done on the server.
Now, I know there are command line tools I can use. I already found one that works great for joining wav files. However, this method requires saving the merged file to some output file. True, I can delete the file once it's been used, but I'd rather do something that worked "on the fly".
So, let me just make sure I am with you.
User comes to the site and can click on the link to read the letters that they need to type.
The script randomly gens the string 'foobar' and grabs the f-o-o-b-a-r, all wav's, and cats them together and creates a new file.
You tested slamming them together and only the first wav plays. Makes me think there is an end file char that is killing it.
So essentially it needs to grab the first letter, read contents, get rid of end char, get next letter, read contents, when at last letter leave end char and write the new file.
Currently I have a script that merges a number of files, and outputs the data to a new file. But, this is just for testing purposes. Once I have something that works, I'll replace the saving stage with passthru(). However, I have yet to find a way of successfully merging/joining multiple wav files together. So far, only the first file is played.
I also have this command line tool that I can use. It is written in C, and it takes arguments for joining a number of wav files. However, it writes the output to a new file. True, I could then open this new file with PHP, grab the data, delete the file, and then send the data to the browser. But that seems like being a roundabout way of doing things.
I would rather do one of the following:
1) find a way of merging the files in PHP, and just pass the data on to the browser
2) find a way of redirecting the output from the other program. Instead of having it write data to a file (which I would then have to open in PHP) I would like it to simply
return the output, which can then be passed on straight to the browser If I knew C I could either convert the C script to PHP, or rewrite the C script to write the data to STDOUT instead.
[search.cpan.org...]
I'll post the URL here in case someone else runs into the same problem :)
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=71&lngWId=6
Thanks so much for your help! :)
WAV files have headers that determine what the rest of the file contains, so simply concatenating the files won't work -- As you've mentioned.
Combining two WAV files would require reading both files, and then building a new header based on the information in each. This would require a bit of processing. And even though you'd prefer not to use your command-line tool to create the file, then delete it, your command-line tool is written in compiled C instead of interpreted PHP. This means that, even though it's a roundabout way, it's likely to be faster and more efficient as far as server processing time is concerned and is probably your best bet.
Also.. not sure how your command-line programs outputs, but if the output could be redirected to a the standard output, it could be read in as a variable in PHP, bypassing the need to create and delete a file.
For one thing - and this should be obvious - not everyone has speakers on their computer. Many people access the web from the public Library or cafe, and most of the time these are silent machines. And moreso ... you've alienated every deaf or hearing-impaired person who tries to use your site.
If you want someone to confirm a random string in order to confuse harvesting robots, do what the experts do. Create a graphic that has your word in it, but obfuscated in some way that makes it readable to a human brain, but not to a harvesting OCR program. A great example of this is when you sign up for a Yahoo ID or a Yahoo forum.
I understand what you're trying to do, and this is an interesting intellectual exercise, but seriously I think you're solving the problem in an inappropriate way.For one thing - and this should be obvious - not everyone has speakers on their computer. Many people access the web from the public Library or cafe, and most of the time these are silent machines. And moreso ... you've alienated every deaf or hearing-impaired person who tries to use your site.
If you want someone to confirm a random string in order to confuse harvesting robots, do what the experts do. Create a graphic that has your word in it, but obfuscated in some way that makes it readable to a human brain, but not to a harvesting OCR program. A great example of this is when you sign up for a Yahoo ID or a Yahoo forum.
I think he's doing it as an alternative to the "random string in an image" approach since screen readers cannot read those images. (because alt text would be harvested by the bots)
It's a unique approach. I like it.
This way, the page should be accessible for anyone, no matter if they are blind or deaf, or dyslexic, or whatever it may be.