Merge two mp3 php

前端 未结 5 1580
青春惊慌失措
青春惊慌失措 2020-12-05 22:10

Do you know a class to merge two MP3 files using PHP?

I\'ve found nothing on Google.

5条回答
  •  渐次进展
    2020-12-05 22:39

    Important things to remember:

    • The bit rates must match. It's also a good idea to ensure the rate (Hz) and stereo/mono are matched (I used Audacity).
    • The Content-length header be the length of both files.

    Here's a sample from my text-to-speech project. I needed to add a 1 second silence at the end of MP3 audio that was generated dynamically:

    $output_audio = textToMP3("Hello World");               // Original audio
    $silent_audio = file_get_contents("silence.mp3");       // 1 second silence
    $content_length = strlen($output_audio) + strlen($silent_audio);
    
    // Output the audio stream
    header('Content-type: audio/mpeg');
    header('Content-length: ' . $content_length);
    header('Cache-Control: no-cache');
    header("Pragma: no-cache");
    header("Expires: 0");
    echo $audio . $silent_audio;
    

提交回复
热议问题