forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
51 lines (49 loc) · 1.88 KB
/
Copy pathindex.ts
File metadata and controls
51 lines (49 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { createDeepgramTranscriber } from './deepgram';
import { createParakeetTranscriber } from './parakeet';
import { createWhisperTranscriber } from './whisper';
import type { SttEngine, StreamingTranscriber, TranscriptHandler } from './types';
export type { SttEngine, StreamingTranscriber, TranscriptHandler } from './types';
export { createDeepgramTranscriber } from './deepgram';
export { createParakeetTranscriber, parakeetWsUrl } from './parakeet';
export { createWhisperTranscriber } from './whisper';
export function createTranscriber(
engine: SttEngine,
options: {
onTranscript: TranscriptHandler;
apiKey?: string;
apiUrl?: string;
sampleRate?: number;
whisperRunner?: (pcm: Uint8Array) => Promise<string> | string;
createWebSocket?: (url: string, headers: Record<string, string>) => WebSocket;
}
): StreamingTranscriber {
switch (engine) {
case 'deepgram':
if (!options.apiKey) throw new Error('Deepgram apiKey required');
return createDeepgramTranscriber({
apiKey: options.apiKey,
sampleRate: options.sampleRate,
onTranscript: options.onTranscript,
createWebSocket: options.createWebSocket,
});
case 'parakeet': {
const apiUrl = options.apiUrl || (globalThis as any)?.process?.env?.HOSTED_PARAKEET_API_URL;
if (!apiUrl) throw new Error('Parakeet apiUrl or HOSTED_PARAKEET_API_URL required');
return createParakeetTranscriber({
apiUrl,
sampleRate: options.sampleRate,
onTranscript: options.onTranscript,
});
}
case 'whisper':
if (!options.whisperRunner) {
throw new Error('Whisper requires whisperRunner (feature-gated local model)');
}
return createWhisperTranscriber({
runner: options.whisperRunner,
onTranscript: options.onTranscript,
});
default:
throw new Error(`Unknown STT engine: ${engine}`);
}
}