Re: Combining sound files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 9:49 PM +0000 2/25/07, Colin Guthrie wrote:
tedd wrote:
 Hi gang:

 I can combine two mp3 sound files together by simply:

 // load  first

 $file = "a.mp3";
 $handle = fopen($file, "rb");
 $size = filesize($file);
 $load = fread($handle, $size);
 fclose($handle);

 // load second

 $file = "b.mp3";
 $handle = fopen($file, "rb");
 $size = filesize($file);
 $load .= fread($handle, $size);
 fclose($handle);

 // save both as one audio file

 $filename = "tmp/a.mp3";
 $file = fopen( $filename, "wb" );
 fwrite( $file, $load);
 fclose( $file );

 > However, I can't do the same with .WAV files. Does anyone know a way to
 > combine .WAV files similar to the way shown above?

If you are using linux I'd just shell out to sox or similar.

I don't know how to do that.

BTW the MP3s you produce in the above way are perhaps not that
"prefect". MP3 is a frame based format which means that you can in
theory combine two files quite simply, but I'm not sure how well it will
all work with if the two files are different bit rates or one is a VBR etc.

WAV format is quite similar to raw PCM, but it does have a header. It's
a relatively simple format tho' so the specs are relatively easy to
understand (tho' I've not looked at them for a while.

In theory, it should just be a matter of removing the WAV header from
the second file and concatenating as per your above algorithm, but in
practice it is more complex. WAV allows different sample rates and
channels etc. so you may have to resample the files to allow for simple
concatenation. All in all, I think sox will solve your problems if you
can shell out in linux.

sox is for sound what imagemagick is for graphics.

I'm aware of what can happen when you combine sound files recorded with different parameters, but that's not a problem here. All files were recorded exactly the same.

I also understand that the problem is probably the headers in the WAV files. However, my dilemma here is how to remove these headers?

For my current problem, it's not necessary that I to do this on the fly -- I don't necessarily need a php solution (unless someone can provide one). I only have 11 very short files (i.e., numbers 0-9, beep, and pause) that need the headers extracted -- and -- I need only one file that contains only a header. From there, I should be able to assemble the sound files that I need.

Any takers -- or suggestions how I can do this on a Mac?

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux