2017 © Pedro Peláez
 

library waveform

A php package that can generate waveforms based on a WAV file

image

boyhagemann/waveform

A php package that can generate waveforms based on a WAV file

  • Wednesday, November 23, 2016
  • by boyhagemann
  • Repository
  • 3 Watchers
  • 26 Stars
  • 14,141 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 7 Forks
  • 4 Open issues
  • 1 Versions
  • 5 % Grown

The README.md

Waveform

This package creates a waveform, based on the BoyHagemann\Wave class. It will have several generators to present the waveform., (*1)

An example of a generated waveform, (*2)

Install

You can install with composer using the following lines in your composer.json file:, (*3)

"minimum-stability": "dev",
"require": {
    "boyhagemann/waveform": "dev-master"
}

How to use

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>

Generate an svg based waveform

<?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);

Maximize

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

Get wave metadata

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();

To do

  • [X] Add png generator
  • [ ] Add svg generator
  • [ ] Allow different bits per sample (8, 16, 24, 32)

The Versions

23/11 2016

dev-master

9999999-dev

A php package that can generate waveforms based on a WAV file

  Sources   Download

The Requires

 

php audio chunk wave waveform riff