browser-vad-test
v0.0.7
Published
Browser-based Voice Activity Detection using Silero VAD
Maintainers
Readme
Browser VAD (Voice Activity Detection)
A simple browser-based Voice Activity Detection library using Silero VAD.
Installation
npm install browser-vadUsage
import VAD from 'browser-vad';
// Initialize VAD (must be called before using other methods)
await VAD.initialize();
// Optionally, you can provide a custom model path
// await VAD.initialize('./path/to/silero_vad.onnx');
// Start voice detection
await VAD.start();
// Stop voice detection
VAD.stop();
// Toggle between start and stop
const isRecording = await VAD.toggle();
// Listen for state changes (speaking/not speaking)
VAD.onStateChange((state) => {
console.log('VAD State:', state);
// state = {
// status: 'active' | 'inactive',
// probability: number,
// ratio: number
// }
});
// Listen for audio data
VAD.onDataAvailable((audioBlob) => {
// audioBlob is a WAV file blob containing the recorded audio
console.log('Audio data received:', audioBlob);
});API Reference
VAD.initialize(modelPath?: string): Promise<boolean>
Initializes the VAD system. Must be called before using other methods.
modelPath: Optional path to the Silero VAD model file. If not provided, uses the default model.- Returns: Promise that resolves to true if initialization was successful.
VAD.start(): Promise<boolean>
Starts voice detection.
- Returns: Promise that resolves to true if successfully started.
VAD.stop(): void
Stops voice detection.
VAD.toggle(): Promise<boolean>
Toggles between start and stop states.
- Returns: Promise that resolves to the new recording state (true if recording, false if stopped).
VAD.onStateChange(callback: function): void
Sets up a callback for voice activity state changes.
callback: Function that receives state updates with the following structure:{ status: 'active' | 'inactive', // active when voice detected probability: number, // confidence score ratio: number // ratio of voice frames }
VAD.onDataAvailable(callback: function): void
Sets up a callback for receiving audio data.
callback: Function that receives a WAV Blob containing the recorded audio.
