Open History to see the last commit
1/** Cancellation is cooperative: settle only after the underlying work has stopped. */
2export type VoiceTranscriptionOptions = {
3 readonly signal: AbortSignal;
4};
5
6export type PreparedVoiceTranscription = {
7 readonly locale: string;
8 readonly transcribe: (uri: string, options: VoiceTranscriptionOptions) => Promise<string>;
9};
10
11export type VoiceTranscriber = {
12 readonly prepare: (options: VoiceTranscriptionOptions) => Promise<PreparedVoiceTranscription>;
13};
14
15export type VoiceTranscriptionErrorCode =
16 | "unavailable"
17 | "unsupported-locale"
18 | "preparation-failed"
19 | "transcription-failed"
20 | "cancelled";
21
22export class VoiceTranscriptionError extends Error {
23 readonly code: VoiceTranscriptionErrorCode;
24
25 constructor(code: VoiceTranscriptionErrorCode, message: string, options?: ErrorOptions) {
26 super(message, options);
27 this.name = "VoiceTranscriptionError";
28 this.code = code;
29 }
30}
31
32export function throwIfVoiceTranscriptionAborted(signal: AbortSignal): void {
33 if (signal.aborted) {
34 throw new VoiceTranscriptionError("cancelled", "Voice transcription was cancelled.");
35 }
36}