We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

php function to convert recording to .wav file

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
jbrohan
Posts: 19
Joined: Mon Nov 19, 2007 10:17 am
Location: Montreal Canada
Contact:

php function to convert recording to .wav file

Post by jbrohan »

This php function will convert a recording into a ulaw compressed wave file that is playable on any application. Be sure to have magic-quotes off while the function is running.

Improvements and comments to jbrohan (at) tradersmicro.com

(c) Traders Micro. you may freely use this code for any purpose. No guarantees given or implied.




function Store_to_wave ( $infilename, $wavefilename ){
$a = file_get_contents ( $infilename );
$b = "RIFF";
$n = strlen ( $a ) + 44;
$b .= pack ( 'V', $n );
$b .= "WAVEfmt "; // 8
$b .= pack ( 'V', 16 ); // length of format block 4
$b .= pack ( 'v', 7 ); // ulaw encoding 2
$b .= pack ( 'v', 1 ); // channel numbers 2
$b .= pack ( 'V', 8000 ); // sample rate Hz 4
$b .= pack ( 'V', 8000 ); // bytes / sec 4
$b .= pack ( 'v', 1 ); // bytes / sample 2
$b .= pack ( 'v', 8 ); // bits / sample 2
$b .= "data"; // 4
$b .= pack ( 'V', strlen ( $a )); // 4
$b .= $a;
$f = fopen ( $wavefilename, "wb" );
fwrite ( $f, $b, strlen ( $b ));
fclose ( $f );
}
John Brohan National Instruments LabVIEW expert in Montreal
Traders Micro "We connect all sorts of things to computers"
telemedicine applications
www.woundfollowup.com

Post Reply