How do I check a sound file

I want to make a page where people can upload a sound file.
It have to be in Wav-format and some parameters have to be correct when uploading.

Is there any way I can check a file when it has been uploaded, so the user will see that everything was ok.
The file needs to be: Audio with 16 bit (sample size), 44.1 kHz (sample rate), 1411 kbps (bit rate) stereo WAV file.

Not sure if it’s possible, but would be great and save a lot of time if this process could be built in in the upload script.

Any ideas?

Probably with ffmpeg.

No, I want the users to make sure they are uploading the correct file. It’s supposed to be a master sound file that can be used uncompressed.
So, when they are uploading, I want my script to look at the details of the file and make sure all the elements are correct and give the uploader a thumbs up.
Don’t want them to upload a crappy mp3 file.

I guess there must be some way I can check what’s in the file with some code?

No. In order for your server to check the file it must be uploaded. There is no magic powers here.

I’m unsure of the checks that can be done, but if there is a third party script to do the check on media such as this, you can always upload to a temp folder, run the check, and move the file to where it can be used or delete it accordingly depending on the result.

Well, yes something like that. I’ve seen it somewhere, but don’t remember where.
The file is uploaded and a temporary folder might be fine. But I don’t know how to check the file. How is a check like that working? What kind of code do I use for this?

You need to find a command line tool, from there you can use shell_exec (http://php.net/manual/en/function.shell-exec.php). As logic pointed out, you might be able to use ffmpeg, but you’ll have to play around with it to see if it will fit your needs.

Isn’t there any way I can look at a file that is uploaded. When a user is uploading a sound file I would like to look at the header info or wherever this may be hidden. And then check if the file is 16 bit (sample size), 44.1 kHz (sample rate), 1411 kbps (bit rate) stereo WAV files.
If everything is ok, I will tell the user that it looks fine. But if any of this is not correct, I will show an error code on the page, telling the user that the sample rate is not correct, or whatever is the error.

Is there a way to do this or what should I look for when searching for answers?

Sorry, I just found the answer.

<pre>
<?php
$fp = fopen(‘soundd.wav’, ‘r’);
fseek($fp, 20);
$rawheader = fread($fp, 16);
$header = unpack(‘vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits’,
$rawheader);
print_r($header);
?>
</pre>

Well, I was too quick. I can’t see the bitrate there. Is there a way to add that one as well? Or is that some math involved?

Check out ffmpeg-php. Don’t be fooled by the name ffmpeg … it doesn’t only handle mpeg files. It handles lots of audio formats as well as a plethora of video formats. It will be more than enough to do what you need… including file creation, conversion, and even grabbing individual frames from video files.