Nick F
Nick F

Reputation: 10122

How to join WAV files using PHP?

I need to create a WAV file in PHP that consists of four repetitions of a single WAV (ie. append the uploaded file to itself 3 times). Can anyone suggest a simple way of repeating the data portion of the wav file?

I've tried using this script to join the file to itself four times, but the resulting file always seems to consist of a repetition of only the first 0.2s or so (the exact length seems to vary per file) of the file. Unfortunately, I don't know enough about the WAV file format to be able to figure out what's wrong with this script.

The WAV files we're using are always Stereo 16-bit 44.1kHz Windows PCM format, so it occurred to me it might be possible to write a much simpler script that just duplicates (quadruplicates?) the audio portion of the file and modifies only the 'size' portion of the header.

Any suggestions / help would be very much appreciated!

Upvotes: 2

Views: 3495

Answers (1)

Uku Loskit
Uku Loskit

Reputation: 42040

I'd rather have an external tool do it for me than try to hack it together in PHP.

It turns out that this isn't possible with ffmpeg (I Ggoogled it yesterday and found information about doing it with SoX too), but SoX as you found out for yourself.

Usually it is a lot simpler to delegate the complexity of very specific task to a library or an external tool. This is one of these cases.

Upvotes: 2

Related Questions