web-asr-core
Version:
WebASR Core - Browser-based speech processing with VAD, WakeWord and Whisper - Unified all-in-one version
90 lines • 2.33 kB
TypeScript
/**
* ONNX Runtime Web Worker for Model Inference
*
* 執行 VAD 和喚醒詞模型推理的 Web Worker,支援 WebGPU 加速
*/
declare const isModuleWorker: boolean;
declare const importScripts: any;
declare namespace ort {
class Tensor {
constructor(type: string, data: any, shape: number[]);
data: any;
}
class InferenceSession {
static create(path: string, options: any): Promise<InferenceSession>;
run(feeds: any): Promise<any>;
}
interface ExecutionProviderConfig {
name: string;
[key: string]: any;
}
const env: {
wasm: {
simd: boolean;
numThreads: number;
wasmPaths: string;
};
webgpu: {
powerPreference: string;
};
};
}
interface ModelConfig {
modelPath: string;
executionProviders: string[];
webgpuOptions?: {
powerPreference?: 'default' | 'low-power' | 'high-performance';
};
wasmOptions?: {
simd?: boolean;
numThreads?: number;
};
}
interface InferenceRequest {
id: string;
type: 'vad' | 'wakeword';
modelName: string;
inputData: Float32Array;
config?: ModelConfig;
}
interface InferenceResponse {
id: string;
type: 'vad' | 'wakeword';
result: any;
error?: string;
executionTime?: number;
provider?: string;
}
/**
* Worker 事件橋接器
*
* @description 負責將 Worker 內部的事件轉發到主執行緒
*/
declare class WorkerEventBridge {
/**
* 發送事件到主執行緒
*/
static emitEvent(eventType: string, detail: any): void;
/**
* 發送處理錯誤事件
*/
static emitError(error: Error, context: string): void;
}
declare class ONNXInferenceWorker {
private sessions;
private vadStates;
private vadActiveStates;
private isWebGPUAvailable;
constructor();
private isVadActive;
private setVadActive;
private initialize;
private loadModel;
private runVADInference;
private runWakeWordInference;
processInference(request: InferenceRequest): Promise<InferenceResponse>;
preloadModel(modelName: string, config: ModelConfig): Promise<void>;
clearCache(): void;
}
declare const worker: ONNXInferenceWorker;
//# sourceMappingURL=onnx-inference.worker.d.ts.map