Merge Two Wave Files using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajasekar.karthik
    New Member
    • May 2006
    • 5

    Merge Two Wave Files using php

    Hi Guys

    I need a php script which will merge two wave files as i have already done a script which will will join the two wave files and play one after the other, can anyone advice me how to merge the two wave file and the two files has to play simultaneously. i have placed my script here


    <?php

    $content = joinwavs(array( '1.wav','2.wav' ));
    header('Content-Type: audio/x-wav');
    //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);
    // Destination file to be writed
    $destfile = "destination.wa v";
    // read optional extra stuff
    if($info['Subchunk1Size'] > 16){
    $header .= fread($fp,($inf o['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 );
    $filecontent = $header.pack('V ',strlen($data) ).$data;
    // Write the output data in a seperate file
    $fp1 = fopen($destfile ,"wb");
    fwrite($fp1,$fi lecontent);
    fclose($fp1);


    }
    }

    ?>





    Regards

    Karthik
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    This is getting more into the area of programming that PHP is not designed for. You will need to examine the WAV standard and see exactly how two overlapped WAV files are represented as data. My assumption is that you will first need to read in each segment of data from each WAV file and perform a sort of "data merge" on the waveform, and then produce a new file using your new data set.

    You will probably have better luck finding a tool that will do this for you.

    Comment

    • tolkienarda
      Contributor
      • Dec 2006
      • 316

      #3
      just as a brief suggestion of a language that would work is python. it is so versitle i an still a total beginer but the more i learn the more i love the language and its odd rules.

      eric

      Comment

      • rajasekar.karthik
        New Member
        • May 2006
        • 5

        #4
        Originally posted by Motoma
        This is getting more into the area of programming that PHP is not designed for. You will need to examine the WAV standard and see exactly how two overlapped WAV files are represented as data. My assumption is that you will first need to read in each segment of data from each WAV file and perform a sort of "data merge" on the waveform, and then produce a new file using your new data set.

        You will probably have better luck finding a tool that will do this for you.

        Is there any third party tool to do this , if so can u mention some of the tools that should work in linux server.

        Comment

        Working...