"Audero Wav Extractor" is a PHP library that allows to extract a chunk from a wav file.

The extracted chunk of the wav file can be saved on the hard disk, can be forced to be prompted as download by the user's browser, returned as a string for a later processing or a combination of the first and second possibilities. It is very easy to use "Audero Wav Extractor" to extract a piece of audio from a wav file. All you have to do is give the name of the file, the start and the end time to extract (optionally you can provide a name for the extracted chunk).

LICENSE: "Audero Wav Extractor" (from now on "The software") is released under the CC BY-NC 3.0 ("Creative Commons Attribution NonCommercial 3.0") license. More details can be found here: http://creativecommons.org/licenses/by-nc/3.0/

WARRANTY: The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

package Audero\WavExtractor
author Aurelio De Rosa
license CC BY-NC 3.0
link https://bitbucket.org/AurelioDeRosa/audero-wav-extractor

 Methods

The constructor of the object.

__construct(string $filePath) 

It loads all the required class and create the Wav object that represents the chosen one.

Parameters

$filePath

string

The filename, including the path, of the managed file wav

Extract a chunk and force the download to the user's browser

downloadChuck(int $start, int $end, string $filename) : void

Parameters

$start

int

The start time, in milliseconds, of the portion to extract

$end

int

The end time, in milliseconds, of the portion to extract

$filename

string

The filename that will be shown by the browser

Extract a portion of the current, from the $start to $end.

extractChunk(int $start, int $end, int $destination, string $filename) : string

The chunk will be saved, with name $filename, in the local server, the browser or the user and so on based on the value of $Destination.

The possible value of $Destination are:

  • 1: send the file to the browser and force the download with the name given by $filename.
  • 2: save into the local disk the file with the name given by $filename.
  • 3: return the wav as a string. In this case $filename is ignored.
  • 4: both 2 and 3
deprecated Since version 2.0.0

Parameters

$start

int

The start time, in milliseconds, of the portion to extract

$end

int

The end time, in milliseconds, of the portion to extract

$destination

int

Where to save the extracted chunk

$filename

string

&$filename The name to assign to the chunk. If no name is provided the method generate one using this rule: "InputFilename-Start-End.wav"

Exceptions

\InvalidArgumentException If the give boundary is invalid (for example if the end is lower than start) or if the destination value isn't valid (for example greater than 4).
\RuntimeException If there's not enough memory to save the given range

Returns

stringThe chunk to extract, including the headers

Extract a portion of the current, from the $start to $end and return it as a string

getChunk(int $start, int $end) : string

Parameters

$start

int

The start time, in milliseconds, of the portion to extract

$end

int

The end time, in milliseconds, of the portion to extract

Exceptions

\InvalidArgumentException If the give boundary is invalid (for example if the end is lower than start) or if the destination value isn't valid (for example greater than 4).
\RuntimeException If there's not enough memory to save the given range

Returns

stringThe chunk to extract, including the headers

Get the instance of the current wav file

getWav() : \Audero\WavExtractor\Wav\Wav

Returns

\Audero\WavExtractor\Wav\WavThe current wav file

Try to test if the available memory is enough to extract the chunk

isEnoughMemory(int $start, int $end) : bool

Parameters

$start

int

The start time, in milliseconds, of the chunk that has to be extracted

$end

int

The end time, in milliseconds, of the chunk that has to be extracted

Returns

booltrue if the memory is enough. false otherwise.

Save the extracted chunk on the hard disk

saveChunk(int $start, int $end, string $filename) : void

Parameters

$start

int

The start time, in milliseconds, of the portion to extract

$end

int

The end time, in milliseconds, of the portion to extract

$filename

string

The filename to use to save the file on the hard disk

Exceptions

\InvalidArgumentException If the chunk is empty
\Exception If the library is unable to create the file on the hard disk

Get the filename (include the path) of the current wav file.

getFilename(boolean $includeExtension) : string

If false is passed, the extension of the file is stripped.

Parameters

$includeExtension

boolean

Include or not the extension (.wav) of the file. Default is true.

Returns

stringThe filename of the managed wav file

 Properties