node-api / server /realtime-stt-provider.ts
taqarub's picture
Integrate ShihabASR streaming provider
a202950
Raw History Blame Contribute Delete
966 Bytes
import type { BufferedAudioFrame } from "../shared/realtime-voice-protocol";
export type SendVoiceMessage = (message: Record<string, unknown>) => void;
export interface RealtimeSttRecognizer {
start(): Promise<void>;
accept(frame: BufferedAudioFrame): void;
stop(): void;
close(): void;
acknowledgedSequence(): number;
replayTranscriptEvents(): void;
}
export type SttProvider = "existing" | "shihab";
export type SttEnvironment = Record<string, string | undefined>;
export function resolveSttProvider(
environment: SttEnvironment = process.env,
): SttProvider {
const configured = (environment.STT_PROVIDER ?? "shihab")
.trim()
.toLowerCase();
if (configured !== "existing" && configured !== "shihab") {
throw new Error(
`Unsupported STT_PROVIDER=${configured}; expected existing or shihab`,
);
}
if (configured === "shihab" && !environment.SHIHAB_API_KEY?.trim()) {
return "existing";
}
return configured;
}