dev-master
9999999-devA php package that can generate waveforms based on a WAV file
The Requires
- php >=5.3.3
- boyhagemann/wave dev-master
php audio chunk wave waveform riff
A php package that can generate waveforms based on a WAV file
This package creates a waveform, based on the BoyHagemann\Wave class. It will have several generators to present the waveform., (*1)
, (*2)
You can install with composer using the following lines in your composer.json file:, (*3)
"minimum-stability": "dev", "require": { "boyhagemann/waveform": "dev-master" }
The most basic way to generate a waveform is like this. It has a default width of 500 pixels and a height of 200 pixels., (*4)
setGenerator(new Generator\Png) ->setWidth(960) ->setHeight(400); // Will display the image, including setting the read image/png header echo $waveform->generate(); ``` ### Generate a html/css based waveform ```php setGenerator(new Generator\Html) ->setWidth(960) ->setHeight(400); $waveformHtml = $waveform->generate(); ?> <html> <head> <style> #waveform { float: left; position: relative; height: 400px; width: 960px; } span { position: absolute; display: block; width: 1px; background: #ddd; float: left; bottom: 0; } </style> </head> <body> <div id="waveform"> <?php echo $waveformHtml ?> </div> </body> </html>
<?php use BoyHagemann\Waveform\Waveform; $filename = 'the/path/to/your/file.wav'; $waveform = Waveform::fromFilename($filename); $waveform->setGenerator(new Generator\Svg) $waveformSvg = $waveform->generate(); \\do something, e.g. save it to a file file_put_contents ('the/path/to/result/file.svg', $waveformSvg);
By default, the wave amplitude data is maximized to match the height you set for the waveform. This means that if you set the height to 200, then the waveform is maximized to 200 pixels. The result is a nice looking waveform regardless of the overall loudness. Don't want this nifty feature? You can change the behaviour with one simple line of code:, (*5)
$waveform->setMaximized(false); // defaults to true
You have access to all the wave metadata. The only thing you have to do is retrieving the original Wave object and get the desired information. Form more detailed information see BoyHagemann\Wave documentation., (*6)
$wave = $waveform->getWave(); $metadata = $wave->getMetadata(); $metadata->getSampleRate(); $metadata->getBitsPerSample();
A php package that can generate waveforms based on a WAV file
php audio chunk wave waveform riff