Audio format detection library for PHP.
- Detection of the audio type based on its header
- No dependencies
- Very fast
- MP3
- WAV (WAVE PCM soundfile format)
- PHP 7.1+
composer require selective/audio-type
use Selective\AudioType\AudioTypeDetector;
use Selective\AudioType\Provider\DefaultAudioVideoProvider;
use SplFileObject;
$file = new SplFileObject('example.mp3');
$detector = new AudioTypeDetector();
// Add video detectors
$detector->addProvider(new DefaultVideoProvider());
$audioType = $detector->getAudioTypeFromFile($file);
// Get the video format
echo $audioType->getFormat(); // mp3
// Get the mime type
echo $audioType->getMimeType(); // audio/mp3
$audio = new SplTempFileObject();
$audio->fwrite('my file content');
$detector = new AudioTypeDetector();
// Add audio detectors
$detector->addProvider(new DefaultAudioProvider());
echo $detector->getAudioTypeFromFile($file)->getFormat();
The MIT License (MIT). Please see License File for more information.