maximal/audio-waveform
Composer 安装命令:
composer require maximal/audio-waveform
包简介
Audio waveform generator on PHP with SoX
关键字:
README 文档
README
Install
Install SoX and some of its handlers for different audio formats.
Also you need a GD module or other extension providing imagecreatetruecolor() functionality.
For example, on Ubuntu:
sudo apt install sox libsox-fmt-all sudo apt install php-gd
Install this package using the Composer require command:
composer require maximal/audio-waveform '~1.0'
or add the package name to the require section in your composer.json file:
"require": { "maximal/audio-waveform": "~1.0" }
and then run:
composer update
Use
In your PHP source:
// Include `maximal\audio` namespace use maximal\audio\Waveform; // Open an audio file `track.mp3` $waveform = new Waveform('track.mp3'); // Save its waveform to the `thumbnail.png` image file which size is 1024×512 pixels $success = $waveform->getWaveform('thumbnail.png', 1024, 512);
One Phase
To get positive waveform only (i.e. one phase) pass onePhase parameter set to true:
$waveform->getWaveform('one-phase.png', 800, 400, true);
Stereo source:
Mono source:
Settings
All settings are public static members of Waveform class:
$linesPerPixelis the count of lines per each pixel in horizontal axis. Default is8.$samplesPerLineis the count of samples per each line. Default is512.$coloris the color of each line. Default is[95, 95, 95, 0.5]meaning the dark grey color with 50% opacity.$backgroundColoris the background color of the waveform file. Default is[245, 245, 245, 1]meaning the light grey opaque background with 100% opacity.$axisColoris the color of each axis. Default is[0, 0, 0, 0.15]meaning the black color with 15% opacity.
Examples
Red waveform with half-transparent peaks:
$waveform = new Waveform('track.mp3'); Waveform::$color = [255, 0, 0, 0.5]; $success = $waveform->getWaveform('thumbnail.png', 1024, 512);
Red waveform and fully transparent background:
$waveform = new Waveform('track.mp3'); Waveform::$color = [255, 0, 0, 0.5]; Waveform::$backgroundColor = [0, 0, 0, 0]; $success = $waveform->getWaveform('thumbnail.png', 1024, 512);
Ubuntu Linux thumbnailer for Nautilus file explorer
-
Install the package to some directory. For example:
/opt/maximal/audio-waveform-php -
Place the following code in the file
/usr/share/thumbnailers/waveform.thumbnailer[Thumbnailer Entry] Exec=/opt/maximal/audio-waveform-php/thumbnailer.php %i %o %sx%s MimeType=audio/wave;audio/x-wav;audio/mpeg;audio/oggThis repository contains an example thumbnailer file. See:
usr/share/thumbnailers/waveform.thumbnailer.Also you can add other MIME types to the
MimeTypesection of your thumbnaler file as long as they are supportable by SoX utility. -
Clear thumbnail cache and restart Nautilus:
rm -rf ~/.thumbnails nautilus -q -
Since then all your audio files with specified MIME types will be shown in Nautilus using its small waveforms. By default they are WAV, MP3 and OGG files.
Integration with other libraries (e.g. wavesurfer.js)
Waveform class has getWaveformData() method for retrieving the waveform data without generating the image.
You can use it to integrate with different libraries, for instance, with the great
wavesurfer.js.
$waveform = new Waveform('track.mp3'); $width = 1024; $data = $waveform->getWaveformData($width); // $data['lines1'] and $data['lines2'] now have the waveform data for channels 1 and 2
To get positive values only (i.e. one phase) pass onePhase parameter set to true:
$data = $waveform->getWaveformData($width, true);
Contact the author
- Website: https://maximals.ru (Russian)
- Sijeko Company: https://sijeko.ru (web, mobile, desktop applications development and graphic design)
- Personal GitHub: https://github.com/maximal
- Company’s GitHub: https://github.com/sijeko
maximal/audio-waveform 适用场景与选型建议
maximal/audio-waveform 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 61.96k 次下载、GitHub Stars 达 52, 最近一次更新时间为 2016 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「audio」 「waveform」 「sox」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maximal/audio-waveform 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maximal/audio-waveform 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maximal/audio-waveform 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
A php package to read WAV data
A php package that can generate waveforms based on a WAV file
Library for manipulating audio files (validating, transcoding, and tagging)
A php package to read WAV data
Waveform generator for php 7.0
统计信息
- 总下载量: 61.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 53
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-21


