__construct()
extractChunk()
getWav()
isEnoughMemory()
downloadChuck()
getFilename()
init()
saveChunk()
$Wav
"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).
The follow is an example of how to extract a chunk from a wav file and force the download using this class:
require_once('AuderoWavExtractor/AuderoWavExtractor.php');
$InputFile = 'audio.wav'; // path to input wav file
$OutputFile = 'chunk.wav'; // path to the output chunk
$Start = 0 * 1000; // Start time of the chunk
$End = 20 * 1000; // End time of the chunk
$Extractor = new AuderoWavExtractor($InputFile);
$Extractor->extractChunk($Start, $End);
The follow is an example of how to extract a chunk from a wav file and save it into the local disk:
require_once('AuderoWavExtractor.php');
$InputFile = 'audio.wav'; // path to input wav file
$OutputFile = 'chunk.wav'; // path to the output chunk
$Start = 12 * 1000; // Start time of the chunk
$End = 20 * 1000; // End time of the chunk
$Extractor = new AuderoWavExtractor($InputFile);
$Extractor->extractChunk($Start, $End, 2, $OutputFile);
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.
| author | Aurelio De Rosa |
|---|---|
| version | 1.0 |
| license | CC BY-NC 3.0 |
| link | https://bitbucket.org/AurelioDeRosa/audero-wav-extractor |
| package | Audero\AuderoWavExtractor |
__construct(string $FilePath)
stringThe filename, including the path, of the managed file wav
extractChunk(int $Start, int $End, int $Destination, string $Filename) : string
The possible value of $Destination are:
intThe start time, in milliseconds, of the portion to extract
intThe end time, in milliseconds, of the portion to extract
intWhere to save the extracted chunk
string&$Filename The name to assing to the chunk. If no name is provided the method generate one using this rule: "InputFilename-Start-End.wav"
\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 |
stringThe chunk to extract, including the headersisEnoughMemory(int $Start, int $End) : bool
intThe start time, in milliseconds, of the chunk that has to be extracted
intThe end time, in milliseconds, of the chunk that has to be extracted
boolTrue if the memory is enough. False otherwise.downloadChuck(string $Chunk, string $Filename)
stringThe string containing the bytes of the chunk
stringThe filename that will be shown by the browser
getFilename(boolean $IncludeExtention) : string
If false is passed, the extention of the file is stripped.
booleanInclude or not the extention (.wav) of the file. Default is true.
stringThe filename of the managed wav fileinit()
saveChunk(string $Chunk, string $Filename)
stringThe string containing the bytes of the chunk
stringThe filename to use to save the file on the harddisk
\InvalidArgumentException |
If the chunk is empty |
|---|---|
\Exception |
If the library is unable to create the file on the harddisk |