/audio-type

Audio format detector for PHP

Primary LanguagePHPMIT LicenseMIT

selective/audio-type

Audio format detection library for PHP.

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Features

  • Detection of the audio type based on its header
  • No dependencies
  • Very fast

Supported formats

  • MP3
  • WAV (WAVE PCM soundfile format)

Requirements

  • PHP 7.1+

Installation

composer require selective/audio-type

Usage

Detect the audio type of file

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

Detect the audio type of in-memory object

$audio = new SplTempFileObject();

$audio->fwrite('my file content');

$detector = new AudioTypeDetector();

// Add audio detectors
$detector->addProvider(new DefaultAudioProvider());

echo $detector->getAudioTypeFromFile($file)->getFormat();

License

The MIT License (MIT). Please see License File for more information.