@abrahamian/wavesurfer.js 中文文档教程

发布于 5年前 浏览 8 项目主页 更新于 3年前

wavesurfer.js

npm 版本 npm 在 https 加入聊天://gitter.im/katspaugh/wavesurfer.js

使用网络音频和画布的交互式导航音频可视化。

 Screenshot

查看教程wavesurfer-js.org 上的 .org/examples">示例。

Browser support

wavesurfer.js 仅适用于支持网络音频的现代浏览器

它将回退到其他浏览器中的音频元素(没有图形)。 您也可以尝试 wavesurfer.swf,这是一个基于 Flash 的后备方案。

FAQ

Can the audio start playing before the waveform is drawn?

是的,如果您使用 backend: 'MediaElement' 选项。 请参阅此处:https://wavesurfer-js.org/example/audio-element/。 当您按下播放键时,音频将开始播放。 将显示一条细线,直到下载并解码整个音频文件以绘制波形。

Can drawing be done as file loads?

不可以。Web Audio 需要整个文件才能在浏览器中对其进行解码。 但是,您可以加载预解码的波形数据以立即绘制波形。 请参阅此处:https://wavesurfer-js.org/example/audio-element/(“预编码峰”部分)。

API in examples

选择一个容器:

<div id="waveform"></div>

创建一个实例,传递容器选择器和选项

var wavesurfer = WaveSurfer.create({
    container: '#waveform',
    waveColor: 'violet',
    progressColor: 'purple'
});

订阅一些events

wavesurfer.on('ready', function () {
    wavesurfer.play();
});

从 URL 加载音频文件:

wavesurfer.load('example/media/demo.wav');

Documentation

查看所有可用的文档 方法选项事件主页

Upgrade

如果您要从以前版本的 wavesurfer.js 升级,请参阅升级文档。

Using with a module bundler

Wavesurfer 可以与这样的模块系统一起使用:

// import
import WaveSurfer from 'wavesurfer.js';

// commonjs/requirejs
var WaveSurfer = require('wavesurfer.js');

// amd
define(['WaveSurfer'], function(WaveSurfer) {
  // ... code
});

Related projects

有关使用 wavesurfer.js 的项目列表,请查看 项目页面

Development

构建状态 覆盖状态 Size

安装开发依赖:

npm install

开发任务在文件时自动重建库的某些部分已更改(start – wavesurfer,start:plugins – 插件)。 启动开发任务并转到 localhost:8080/example/ 以测试当前构建。

启动核心库开发服务器:

npm run start

启动插件开发服务器:

npm run start:plugins

构建所有文件。 (生成的文件放在 dist 目录中。)

npm run build

仅运行测试:

npm run test

使用 esdoc 构建文档(生成的文件放在 doc 目录中。)

npm run doc

如果你想使用 < a href="https://github.com/Microsoft/vscode-chrome-debug">VS Code - Chrome 调试器,已经有一个 launch.json 为您正确配置了 sourceMapPathOverrides

Editing documentation

主页和文档文件保存在 gh-pages 分支 . 特别欢迎对文档的贡献。

Credits

Alex Khokhulin 的初步想法。 许多 谢谢 很棒的贡献者

License

License

本作品已获得许可 BSD 3-Clause 许可证

wavesurfer.js

npm version npm Join the chat at https://gitter.im/katspaugh/wavesurfer.js

Interactive navigable audio visualization using Web Audio and Canvas.

Screenshot

See a tutorial and examples on wavesurfer-js.org.

Browser support

wavesurfer.js works only in modern browsers supporting Web Audio.

It will fallback to Audio Element in other browsers (without graphics). You can also try wavesurfer.swf which is a Flash-based fallback.

FAQ

Can the audio start playing before the waveform is drawn?

Yes, if you use the backend: 'MediaElement' option. See here: https://wavesurfer-js.org/example/audio-element/. The audio will start playing as you press play. A thin line will be displayed until the whole audio file is downloaded and decoded to draw the waveform.

Can drawing be done as file loads?

No. Web Audio needs the whole file to decode it in the browser. You can however load pre-decoded waveform data to draw the waveform immediately. See here: https://wavesurfer-js.org/example/audio-element/ (the "Pre-recoded Peaks" section).

API in examples

Choose a container:

<div id="waveform"></div>

Create an instance, passing the container selector and options:

var wavesurfer = WaveSurfer.create({
    container: '#waveform',
    waveColor: 'violet',
    progressColor: 'purple'
});

Subscribe to some events:

wavesurfer.on('ready', function () {
    wavesurfer.play();
});

Load an audio file from a URL:

wavesurfer.load('example/media/demo.wav');

Documentation

See the documentation on all available methods, options and events on the homepage.

Upgrade

See the upgrade document if you're upgrading from a previous version of wavesurfer.js.

Using with a module bundler

Wavesurfer can be used with a module system like this:

// import
import WaveSurfer from 'wavesurfer.js';

// commonjs/requirejs
var WaveSurfer = require('wavesurfer.js');

// amd
define(['WaveSurfer'], function(WaveSurfer) {
  // ... code
});

Related projects

For a list of projects using wavesurfer.js, check out the projects page.

Development

Build Status Coverage Status Size

Install development dependencies:

npm install

Development tasks automatically rebuild certain parts of the library when files are changed (start – wavesurfer, start:plugins – plugins). Start a dev task and go to localhost:8080/example/ to test the current build.

Start development server for core library:

npm run start

Start development server for plugins:

npm run start:plugins

Build all the files. (generated files are placed in the dist directory.)

npm run build

Running tests only:

npm run test

Build documentation with esdoc (generated files are placed in the doc directory.)

npm run doc

If you want to use the VS Code - Debugger for Chrome, there is already a launch.json with a properly configured sourceMapPathOverrides for you.

Editing documentation

The homepage and documentation files are maintained in the gh-pages branch. Contributions to the documentation are especially welcome.

Credits

Initial idea by Alex Khokhulin. Many thanks to the awesome contributors!

License

License

This work is licensed under a BSD 3-Clause License.

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文