Amin Shah
Amin Shah

Reputation: 45

Read binary data and convert it into .wav or mp3 audio file

i am developing an web application in which i have to read binary from database base actually this is audio which is saved in the form or binary. how to convert this binary into wav or mp3 file

Upvotes: 0

Views: 5902

Answers (2)

mrwooster
mrwooster

Reputation: 24207

You do not need to 'convert' it, but if you want to allow a user to download an mp3 or wav file you need to set the correct headers.

You can set the headers for an mp3 download using the following code.

header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache'); 
header("Content-Type: audio/mpeg");
header("Content-Length: " . $len);

Note, you will need to know the length of the mp3 data.

See http://php.net/manual/en/function.header.php for more information on setting headers.

Upvotes: 0

deceze
deceze

Reputation: 522101

If you didn't touch the binary data and it's still in its original binary wav/mp3 form, you have the audio file. Just write it to a file to make it an actual file:

file_put_contents('sound.wav', $binaryData);

Upvotes: 2

Related Questions