Answer the question
In order to leave comments, you need to log in
How to merge two wav files into one in php?
Tell me, can anyone know how to glue two wav files into one in php, the code below glues, but only for 1 second.
<?php
$wav_array = array(); // этот массив нам пригодится для хранения имен звуковых файлов
array_push($wav_array, '5-500.wav');
array_push($wav_array, '5-800.wav');
header('Content-Type: audio/x-wav'); // заголовок для указания типа файла (аудио)
$content = joinwavs($wav_array); // вызов функции joinwavs для соединения файлов
echo $content; // вывод бинарного содержимого нового файла
function joinwavs($wavs){
$fields = join('/',array( 'H8ChunkID', 'VChunkSize', 'H8Format',
'H8Subchunk1ID', 'VSubchunk1Size',
'vAudioFormat', 'vNumChannels', 'VSampleRate',
'VByteRate', 'vBlockAlign', 'vBitsPerSample' ));
$data = '';
foreach($wavs as $wav){
$fp = fopen($wav,'rb');
$header = fread($fp,36);
$info = unpack($fields,$header);
// read optional extra stuff
if($info['Subchunk1Size'] > 16){
$header .= fread($fp,($info['Subchunk1Size']-16));
}
// read SubChunk2ID
$header .= fread($fp,4);
// read Subchunk2Size
$size = unpack('vsize',fread($fp, 4));
$size = $size['size'];
// read data
$data .= fread($fp,$size);
}
return $header.pack('V',strlen($data)).$data;
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question