boyhagemann/waveform 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

boyhagemann/waveform

Composer 安装命令:

composer require boyhagemann/waveform

包简介

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

README 文档

README

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

An example of a generated waveform

Install

You can install with composer using the following lines in your composer.json file:

"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.

<?php

use BoyHagemann\Waveform\Waveform;

echo Waveform::fromFilename('the/path/to/the/file.wav');

Generators

The waveform can be presented in multiple ways:

  • Html
  • Png
  • Svg

It uses a simple interface so you can build your own generator. The interface GeneratorInterface uses three simple methods:

<?php

namespace BoyHagemann\Waveform\Generator;

use BoyHagemann\Waveform\Waveform;

interface GeneratorInterface
{
    public function setWaveform(Waveform $waveform);
    public function getWaveform();
    public function generate();
}

Examples

If you want to test it yourself, try the following codes.

Generate a png image

<?php

use BoyHagemann\Waveform\Waveform;
use BoyHagemann\Waveform\Generator;

$filename = 'the/path/to/your/file.wav';

$waveform =  Waveform::fromFilename($filename);
$waveform->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

use BoyHagemann\Waveform\Waveform;

$filename = 'the/path/to/your/file.wav';

$waveform =  Waveform::fromFilename($filename);
$waveform->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:

$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.

$wave = $waveform->getWave();
$metadata = $wave->getMetadata();
$metadata->getSampleRate();
$metadata->getBitsPerSample();

To do

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

统计信息

  • 总下载量: 18.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 42
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 40
  • Watchers: 3
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-02-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固