@tekyzinc/stt-component 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +279 -0
- package/dist/index.cjs +482 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +223 -0
- package/dist/index.d.ts +223 -0
- package/dist/index.js +445 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/** Supported Whisper model sizes. */
|
|
2
|
+
type STTModelSize = 'tiny' | 'base' | 'small' | 'medium';
|
|
3
|
+
/** Supported compute backends. */
|
|
4
|
+
type STTBackend = 'webgpu' | 'wasm' | 'auto';
|
|
5
|
+
/** Engine lifecycle states. */
|
|
6
|
+
type STTStatus = 'idle' | 'loading' | 'ready' | 'recording' | 'processing';
|
|
7
|
+
/** Correction timing configuration. */
|
|
8
|
+
interface STTCorrectionConfig {
|
|
9
|
+
/** Enable mid-recording Whisper correction. Default: true */
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
/** Silence duration (ms) before triggering correction. Default: 3000 */
|
|
12
|
+
pauseThreshold?: number;
|
|
13
|
+
/** Maximum interval (ms) between forced corrections. Default: 5000 */
|
|
14
|
+
forcedInterval?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Audio chunking configuration for long-form audio. */
|
|
17
|
+
interface STTChunkingConfig {
|
|
18
|
+
/** Chunk length in seconds for Whisper processing. Default: 30 */
|
|
19
|
+
chunkLengthS?: number;
|
|
20
|
+
/** Stride length in seconds for overlapping chunks. Default: 5 */
|
|
21
|
+
strideLengthS?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Full engine configuration. All fields optional — sensible defaults applied. */
|
|
24
|
+
interface STTConfig {
|
|
25
|
+
/** Whisper model size. Default: 'tiny' */
|
|
26
|
+
model?: STTModelSize;
|
|
27
|
+
/** Compute backend preference. Default: 'auto' (WebGPU with WASM fallback) */
|
|
28
|
+
backend?: STTBackend;
|
|
29
|
+
/** Transcription language. Default: 'en' */
|
|
30
|
+
language?: string;
|
|
31
|
+
/** Model quantization dtype. Default: 'q4' */
|
|
32
|
+
dtype?: string;
|
|
33
|
+
/** Mid-recording correction settings. */
|
|
34
|
+
correction?: STTCorrectionConfig;
|
|
35
|
+
/** Audio chunking settings for long-form audio. */
|
|
36
|
+
chunking?: STTChunkingConfig;
|
|
37
|
+
}
|
|
38
|
+
/** Resolved configuration with all defaults applied. */
|
|
39
|
+
interface ResolvedSTTConfig {
|
|
40
|
+
model: STTModelSize;
|
|
41
|
+
backend: STTBackend;
|
|
42
|
+
language: string;
|
|
43
|
+
dtype: string;
|
|
44
|
+
correction: Required<STTCorrectionConfig>;
|
|
45
|
+
chunking: Required<STTChunkingConfig>;
|
|
46
|
+
}
|
|
47
|
+
/** Engine state exposed to consumers via status events. */
|
|
48
|
+
interface STTState {
|
|
49
|
+
status: STTStatus;
|
|
50
|
+
isModelLoaded: boolean;
|
|
51
|
+
/** Model download progress (0–100). */
|
|
52
|
+
loadProgress: number;
|
|
53
|
+
/** Active compute backend, or null if not yet determined. */
|
|
54
|
+
backend: 'webgpu' | 'wasm' | null;
|
|
55
|
+
error: string | null;
|
|
56
|
+
}
|
|
57
|
+
/** Structured error emitted via the 'error' event. */
|
|
58
|
+
interface STTError {
|
|
59
|
+
code: string;
|
|
60
|
+
message: string;
|
|
61
|
+
}
|
|
62
|
+
/** Event map for the typed event emitter. */
|
|
63
|
+
type STTEvents = {
|
|
64
|
+
/** Streaming interim text during recording. */
|
|
65
|
+
transcript: (text: string) => void;
|
|
66
|
+
/** Whisper-corrected text replacing interim text. */
|
|
67
|
+
correction: (text: string) => void;
|
|
68
|
+
/** Actionable error (mic denied, model fail, transcription fail). */
|
|
69
|
+
error: (error: STTError) => void;
|
|
70
|
+
/** Engine state change. */
|
|
71
|
+
status: (state: STTState) => void;
|
|
72
|
+
};
|
|
73
|
+
/** Handle returned by audio capture — used internally. */
|
|
74
|
+
interface AudioCaptureHandle {
|
|
75
|
+
audioCtx: AudioContext;
|
|
76
|
+
stream: MediaStream;
|
|
77
|
+
samples: Float32Array[];
|
|
78
|
+
/** Retain reference to prevent GC from stopping audio processing. */
|
|
79
|
+
_processor: ScriptProcessorNode;
|
|
80
|
+
}
|
|
81
|
+
/** Default configuration values. */
|
|
82
|
+
declare const DEFAULT_STT_CONFIG: ResolvedSTTConfig;
|
|
83
|
+
/** Merge user config with defaults to produce resolved config. */
|
|
84
|
+
declare function resolveConfig(config?: STTConfig): ResolvedSTTConfig;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A generic, typed event emitter.
|
|
88
|
+
*
|
|
89
|
+
* Type parameter `T` is a map of event names to listener signatures,
|
|
90
|
+
* giving consumers compile-time safety on event names and callback args.
|
|
91
|
+
*/
|
|
92
|
+
declare class TypedEventEmitter<T extends Record<string, (...args: any[]) => void>> {
|
|
93
|
+
private listeners;
|
|
94
|
+
/** Subscribe to an event. */
|
|
95
|
+
on<K extends keyof T>(event: K, listener: T[K]): void;
|
|
96
|
+
/** Unsubscribe a specific listener. No-op if not registered. */
|
|
97
|
+
off<K extends keyof T>(event: K, listener: T[K]): void;
|
|
98
|
+
/** Emit an event, calling all registered listeners in insertion order. */
|
|
99
|
+
emit<K extends keyof T>(event: K, ...args: Parameters<T[K]>): void;
|
|
100
|
+
/** Remove all listeners, optionally for a single event. */
|
|
101
|
+
removeAllListeners(event?: keyof T): void;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Start capturing raw PCM audio from the microphone.
|
|
106
|
+
* Uses ScriptProcessorNode to collect Float32Array samples directly.
|
|
107
|
+
*/
|
|
108
|
+
declare function startCapture(): Promise<AudioCaptureHandle>;
|
|
109
|
+
/**
|
|
110
|
+
* Copy current audio buffer without stopping capture.
|
|
111
|
+
* Returns a shallow copy of the samples array (each chunk is shared, not cloned).
|
|
112
|
+
*/
|
|
113
|
+
declare function snapshotAudio(capture: AudioCaptureHandle): Float32Array[];
|
|
114
|
+
/**
|
|
115
|
+
* Concatenate sample chunks and resample to 16kHz for Whisper.
|
|
116
|
+
*/
|
|
117
|
+
declare function resampleAudio(samples: Float32Array[], nativeSr: number): Promise<Float32Array>;
|
|
118
|
+
/**
|
|
119
|
+
* Stop capturing and return resampled audio at 16kHz.
|
|
120
|
+
*/
|
|
121
|
+
declare function stopCapture(capture: AudioCaptureHandle): Promise<Float32Array>;
|
|
122
|
+
|
|
123
|
+
/** Events emitted by the WorkerManager. */
|
|
124
|
+
type WorkerManagerEvents = {
|
|
125
|
+
progress: (percent: number) => void;
|
|
126
|
+
ready: () => void;
|
|
127
|
+
result: (text: string) => void;
|
|
128
|
+
error: (message: string) => void;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Manages the Whisper Web Worker lifecycle.
|
|
132
|
+
* Provides typed message passing and a promise-based transcription API.
|
|
133
|
+
*/
|
|
134
|
+
declare class WorkerManager extends TypedEventEmitter<WorkerManagerEvents> {
|
|
135
|
+
private worker;
|
|
136
|
+
private transcribeResolve;
|
|
137
|
+
private modelReadyResolve;
|
|
138
|
+
private modelReadyReject;
|
|
139
|
+
/** Spawn the Web Worker. Must be called before loadModel/transcribe. */
|
|
140
|
+
spawn(workerUrl?: URL): void;
|
|
141
|
+
/** Load the Whisper model in the worker. Resolves when ready. */
|
|
142
|
+
loadModel(config: ResolvedSTTConfig): Promise<void>;
|
|
143
|
+
/** Send audio to the worker for transcription. Resolves with text. */
|
|
144
|
+
transcribe(audio: Float32Array): Promise<string>;
|
|
145
|
+
/** Cancel any in-flight transcription. */
|
|
146
|
+
cancel(): void;
|
|
147
|
+
/** Terminate the worker and release resources. */
|
|
148
|
+
destroy(): void;
|
|
149
|
+
private handleMessage;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Manages mid-recording correction timing.
|
|
154
|
+
* Two triggers: pause detection and forced interval.
|
|
155
|
+
*/
|
|
156
|
+
declare class CorrectionOrchestrator {
|
|
157
|
+
private forcedTimer;
|
|
158
|
+
private lastCorrectionTime;
|
|
159
|
+
private correctionFn;
|
|
160
|
+
private config;
|
|
161
|
+
/** Create a new correction orchestrator with the given timing config. */
|
|
162
|
+
constructor(config: ResolvedSTTConfig['correction']);
|
|
163
|
+
/** Set the function to call when a correction is triggered. */
|
|
164
|
+
setCorrectionFn(fn: () => void): void;
|
|
165
|
+
/** Start the correction orchestrator (begin forced interval timer). */
|
|
166
|
+
start(): void;
|
|
167
|
+
/** Stop the orchestrator (clear all timers). */
|
|
168
|
+
stop(): void;
|
|
169
|
+
/** Called when a speech pause is detected. Triggers correction if cooldown elapsed. */
|
|
170
|
+
onPauseDetected(): void;
|
|
171
|
+
/** Force a correction now (resets timer). */
|
|
172
|
+
forceCorrection(): void;
|
|
173
|
+
private triggerCorrection;
|
|
174
|
+
private startForcedTimer;
|
|
175
|
+
private stopForcedTimer;
|
|
176
|
+
private restartForcedTimer;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Main STT engine — the public API for speech-to-text with Whisper correction.
|
|
181
|
+
*
|
|
182
|
+
* Usage:
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const engine = new STTEngine({ model: 'tiny' });
|
|
185
|
+
* engine.on('transcript', (text) => console.log(text));
|
|
186
|
+
* engine.on('correction', (text) => console.log('corrected:', text));
|
|
187
|
+
* await engine.init();
|
|
188
|
+
* await engine.start();
|
|
189
|
+
* const finalText = await engine.stop();
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
declare class STTEngine extends TypedEventEmitter<STTEvents> {
|
|
193
|
+
private config;
|
|
194
|
+
private workerManager;
|
|
195
|
+
private correctionOrchestrator;
|
|
196
|
+
private capture;
|
|
197
|
+
private state;
|
|
198
|
+
private workerUrl?;
|
|
199
|
+
/**
|
|
200
|
+
* Create a new STT engine instance.
|
|
201
|
+
* @param config - Optional configuration overrides (model, backend, language, etc.).
|
|
202
|
+
* @param workerUrl - Optional custom URL for the Whisper Web Worker script.
|
|
203
|
+
*/
|
|
204
|
+
constructor(config?: STTConfig, workerUrl?: URL);
|
|
205
|
+
/** Initialize the engine: spawn worker and load model. */
|
|
206
|
+
init(): Promise<void>;
|
|
207
|
+
/** Start recording audio and enable correction cycles. */
|
|
208
|
+
start(): Promise<void>;
|
|
209
|
+
/** Stop recording, run final transcription, return text. */
|
|
210
|
+
stop(): Promise<string>;
|
|
211
|
+
/** Destroy the engine: terminate worker, release all resources. */
|
|
212
|
+
destroy(): void;
|
|
213
|
+
/** Get current engine state. */
|
|
214
|
+
getState(): Readonly<STTState>;
|
|
215
|
+
/** Notify the correction orchestrator of a speech pause. */
|
|
216
|
+
notifyPause(): void;
|
|
217
|
+
private performCorrection;
|
|
218
|
+
private setupWorkerListeners;
|
|
219
|
+
private updateStatus;
|
|
220
|
+
private emitError;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export { type AudioCaptureHandle, CorrectionOrchestrator, DEFAULT_STT_CONFIG, type ResolvedSTTConfig, type STTBackend, type STTChunkingConfig, type STTConfig, type STTCorrectionConfig, STTEngine, type STTError, type STTEvents, type STTModelSize, type STTState, type STTStatus, TypedEventEmitter, WorkerManager, type WorkerManagerEvents, resampleAudio, resolveConfig, snapshotAudio, startCapture, stopCapture };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/** Supported Whisper model sizes. */
|
|
2
|
+
type STTModelSize = 'tiny' | 'base' | 'small' | 'medium';
|
|
3
|
+
/** Supported compute backends. */
|
|
4
|
+
type STTBackend = 'webgpu' | 'wasm' | 'auto';
|
|
5
|
+
/** Engine lifecycle states. */
|
|
6
|
+
type STTStatus = 'idle' | 'loading' | 'ready' | 'recording' | 'processing';
|
|
7
|
+
/** Correction timing configuration. */
|
|
8
|
+
interface STTCorrectionConfig {
|
|
9
|
+
/** Enable mid-recording Whisper correction. Default: true */
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
/** Silence duration (ms) before triggering correction. Default: 3000 */
|
|
12
|
+
pauseThreshold?: number;
|
|
13
|
+
/** Maximum interval (ms) between forced corrections. Default: 5000 */
|
|
14
|
+
forcedInterval?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Audio chunking configuration for long-form audio. */
|
|
17
|
+
interface STTChunkingConfig {
|
|
18
|
+
/** Chunk length in seconds for Whisper processing. Default: 30 */
|
|
19
|
+
chunkLengthS?: number;
|
|
20
|
+
/** Stride length in seconds for overlapping chunks. Default: 5 */
|
|
21
|
+
strideLengthS?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Full engine configuration. All fields optional — sensible defaults applied. */
|
|
24
|
+
interface STTConfig {
|
|
25
|
+
/** Whisper model size. Default: 'tiny' */
|
|
26
|
+
model?: STTModelSize;
|
|
27
|
+
/** Compute backend preference. Default: 'auto' (WebGPU with WASM fallback) */
|
|
28
|
+
backend?: STTBackend;
|
|
29
|
+
/** Transcription language. Default: 'en' */
|
|
30
|
+
language?: string;
|
|
31
|
+
/** Model quantization dtype. Default: 'q4' */
|
|
32
|
+
dtype?: string;
|
|
33
|
+
/** Mid-recording correction settings. */
|
|
34
|
+
correction?: STTCorrectionConfig;
|
|
35
|
+
/** Audio chunking settings for long-form audio. */
|
|
36
|
+
chunking?: STTChunkingConfig;
|
|
37
|
+
}
|
|
38
|
+
/** Resolved configuration with all defaults applied. */
|
|
39
|
+
interface ResolvedSTTConfig {
|
|
40
|
+
model: STTModelSize;
|
|
41
|
+
backend: STTBackend;
|
|
42
|
+
language: string;
|
|
43
|
+
dtype: string;
|
|
44
|
+
correction: Required<STTCorrectionConfig>;
|
|
45
|
+
chunking: Required<STTChunkingConfig>;
|
|
46
|
+
}
|
|
47
|
+
/** Engine state exposed to consumers via status events. */
|
|
48
|
+
interface STTState {
|
|
49
|
+
status: STTStatus;
|
|
50
|
+
isModelLoaded: boolean;
|
|
51
|
+
/** Model download progress (0–100). */
|
|
52
|
+
loadProgress: number;
|
|
53
|
+
/** Active compute backend, or null if not yet determined. */
|
|
54
|
+
backend: 'webgpu' | 'wasm' | null;
|
|
55
|
+
error: string | null;
|
|
56
|
+
}
|
|
57
|
+
/** Structured error emitted via the 'error' event. */
|
|
58
|
+
interface STTError {
|
|
59
|
+
code: string;
|
|
60
|
+
message: string;
|
|
61
|
+
}
|
|
62
|
+
/** Event map for the typed event emitter. */
|
|
63
|
+
type STTEvents = {
|
|
64
|
+
/** Streaming interim text during recording. */
|
|
65
|
+
transcript: (text: string) => void;
|
|
66
|
+
/** Whisper-corrected text replacing interim text. */
|
|
67
|
+
correction: (text: string) => void;
|
|
68
|
+
/** Actionable error (mic denied, model fail, transcription fail). */
|
|
69
|
+
error: (error: STTError) => void;
|
|
70
|
+
/** Engine state change. */
|
|
71
|
+
status: (state: STTState) => void;
|
|
72
|
+
};
|
|
73
|
+
/** Handle returned by audio capture — used internally. */
|
|
74
|
+
interface AudioCaptureHandle {
|
|
75
|
+
audioCtx: AudioContext;
|
|
76
|
+
stream: MediaStream;
|
|
77
|
+
samples: Float32Array[];
|
|
78
|
+
/** Retain reference to prevent GC from stopping audio processing. */
|
|
79
|
+
_processor: ScriptProcessorNode;
|
|
80
|
+
}
|
|
81
|
+
/** Default configuration values. */
|
|
82
|
+
declare const DEFAULT_STT_CONFIG: ResolvedSTTConfig;
|
|
83
|
+
/** Merge user config with defaults to produce resolved config. */
|
|
84
|
+
declare function resolveConfig(config?: STTConfig): ResolvedSTTConfig;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A generic, typed event emitter.
|
|
88
|
+
*
|
|
89
|
+
* Type parameter `T` is a map of event names to listener signatures,
|
|
90
|
+
* giving consumers compile-time safety on event names and callback args.
|
|
91
|
+
*/
|
|
92
|
+
declare class TypedEventEmitter<T extends Record<string, (...args: any[]) => void>> {
|
|
93
|
+
private listeners;
|
|
94
|
+
/** Subscribe to an event. */
|
|
95
|
+
on<K extends keyof T>(event: K, listener: T[K]): void;
|
|
96
|
+
/** Unsubscribe a specific listener. No-op if not registered. */
|
|
97
|
+
off<K extends keyof T>(event: K, listener: T[K]): void;
|
|
98
|
+
/** Emit an event, calling all registered listeners in insertion order. */
|
|
99
|
+
emit<K extends keyof T>(event: K, ...args: Parameters<T[K]>): void;
|
|
100
|
+
/** Remove all listeners, optionally for a single event. */
|
|
101
|
+
removeAllListeners(event?: keyof T): void;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Start capturing raw PCM audio from the microphone.
|
|
106
|
+
* Uses ScriptProcessorNode to collect Float32Array samples directly.
|
|
107
|
+
*/
|
|
108
|
+
declare function startCapture(): Promise<AudioCaptureHandle>;
|
|
109
|
+
/**
|
|
110
|
+
* Copy current audio buffer without stopping capture.
|
|
111
|
+
* Returns a shallow copy of the samples array (each chunk is shared, not cloned).
|
|
112
|
+
*/
|
|
113
|
+
declare function snapshotAudio(capture: AudioCaptureHandle): Float32Array[];
|
|
114
|
+
/**
|
|
115
|
+
* Concatenate sample chunks and resample to 16kHz for Whisper.
|
|
116
|
+
*/
|
|
117
|
+
declare function resampleAudio(samples: Float32Array[], nativeSr: number): Promise<Float32Array>;
|
|
118
|
+
/**
|
|
119
|
+
* Stop capturing and return resampled audio at 16kHz.
|
|
120
|
+
*/
|
|
121
|
+
declare function stopCapture(capture: AudioCaptureHandle): Promise<Float32Array>;
|
|
122
|
+
|
|
123
|
+
/** Events emitted by the WorkerManager. */
|
|
124
|
+
type WorkerManagerEvents = {
|
|
125
|
+
progress: (percent: number) => void;
|
|
126
|
+
ready: () => void;
|
|
127
|
+
result: (text: string) => void;
|
|
128
|
+
error: (message: string) => void;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Manages the Whisper Web Worker lifecycle.
|
|
132
|
+
* Provides typed message passing and a promise-based transcription API.
|
|
133
|
+
*/
|
|
134
|
+
declare class WorkerManager extends TypedEventEmitter<WorkerManagerEvents> {
|
|
135
|
+
private worker;
|
|
136
|
+
private transcribeResolve;
|
|
137
|
+
private modelReadyResolve;
|
|
138
|
+
private modelReadyReject;
|
|
139
|
+
/** Spawn the Web Worker. Must be called before loadModel/transcribe. */
|
|
140
|
+
spawn(workerUrl?: URL): void;
|
|
141
|
+
/** Load the Whisper model in the worker. Resolves when ready. */
|
|
142
|
+
loadModel(config: ResolvedSTTConfig): Promise<void>;
|
|
143
|
+
/** Send audio to the worker for transcription. Resolves with text. */
|
|
144
|
+
transcribe(audio: Float32Array): Promise<string>;
|
|
145
|
+
/** Cancel any in-flight transcription. */
|
|
146
|
+
cancel(): void;
|
|
147
|
+
/** Terminate the worker and release resources. */
|
|
148
|
+
destroy(): void;
|
|
149
|
+
private handleMessage;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Manages mid-recording correction timing.
|
|
154
|
+
* Two triggers: pause detection and forced interval.
|
|
155
|
+
*/
|
|
156
|
+
declare class CorrectionOrchestrator {
|
|
157
|
+
private forcedTimer;
|
|
158
|
+
private lastCorrectionTime;
|
|
159
|
+
private correctionFn;
|
|
160
|
+
private config;
|
|
161
|
+
/** Create a new correction orchestrator with the given timing config. */
|
|
162
|
+
constructor(config: ResolvedSTTConfig['correction']);
|
|
163
|
+
/** Set the function to call when a correction is triggered. */
|
|
164
|
+
setCorrectionFn(fn: () => void): void;
|
|
165
|
+
/** Start the correction orchestrator (begin forced interval timer). */
|
|
166
|
+
start(): void;
|
|
167
|
+
/** Stop the orchestrator (clear all timers). */
|
|
168
|
+
stop(): void;
|
|
169
|
+
/** Called when a speech pause is detected. Triggers correction if cooldown elapsed. */
|
|
170
|
+
onPauseDetected(): void;
|
|
171
|
+
/** Force a correction now (resets timer). */
|
|
172
|
+
forceCorrection(): void;
|
|
173
|
+
private triggerCorrection;
|
|
174
|
+
private startForcedTimer;
|
|
175
|
+
private stopForcedTimer;
|
|
176
|
+
private restartForcedTimer;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Main STT engine — the public API for speech-to-text with Whisper correction.
|
|
181
|
+
*
|
|
182
|
+
* Usage:
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const engine = new STTEngine({ model: 'tiny' });
|
|
185
|
+
* engine.on('transcript', (text) => console.log(text));
|
|
186
|
+
* engine.on('correction', (text) => console.log('corrected:', text));
|
|
187
|
+
* await engine.init();
|
|
188
|
+
* await engine.start();
|
|
189
|
+
* const finalText = await engine.stop();
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
declare class STTEngine extends TypedEventEmitter<STTEvents> {
|
|
193
|
+
private config;
|
|
194
|
+
private workerManager;
|
|
195
|
+
private correctionOrchestrator;
|
|
196
|
+
private capture;
|
|
197
|
+
private state;
|
|
198
|
+
private workerUrl?;
|
|
199
|
+
/**
|
|
200
|
+
* Create a new STT engine instance.
|
|
201
|
+
* @param config - Optional configuration overrides (model, backend, language, etc.).
|
|
202
|
+
* @param workerUrl - Optional custom URL for the Whisper Web Worker script.
|
|
203
|
+
*/
|
|
204
|
+
constructor(config?: STTConfig, workerUrl?: URL);
|
|
205
|
+
/** Initialize the engine: spawn worker and load model. */
|
|
206
|
+
init(): Promise<void>;
|
|
207
|
+
/** Start recording audio and enable correction cycles. */
|
|
208
|
+
start(): Promise<void>;
|
|
209
|
+
/** Stop recording, run final transcription, return text. */
|
|
210
|
+
stop(): Promise<string>;
|
|
211
|
+
/** Destroy the engine: terminate worker, release all resources. */
|
|
212
|
+
destroy(): void;
|
|
213
|
+
/** Get current engine state. */
|
|
214
|
+
getState(): Readonly<STTState>;
|
|
215
|
+
/** Notify the correction orchestrator of a speech pause. */
|
|
216
|
+
notifyPause(): void;
|
|
217
|
+
private performCorrection;
|
|
218
|
+
private setupWorkerListeners;
|
|
219
|
+
private updateStatus;
|
|
220
|
+
private emitError;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export { type AudioCaptureHandle, CorrectionOrchestrator, DEFAULT_STT_CONFIG, type ResolvedSTTConfig, type STTBackend, type STTChunkingConfig, type STTConfig, type STTCorrectionConfig, STTEngine, type STTError, type STTEvents, type STTModelSize, type STTState, type STTStatus, TypedEventEmitter, WorkerManager, type WorkerManagerEvents, resampleAudio, resolveConfig, snapshotAudio, startCapture, stopCapture };
|