静音收音机节点
静静听器节点是一个 伪- 说吧音频节点 它引用一个调用函数,当一串音频流变得沉默或无法产生。 用途 音频工作 如果有的话,就回到 脚本处理器节点 当没有工作时.
安装
使用国家预防机制安装:
npm i @alexanderolsen/silence-listener-node
设置
要使用音频Worklet的功能,请 必须 复制 sln.worklet.js 文件输入 /node modules/@alexanderolsen/ silence- listener-node/dist/ 互联网档案馆的存檔,存档日期2013-12-21 到图书馆能找到它的地方 此文件的默认位置位于服务器根( N)/sln. worklet.js (英语)) (中文(简体) ). 此位置可以使用 dict 的选项更改 createSilenceListenerNode()数字 :
createSilenceListenerNode(context, nChannels, {
pathToWorklet: '/some/path/to/sln.worklet.js', // default '/sln.worklet.js'
});
见 配置 需要更多关于使用 options 下诏.
使用量
在模块中:
import { createSilenceListenerNode } from '@alexanderolsen/silence-listener-node';
let context = new AudioContext();
let nChannels = 2;
let options = {}; // see **Configuration**
let buffSource = context.createBufferSource();
createSilenceListenerNode(context, nChannels, options)
.then((silenceListenerNode) => {
buffSource.connect(silenceListenerNode);
silenceListenerNode.connect(context.destination);
buffSource.start();
});
或者说
const createSilenceListenerNode = require('@alexanderolsen/silence-listener-node').createSilenceListenerNode;
(async function() {
let context = new AudioContext();
let nChannels = 2;
let options = {}; // see **Configuration**
let buffSource = context.createBufferSource();
let silenceListenerNode = await createSilenceListenerNode(context, nChannels, options);
buffSource.connect(silenceListenerNode);
silenceListenerNode.connect(context.destination);
buffSource.start();
})();
在 HTML 中:
<script src="https://cdn.jsdelivr.net/npm/@alexanderolsen/silence-listener-node"></script>
<script>
var context = new AudioContext();
var nChannels = 2;
var options = {}; // see **Configuration**
let buffSource = context.createBufferSource();
SilenceListenerNode.createSilenceListenerNode(context, nChannels, options)
.then((silenceListenerNode) => {
buffSource.connect(silenceListenerNode);
silenceListenerNode.connect(context.destination);
buffSource.start();
});
</script>
或使用静听-节点.js文件 数字 文件夹 :
<script src="silence-listener-node.js"></script>
配置
当创建 SilenceListener 节点实例时, 您拥有可用的选项数 :
let context = new AudioContext();
let nChannels = 2;
// entries are defaults
let options = {
nInputs: 1, // The number of inputs connected to this node. Probably 1
nOutputs: 1, // The number of outputs connected to this node. Probably 1
batchSize: 512, // Stuck at 128 for `AudioWorklet`s. Can be powers of 2 where 256 < batchSize < 16384
silenceThreshold: Math.floor(44100 / batchSize), // This is the number of silent batches which must
// occur before silence callbacks are invoked.
pathToWorklet: '/sln.worklet.js' //The path to the worklet file
}
createSilenceListenerNode(context, nChannels, options).then((silenceListenerNode) => { ... });
nInputs
数目 AudioNodes与这个Silence ListenerNode事件有关. 默认 1.
nOutputs
产出的倒数 AudioNodes 此 SilenceLisner 节点连接到此实例 。 默认 1.
batchSize
修改处理的批量大小 ScriptProcessorNode。这不影响 AudioWorklet因为他们被卡在128。 如果使用脚本处理器节点,则必须是下列之一: [256, 512, 1024, 2048, 4096, 8192, 16384]。 。 。 .
silenceThreshold
在音频流之前必须出现的静态批次数将被标为静态. 默认是(大概)一秒钟的音频值.
pathToWorklet
您的地址 : sln.worklet.js (英语) 文档。 默认位于服务器根 .
API 参考
一旦你创建了静听节点 createSilenceListener() 或者说 SilenceListenerNode.createSilenceListener(),返回对象会暴露:
connect
/**
* Connects SilenceListenerNode to the specific destination AudioNode
*
* @param {AudioNode} destination The node to connect to
*/
connect(destination) { ... }
disconnect
/** Disconnects from the currently-connected AudioNode */
disconnect() { ... }
subscribeToSilence
/**
* Begin receiving silence notifications
*
* @param { Function(isSilent, timeSinceLast) } callback Invoked whenever audio becomes or unbecomes silent
* @return { String } id of the subscription. use with unsubscribeFromSilence(id) to stop receiving notifications
*/
subscribeToSilence(callback) { ... }
unsubscribeFromSilence
/**
* Stop receiving silence events for given ID.
*
* @param { String } id Identifier for callback subscription
*/
unsubscribeFromSilence(id) { ... }
getters
get silent() { ... }
get silence() { ... } // for simplicity
get numberOfInputs() { ... }
get numberOfOutputs() { ... }
get channelCount() { ... }
get channelCountMode() { ... }
get channelInterpretation() { ... }
// e.g. let isSilent = silenceListenerNode.silent;
setters
set channelCount(channelCount) { ... }
set channelCountMode(channelCountMode) { ... }
set channelInterpretation(channelInterpretation) { ... }
// e.g. silenceListenerNode.channelInterpretation = 'speakers';
实例
运行任何服务器( R)http-服务器项目目录中的:
cd silence-listener-node
http-server
访问 当地主机:8080/实例/基本 或者说 本地主机: 8080/ 实例/反应 在浏览器中。 实例 必须是 主机来自根目录,因为他们需要访问文件 数字。 。 。 .
从源建置
git clone https://github.com/aolsenjazz/silence-listener-node
cd silence-listener-node
npm run watch
制作文件放在 数字 目录.
未实现(承诺) DOM Exception:用户中止请求.
当 SilenceListener Node 找不到您的 sln. worklet.js 时, 就会出现这个无益的错误消息 。 为了解决这个问题,确保你 options.pathToWorklet 设置正确,且文件在该位置实际上可以到达.
捐款
欢迎拉动请求。 对于重大变动,请先开出一个问题来讨论你想要改变什么.
许可证
许可证有: LICENSE.md。 。 。 .