PHPAudio – Audio file processing in pure PHP

OVERVIEW

There currently exists no PHP library or code to work with audio file formats. The general solution is to use external libraries or softwares like ffmpeg, sox etc , by calling them with parameters and then capturing their output.

PHPAudio is an attempt to process audio files in pure PHP code without using any external dependencies. This is going to take at least a few months as audio processing is a very big field. For starters, I am going to focus on WAV and MP3 formats as they are the most commonly used and then move on to other formats like Ogg, AU, AIFF etc.

As the library progresses, the download link and documentation will be constantly updated. Any queries, questions or suggestions are very welcome.

 

 

DOCUMENTATION

WAV files

The following types of WAV files are handled:

  • Uncompressed PCM format
  • IEEE Floating Point
  • ALaw encoded
  • muLaw encoded

1.Parse a WAV file and get information about it

Usage:

require_once("clsWAV.php");
$wav = new \phpaudio\WAV('/path to your wave file.wav');
if ($wav->getError() != null && $wav->getError() != "") 
   echo($wav->getError() . "\n");
else 
   var_dump($wav->getHeaderData());

The WaveHeader class gets filled up with all the information about the WAV file. Among other things, it provides information about:

  • WAV format type
  • No.of Channels
  • Sample Rate
  • Byte Rate
  • Bits per Sample
  • No.of Samples
  • Size of Each Sample
  • Duration in Seconds or in HH:MM:SS format
  • Bytes in Each Channel

Check the comments in clsWAV.php for more details.

 

DOWNLOADS

Download Version 1.0 (7.2 Kb) Last Updated 29 Dec 2015

GitHub Repository: https://github.com/amitonline/phpaudio/tree/master/wav

1 Comment

  1. I would like to cut off silent periods in the beginning and end of an audio file.
    is it possible to get the position of both end of silence in the beginning, and start of silent period at the end of .wav file?

Leave a Reply

Your email address will not be published.


*