@accentdotai/recorderjs 中文文档教程

发布于 7年前 浏览 26 项目主页 更新于 3年前

Recorder.js

A plugin for recording/exporting the output of Web Audio API nodes

托管在 Github :octopus:

这个库驱动语言学习应用程序的录音功能 Accent.ai

注意:此存储库是@mattdiamond 的Recorderjs 的最新功能分支。


Syntax

Constructor

var rec = new Recorder(source [, config])

创建记录器实例。

  • source - The node whose output you wish to capture
  • config - (optional) A configuration object (see config section below)

Config

  • workerPath - Path to recorder.js worker script. Defaults to 'js/recorderjs/recorderWorker.js'
  • bufferLen - The length of the buffer that the internal JavaScriptNode uses to capture the audio. Can be tweaked if experiencing performance issues. Defaults to 4096.
  • callback - A default callback to be used with exportWAV.
  • type - The type of the Blob generated by exportWAV. Defaults to 'audio/wav'.

Instance Methods

rec.record()
rec.stop()

非常不言自明...... record 将开始捕获音频,而 stop 将停止捕获音频。 对 record 的后续调用将添加到当前录音中。

rec.clear()

这将清除记录。

rec.exportWAV([callback][, type])

这将生成一个包含 WAV 格式录音的 Blob 对象。 将以 Blob 作为唯一参数调用回调。 如果未指定回调,将使用默认回调(在配置中定义)。 如果未设置默认值,则会抛出错误。

此外,您可以指定要返回的 Blob 类型(默认为“audio/wav”)。

rec.getBuffer([callback])

这会将录制的立体声缓冲区(作为两个 Float32Arrays 的数组,用于单独的左右声道)传递给回调。 它可以通过创建一个新的源缓冲区并将这些缓冲区设置为单独的通道数据来播放:

function getBufferCallback( buffers ) {
    var newSource = audioContext.createBufferSource();
    var newBuffer = audioContext.createBuffer( 2, buffers[0].length, audioContext.sampleRate );
    newBuffer.getChannelData(0).set(buffers[0]);
    newBuffer.getChannelData(1).set(buffers[1]);
    newSource.buffer = newBuffer;

    newSource.connect( audioContext.destination );
    newSource.start(0);
}

该示例代码将播放立体声缓冲区。

rec.configure(config)

这将通过传入配置对象来设置记录器的配置。

Utility Methods (static)

Recorder.forceDownload(blob[, filename])

此方法将使用新的锚链接 download 属性强制下载。 文件名默认为“output.wav”。

Bugs?

将问题提交到:https://github.com/accentdotai/recorderjs/issues

Development

这个包既可以用作 ES6 Node.js 模块和浏览器库。

Node.js 导入使用文件 src/recorder.js

注意: 目前此包只能在兼容 ES6 的 Node.js 应用下使用。

Webpack 用于构建与浏览器兼容的 lib/recorder.js 文件,该文件稍后被丑化(使用 uglify-js)为 dist/recorder.min.js 。

Scripts

为了便于开发,以下脚本在 package.json 中定义:

npm run lint
npm run build

有关这些如何工作的更多信息,只需检查 package.json 中的脚本定义。

TODO

  • Add jasmine tests
  • Make Node.js module version which is compatible with non ES6 apps.

License (MIT)

版权所有 © 2013 Matt Diamond

特此免费授予任何获得本软件和相关文档文件(“软件”)副本的人不受限制地处理本软件,包括但不限于使用权,复制、修改、合并、发布、分发、再许可和/或出售软件的副本,并允许获得软件的人这样做,但须遵守以下条件:

上述版权声明和本许可声明应包含在软件的所有副本或重要部分中。

本软件“按原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、特定用途的适用性和非侵权的保证。 在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是在合同诉讼、侵权行为还是其他方面,由软件或软件的使用或其他交易引起、由软件引起或与之相关软件。

Recorder.js

A plugin for recording/exporting the output of Web Audio API nodes

Hosted in Github :octopus:

This library drives the audio recording capabilities of the language learning app Accent.ai.

Note: This repository is the most up-to-date and functional fork of @mattdiamond's Recorderjs.


Syntax

Constructor

var rec = new Recorder(source [, config])

Creates a recorder instance.

  • source - The node whose output you wish to capture
  • config - (optional) A configuration object (see config section below)

Config

  • workerPath - Path to recorder.js worker script. Defaults to 'js/recorderjs/recorderWorker.js'
  • bufferLen - The length of the buffer that the internal JavaScriptNode uses to capture the audio. Can be tweaked if experiencing performance issues. Defaults to 4096.
  • callback - A default callback to be used with exportWAV.
  • type - The type of the Blob generated by exportWAV. Defaults to 'audio/wav'.

Instance Methods

rec.record()
rec.stop()

Pretty self-explanatory… record will begin capturing audio and stop will cease capturing audio. Subsequent calls to record will add to the current recording.

rec.clear()

This will clear the recording.

rec.exportWAV([callback][, type])

This will generate a Blob object containing the recording in WAV format. The callback will be called with the Blob as its sole argument. If a callback is not specified, the default callback (as defined in the config) will be used. If no default has been set, an error will be thrown.

In addition, you may specify the type of Blob to be returned (defaults to 'audio/wav').

rec.getBuffer([callback])

This will pass the recorded stereo buffer (as an array of two Float32Arrays, for the separate left and right channels) to the callback. It can be played back by creating a new source buffer and setting these buffers as the separate channel data:

function getBufferCallback( buffers ) {
    var newSource = audioContext.createBufferSource();
    var newBuffer = audioContext.createBuffer( 2, buffers[0].length, audioContext.sampleRate );
    newBuffer.getChannelData(0).set(buffers[0]);
    newBuffer.getChannelData(1).set(buffers[1]);
    newSource.buffer = newBuffer;

    newSource.connect( audioContext.destination );
    newSource.start(0);
}

This sample code will play back the stereo buffer.

rec.configure(config)

This will set the configuration for Recorder by passing in a config object.

Utility Methods (static)

Recorder.forceDownload(blob[, filename])

This method will force a download using the new anchor link download attribute. Filename defaults to 'output.wav'.

Bugs?

Submit issues to: https://github.com/accentdotai/recorderjs/issues

Development

This package can be used both as an ES6 Node.js module and a Browser library.

Node.js imports use the file src/recorder.js.

NOTE: Currently this package can only be used under Node.js apps compatible with ES6.

Webpack is used to build the browser-compatible lib/recorder.js file which is later uglified (using uglify-js) into dist/recorder.min.js.

Scripts

The following scripts are defined within package.json for ease of development:

npm run lint
npm run build

For more info on how these work simply checkout the script definitions within package.json.

TODO

  • Add jasmine tests
  • Make Node.js module version which is compatible with non ES6 apps.

License (MIT)

Copyright © 2013 Matt Diamond

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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