UNPKG

web-voice-detection

Version:

A WebAssembly-powered Voice Activity Detection library for the browser.

67 lines (66 loc) 2.64 kB
import * as ortInstance from "onnxruntime-web"; import { FrameProcessor, FrameProcessorOptions, Message, OrtOptions, SpeechProbabilities } from "./common"; type RealTimeDetectionCallbacks = { onFrameProcessed: (data: FrameData) => any; onMisfire: () => any; onSpeechStart: () => any; onSpeechEnd: (audio: Float32Array) => any; onFFTProcessed: (fftData: Float32Array) => any; fftSize: number; }; type AudioConstraints = Omit<MediaTrackConstraints, "channelCount" | "echoCancellation" | "autoGainControl" | "noiseSuppression">; type AssetOptions = { workletURL: string; modelURL: string; modelFetcher: (path: string) => Promise<ArrayBuffer>; }; type RealTimeDetectionOptionsWithoutStream = { additionalAudioConstraints?: AudioConstraints; stream: undefined; } & FrameProcessorOptions & RealTimeDetectionCallbacks & OrtOptions & AssetOptions; type RealTimeDetectionOptionsWithStream = { stream: MediaStream; } & FrameProcessorOptions & RealTimeDetectionCallbacks & OrtOptions & AssetOptions; export declare const ort: typeof ortInstance; export type RealTimeDetectionOptions = RealTimeDetectionOptionsWithStream | RealTimeDetectionOptionsWithoutStream; type FrameData = { probabilities: SpeechProbabilities; fftData: Float32Array; }; export declare const defaultRealTimeDetectionOptions: RealTimeDetectionOptions; export declare class Detect { options: RealTimeDetectionOptions; private audioContext; private stream; private audioNodeDetection; private sourceNode; analyserNode: AnalyserNode; listening: boolean; static new(options?: Partial<RealTimeDetectionOptions>): Promise<Detect>; private constructor(); pause: () => void; start: () => void; destroy: () => void; } export declare class AudioNodeDetection { ctx: AudioContext; options: RealTimeDetectionOptions; private frameProcessor; private entryNode; private analyserNode; static new(ctx: AudioContext, options: Partial<RealTimeDetectionOptions> | undefined, analyserNode: AnalyserNode): Promise<AudioNodeDetection>; private isProcessing; constructor(ctx: AudioContext, options: RealTimeDetectionOptions, frameProcessor: FrameProcessor, entryNode: AudioWorkletNode, analyserNode: AnalyserNode); pause: () => void; start: () => void; receive: (node: AudioNode) => void; processFrame: (frame: Float32Array) => Promise<void>; handleFrameProcessorEvent: (ev: Partial<{ probs: SpeechProbabilities; msg: Message; audio: Float32Array; }>) => void; private processFFT; destroy: () => void; } export {};