从 https://github.com/ricky0123/vad (英语) 它支持网络和反应。 它曾经支持节点,但并不是实时的. 这里基于节点和实时.
详情见项目之家.
特征
- 实时和非实时语音活动检测
- 以Silero VAD模式建造
- 方便使用 API
- 工程全线下线
- 服务器环境的有效处理
安装
npm install @ericedouard/vad-node-realtime
使用量
实时 VAD
使用 RealTimeVAD 当您需要实时处理音频块时, 如接收客户端应用程序的音频 :
const { RealTimeVAD } = require('@eric-edouard/vad-node-realtime');
async function example() {
// Create a new RealTimeVAD instance
const vad = await RealTimeVAD.new({
onSpeechStart: () => {
console.log('Speech started');
},
onSpeechEnd: (audio) => {
console.log('Speech ended, received audio of length:', audio.length);
// Process the audio data here
},
// Optional: customize VAD parameters
positiveSpeechThreshold: 0.6,
negativeSpeechThreshold: 0.4,
minSpeechFrames: 4,
});
// Start processing
vad.start();
// When you receive audio chunks from your source:
function onAudioChunkReceived(audioChunk) {
// Process each chunk of audio data
// audioChunk should be a Float32Array with sample rate matching the sampleRate option (default: 16000Hz)
await vad.processAudio(audioChunk);
}
// When you're done with the stream:
await vad.flush(); // Process any remaining audio
vad.destroy(); // Clean up resources
}
example();
非实时 VAD
用于处理整个音频文件或预录块 :
const { NonRealTimeVAD } = require('@eric-edouard/vad-node-realtime');
async function example() {
const vad = await NonRealTimeVAD.new();
// audioData is a Float32Array of audio samples
// sampleRate is the sample rate of the audio
for await (const { audio, start, end } of vad.run(audioData, sampleRate)) {
console.log(`Speech detected from ${start}ms to ${end}ms`);
// Process detected speech segment
}
}
API 参考
实时VAD
RealTimeVAD.new(options): 创建新的 RealTimeVAD 实例start(): 开始处理音频pause(): 暂停音频处理processAudio(audioData): 处理一整块音频数据flush(): 处理任何剩余音频并触发最后回调reset(): 重置 VAD 状态destroy(): 清理资源
实时VAD 选项
sampleRate: 输入音频的样本率( 默认: 16,000, 不同样本率的输入会自动被重印)onSpeechStart: 发言开始时召回onSpeechEnd: 语音结束时使用音频数据调回onVADMisfire: 检测到语音但太短时召回onFrameProcessed: 每个框架处理后召回positiveSpeechThreshold: 探测语音的阈值(0-1)negativeSpeechThreshold: 探测沉默的阈值(0-1)minSpeechFrames: 用作语音的最小框架数
许可证
公务员制度委员会