@handsforbots/voice 0.0.0-stage → 2.0.0-alpha.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.
Files changed (47) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +20 -2
  3. package/dist/index.d.ts +11 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +11 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/player.d.ts +33 -0
  8. package/dist/player.d.ts.map +1 -0
  9. package/dist/player.js +141 -0
  10. package/dist/player.js.map +1 -0
  11. package/dist/providers/echo.d.ts +25 -0
  12. package/dist/providers/echo.d.ts.map +1 -0
  13. package/dist/providers/echo.js +85 -0
  14. package/dist/providers/echo.js.map +1 -0
  15. package/dist/providers/end-of-turn.d.ts +22 -0
  16. package/dist/providers/end-of-turn.d.ts.map +1 -0
  17. package/dist/providers/end-of-turn.js +29 -0
  18. package/dist/providers/end-of-turn.js.map +1 -0
  19. package/dist/providers/http.d.ts +48 -0
  20. package/dist/providers/http.d.ts.map +1 -0
  21. package/dist/providers/http.js +153 -0
  22. package/dist/providers/http.js.map +1 -0
  23. package/dist/providers/media.d.ts +15 -0
  24. package/dist/providers/media.d.ts.map +1 -0
  25. package/dist/providers/media.js +122 -0
  26. package/dist/providers/media.js.map +1 -0
  27. package/dist/providers/vosk-browser.d.ts +33 -0
  28. package/dist/providers/vosk-browser.d.ts.map +1 -0
  29. package/dist/providers/vosk-browser.js +82 -0
  30. package/dist/providers/vosk-browser.js.map +1 -0
  31. package/dist/providers/websocket.d.ts +38 -0
  32. package/dist/providers/websocket.d.ts.map +1 -0
  33. package/dist/providers/websocket.js +94 -0
  34. package/dist/providers/websocket.js.map +1 -0
  35. package/dist/providers/webspeech.d.ts +40 -0
  36. package/dist/providers/webspeech.d.ts.map +1 -0
  37. package/dist/providers/webspeech.js +201 -0
  38. package/dist/providers/webspeech.js.map +1 -0
  39. package/dist/types.d.ts +263 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +20 -0
  42. package/dist/types.js.map +1 -0
  43. package/dist/voice.d.ts +283 -0
  44. package/dist/voice.d.ts.map +1 -0
  45. package/dist/voice.js +1209 -0
  46. package/dist/voice.js.map +1 -0
  47. package/package.json +37 -3
@@ -0,0 +1,201 @@
1
+ import { SpeechError } from '../types.js';
2
+ function recognitionCtor() {
3
+ if (typeof window === 'undefined')
4
+ return undefined;
5
+ const w = window;
6
+ return w.SpeechRecognition ?? w.webkitSpeechRecognition;
7
+ }
8
+ const ERROR_CODES = {
9
+ 'not-allowed': 'not-allowed',
10
+ 'service-not-allowed': 'service-not-allowed',
11
+ 'no-speech': 'no-speech',
12
+ 'audio-capture': 'audio-capture',
13
+ network: 'network',
14
+ aborted: 'aborted',
15
+ 'language-not-supported': 'not-supported',
16
+ };
17
+ const isAndroid = () => typeof navigator !== 'undefined' && /android/i.test(navigator.userAgent ?? '');
18
+ /** Browser speech recognition (Web Speech API). Quality and privacy depend on the browser vendor. */
19
+ export function webSpeechSTT(sttOptions = {}) {
20
+ const mode = sttOptions.continuous ?? 'auto';
21
+ const nativeContinuous = () => (mode === 'auto' ? !isAndroid() : mode);
22
+ return {
23
+ name: 'webspeech',
24
+ capabilities: { partials: true, continuous: nativeContinuous(), offline: false },
25
+ // Browsers such as Chrome send the audio to their speech service.
26
+ remote: true,
27
+ // Outside a secure context the API exists but every session fails as a denied permission.
28
+ isSupported: () => recognitionCtor() !== undefined && window.isSecureContext !== false,
29
+ listen(options, handlers) {
30
+ const Ctor = recognitionCtor();
31
+ if (!Ctor)
32
+ throw new SpeechError('not-supported', 'Web Speech recognition is not available');
33
+ const recognition = new Ctor();
34
+ recognition.lang = options.language;
35
+ recognition.continuous = options.continuous && nativeContinuous();
36
+ recognition.interimResults = true;
37
+ recognition.maxAlternatives = 1;
38
+ recognition.onresult = (event) => {
39
+ let interim = '';
40
+ for (let i = event.resultIndex; i < event.results.length; i++) {
41
+ const result = event.results[i];
42
+ const alternative = result[0];
43
+ if (result.isFinal) {
44
+ const text = String(alternative.transcript ?? '').trim();
45
+ if (text)
46
+ handlers.onFinal(text, { confidence: alternative.confidence });
47
+ }
48
+ else {
49
+ interim += alternative.transcript;
50
+ }
51
+ }
52
+ if (interim)
53
+ handlers.onPartial?.(interim.trim());
54
+ };
55
+ recognition.onerror = (event) => {
56
+ const code = ERROR_CODES[event.error] ?? 'unknown';
57
+ if (code !== 'aborted')
58
+ handlers.onError(new SpeechError(code, event.message || event.error));
59
+ };
60
+ recognition.onend = () => handlers.onEnd();
61
+ recognition.start();
62
+ return {
63
+ stop: () => recognition.stop(),
64
+ abort: () => recognition.abort(),
65
+ };
66
+ },
67
+ };
68
+ }
69
+ /** Utterance errors that only mean the speech was stopped on purpose. */
70
+ const STOPPED = new Set(['interrupted', 'canceled']);
71
+ /** Browser speech synthesis. */
72
+ export function webSpeechTTS(options = {}) {
73
+ const synth = () => (typeof window !== 'undefined' ? window.speechSynthesis : undefined);
74
+ const startTimeout = options.startTimeout ?? 5000;
75
+ let unlocked = false;
76
+ const voices = async () => {
77
+ const s = synth();
78
+ if (!s)
79
+ return [];
80
+ const list = s.getVoices();
81
+ if (list.length)
82
+ return list;
83
+ // Voices load asynchronously in some browsers.
84
+ return new Promise((resolve) => {
85
+ const done = () => resolve(s.getVoices());
86
+ s.addEventListener?.('voiceschanged', done, { once: true });
87
+ setTimeout(done, 800);
88
+ });
89
+ };
90
+ const pickVoice = async (language, name) => {
91
+ const list = await voices();
92
+ const wanted = name ?? options.voice;
93
+ if (typeof wanted === 'function')
94
+ return list.find(wanted);
95
+ if (wanted)
96
+ return list.find((v) => v.name === wanted);
97
+ const lang = language.toLowerCase().replace('_', '-');
98
+ return (list.find((v) => v.lang.toLowerCase().replace('_', '-') === lang) ??
99
+ list.find((v) => v.lang.toLowerCase().startsWith(lang.split('-')[0])));
100
+ };
101
+ return {
102
+ name: 'webspeech',
103
+ isSupported: () => synth() !== undefined && typeof SpeechSynthesisUtterance !== 'undefined',
104
+ // The browser's audio cannot go through Web Audio: effects reach it only as prosody.
105
+ prosody: { rate: true, pitch: true, volume: true },
106
+ async speak(text, speakOptions) {
107
+ const s = synth();
108
+ if (!s)
109
+ throw new SpeechError('not-supported', 'Speech synthesis is not available', 'speak');
110
+ const voice = await pickVoice(speakOptions.language, speakOptions.voice);
111
+ const { rate, pitch, volume } = utteranceProsody(options, speakOptions.prosody);
112
+ for (const sentence of splitSentences(text)) {
113
+ if (speakOptions.signal?.aborted)
114
+ return;
115
+ await new Promise((resolve, reject) => {
116
+ let timer;
117
+ let settled = false;
118
+ let started = false;
119
+ const finish = (error) => {
120
+ if (settled)
121
+ return;
122
+ settled = true;
123
+ clearTimeout(timer);
124
+ if (error)
125
+ reject(error);
126
+ else
127
+ resolve();
128
+ };
129
+ const utterance = new SpeechSynthesisUtterance(sentence);
130
+ utterance.lang = speakOptions.language;
131
+ if (voice)
132
+ utterance.voice = voice;
133
+ if (rate !== 1)
134
+ utterance.rate = rate;
135
+ if (pitch !== 1)
136
+ utterance.pitch = pitch;
137
+ if (volume !== 1)
138
+ utterance.volume = volume;
139
+ utterance.onstart = () => {
140
+ started = true;
141
+ clearTimeout(timer);
142
+ };
143
+ utterance.onend = () => finish();
144
+ utterance.onerror = (event) => {
145
+ const reason = event?.error;
146
+ if (speakOptions.signal?.aborted || (reason && STOPPED.has(reason)))
147
+ return finish();
148
+ const code = reason === 'not-allowed' ? 'output-blocked' : 'synthesis-failed';
149
+ finish(new SpeechError(code, `speechSynthesis: ${reason ?? 'error'}`, 'speak'));
150
+ };
151
+ speakOptions.signal?.addEventListener('abort', () => finish(), { once: true });
152
+ s.speak(utterance);
153
+ if (startTimeout > 0 && !settled && !started) {
154
+ timer = setTimeout(() => {
155
+ s.cancel();
156
+ finish(new SpeechError('synthesis-failed', `speechSynthesis did not start within ${startTimeout} ms`, 'speak'));
157
+ }, startTimeout);
158
+ }
159
+ });
160
+ }
161
+ },
162
+ unlock() {
163
+ const s = synth();
164
+ if (unlocked || !s || typeof SpeechSynthesisUtterance === 'undefined')
165
+ return;
166
+ unlocked = true;
167
+ // Safari on iOS only speaks outside a gesture after something was spoken inside one.
168
+ const silent = new SpeechSynthesisUtterance('');
169
+ silent.volume = 0;
170
+ s.speak(silent);
171
+ },
172
+ cancel: () => synth()?.cancel(),
173
+ };
174
+ }
175
+ const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
176
+ /**
177
+ * Utterance values for the options and the prosody: `rate` 0.1–10, `pitch`
178
+ * 0–2 (1 = the voice's, semitones become a frequency ratio), `volume` 0–1
179
+ * (decibels become a gain, so it can only go down from the default).
180
+ */
181
+ export function utteranceProsody(options, prosody = {}) {
182
+ return {
183
+ rate: clamp((options.rate ?? 1) * (prosody.rate ?? 1), 0.1, 10),
184
+ pitch: clamp((options.pitch ?? 1) * 2 ** ((prosody.pitch ?? 0) / 12), 0, 2),
185
+ volume: clamp(10 ** ((prosody.volume ?? 0) / 20), 0, 1),
186
+ };
187
+ }
188
+ /** Splits long text into sentence-sized chunks (Chrome cuts long utterances). */
189
+ export function splitSentences(text, max = 220) {
190
+ const sentences = text.replace(/\s+/g, ' ').trim().match(/[^.!?…]+[.!?…]*\s*/g) ?? [];
191
+ const chunks = [];
192
+ for (const sentence of sentences) {
193
+ const last = chunks[chunks.length - 1];
194
+ if (last && last.length + sentence.length <= max)
195
+ chunks[chunks.length - 1] = last + sentence;
196
+ else
197
+ chunks.push(sentence);
198
+ }
199
+ return chunks.map((c) => c.trim()).filter(Boolean);
200
+ }
201
+ //# sourceMappingURL=webspeech.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webspeech.js","sourceRoot":"","sources":["../../src/providers/webspeech.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA4E,MAAM,aAAa,CAAA;AAInH,SAAS,eAAe;IACtB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,SAAS,CAAA;IACnD,MAAM,CAAC,GAAG,MAAa,CAAA;IACvB,OAAO,CAAC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,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;KACxD,CAAA;AACH,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,GAAG,GAAG,GAAG;IACpD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,IAAI,EAAE,CAAA;IACrF,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QACtC,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,IAAI,GAAG;YAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,QAAQ,CAAA;;YACxF,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5B,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AACpD,CAAC"}
@@ -0,0 +1,263 @@
1
+ export type SttCapabilities = {
2
+ /** Emits partial transcripts while the user speaks. */
3
+ partials?: boolean;
4
+ /** Works without network. */
5
+ offline?: boolean;
6
+ /** Can keep listening across utterances (hands-free). */
7
+ continuous?: boolean;
8
+ /** Marks final results with `endOfTurn` (the service detects the end of the turn itself). */
9
+ endOfTurn?: boolean;
10
+ /** Delivers the microphone audio through `onAudio` (for audio end-of-turn models). */
11
+ audio?: boolean;
12
+ };
13
+ export type SttListenOptions = {
14
+ language: string;
15
+ /** Keep listening after an utterance ends (hands-free). */
16
+ continuous: boolean;
17
+ };
18
+ export type SttHandlers = {
19
+ onPartial?(text: string): void;
20
+ /**
21
+ * `endOfTurn`: providers with `capabilities.endOfTurn` say whether the user
22
+ * finished the turn (true) or only paused (false).
23
+ */
24
+ onFinal(text: string, meta?: {
25
+ confidence?: number;
26
+ endOfTurn?: boolean;
27
+ }): void;
28
+ /** Raw microphone audio, mono, from providers with `capabilities.audio`. */
29
+ onAudio?(samples: Float32Array, sampleRate: number): void;
30
+ onError(error: SpeechError): void;
31
+ /** The session ended (stop, silence, error or provider limit). */
32
+ onEnd(): void;
33
+ };
34
+ export type SttSession = {
35
+ /** Stop listening and flush the last result. */
36
+ stop(): void;
37
+ /** Stop immediately, discarding pending results. */
38
+ abort(): void;
39
+ };
40
+ /** Speech-to-text provider: browser, local model or cloud. */
41
+ export type SpeechToText = {
42
+ name: string;
43
+ capabilities: SttCapabilities;
44
+ /** Audio or text leaves the page (cloud service, or the browser's own speech service). */
45
+ remote?: boolean;
46
+ /** Consent purpose required to use it (ADR 0010); skipped while not granted. */
47
+ consent?: string;
48
+ isSupported(): boolean | Promise<boolean>;
49
+ listen(options: SttListenOptions, handlers: SttHandlers): SttSession | Promise<SttSession>;
50
+ };
51
+ /**
52
+ * How to say it, after SSML `<prosody>` (W3C SSML 1.1, section 3.2.4), with
53
+ * relative values only. Absent = the voice's own.
54
+ */
55
+ export type Prosody = {
56
+ /** Speaking rate as a multiplier (SSML `rate="120%"` = 1.2): tempo without a pitch change. */
57
+ rate?: number;
58
+ /** Pitch shift in semitones (SSML `pitch="+2st"` = 2). */
59
+ pitch?: number;
60
+ /** Volume change in decibels (SSML `volume="+6dB"` = 6). */
61
+ volume?: number;
62
+ };
63
+ /** Which parts of the prosody a provider applies itself. */
64
+ export type ProsodySupport = {
65
+ rate?: boolean;
66
+ pitch?: boolean;
67
+ volume?: boolean;
68
+ };
69
+ export type SpeakOptions = {
70
+ language: string;
71
+ voice?: string;
72
+ signal?: AbortSignal;
73
+ /** The part of the prosody this provider applies itself (see `TextToSpeech.prosody`). */
74
+ prosody?: Prosody;
75
+ };
76
+ /** Mono audio made by a synthesizer, before it is played. */
77
+ export type SpeechAudio = {
78
+ samples: Float32Array;
79
+ sampleRate: number;
80
+ };
81
+ /** Download progress of a provider's model, in bytes. */
82
+ export type LoadProgress = {
83
+ loaded: number;
84
+ /** Unknown until the server tells it (no `Content-Length`). */
85
+ total?: number;
86
+ /** The file being downloaded. */
87
+ file?: string;
88
+ };
89
+ /**
90
+ * Text-to-speech provider: the browser's voice, a cloud service behind your
91
+ * backend or a model running in the page. A provider either plays the speech
92
+ * itself (`speak`) or hands the audio to the voice plugin (`synthesize`), which
93
+ * plays it through the effects; at least one of the two is required.
94
+ */
95
+ export type TextToSpeech = {
96
+ name: string;
97
+ remote?: boolean;
98
+ consent?: string;
99
+ isSupported(): boolean | Promise<boolean>;
100
+ /** Plays the speech itself; resolves when it finishes or is cancelled. */
101
+ speak?(text: string, options: SpeakOptions): Promise<void>;
102
+ /** Returns the audio without playing it. Preferred over `speak` when Web Audio is available. */
103
+ synthesize?(text: string, options: SpeakOptions): Promise<SpeechAudio>;
104
+ /** Stops what `speak` is playing. */
105
+ cancel?(): void;
106
+ /**
107
+ * Called in the user's gestures (tap, click, key). Providers that need a
108
+ * gesture before they can speak (`speechSynthesis` on iOS) get ready here.
109
+ */
110
+ unlock?(): void;
111
+ /**
112
+ * Downloads and prepares what it needs (a model). The voice plugin decides
113
+ * when to call it (`load.start`) and what to do with speech meanwhile
114
+ * (`load.whileLoading`). Without it, the provider is ready once supported.
115
+ */
116
+ load?(onProgress: (progress: LoadProgress) => void, signal: AbortSignal): Promise<void>;
117
+ /** Bytes `load` downloads, if known in advance (for the UI). */
118
+ size?: number;
119
+ /** Prosody it applies itself; the player does the rest it can (pitch, volume). */
120
+ prosody?: ProsodySupport;
121
+ /**
122
+ * What happens inside the provider, for logs and debugging (a worker
123
+ * starting, a request and its reply). The voice plugin subscribes and emits
124
+ * each step as `voice.tts`. Returns the unsubscribe function.
125
+ */
126
+ trace?(listener: (event: TtsTraceEvent) => void): () => void;
127
+ };
128
+ /** One step inside a provider: `event` names it, the rest are plain values (no content). */
129
+ export type TtsTraceEvent = {
130
+ event: string;
131
+ } & Record<string, string | number | boolean | undefined>;
132
+ /** One sentence's effects, built by `SpeechEffects.connect`. */
133
+ export type EffectsInstance = {
134
+ /** The node that goes to the speakers. */
135
+ output: AudioNode;
136
+ /** Seconds the effects keep sounding after the speech ends (reverb, echo). */
137
+ tail?: number;
138
+ /** Releases the nodes (oscillators, buffers) once the tail is over or speech stops. */
139
+ dispose?(): void;
140
+ };
141
+ /**
142
+ * Effects on synthesized speech. The voice plugin asks `prosody()` before each
143
+ * sentence (providers apply what they can; `speechSynthesis` gets only this),
144
+ * runs `process` on the samples and plays them through `connect`.
145
+ */
146
+ export type SpeechEffects = {
147
+ name: string;
148
+ prosody?(): Prosody;
149
+ /** Sample-level processing before playback (a noise gate, for example). */
150
+ process?(audio: SpeechAudio): SpeechAudio;
151
+ /** Wires the effects after `source`; may change `source.playbackRate`. */
152
+ connect(context: BaseAudioContext, source: AudioBufferSourceNode): EffectsInstance;
153
+ /** Called when the effects change (so `state.effects` follows `name`). */
154
+ subscribe?(listener: () => void): () => void;
155
+ };
156
+ export type PlayOptions = {
157
+ effects?: SpeechEffects;
158
+ /** Playback rate of the source (changes pitch and tempo together). */
159
+ playbackRate?: number;
160
+ /** Gain in decibels. */
161
+ gainDb?: number;
162
+ signal?: AbortSignal;
163
+ };
164
+ /** Plays synthesized speech. `webAudioPlayer()` is the default. */
165
+ export type AudioPlayer = {
166
+ isSupported(): boolean;
167
+ /** Creates or resumes the audio output; Safari and Firefox only allow it inside a user gesture. */
168
+ unlock(): void;
169
+ /** Resolves when the speech ends or `signal` aborts; effect tails keep sounding after it. */
170
+ play(audio: SpeechAudio, options: PlayOptions): Promise<void>;
171
+ /** Stops everything, tails included. */
172
+ stop(): void;
173
+ };
174
+ export type SpeechErrorCode = 'not-supported'
175
+ /** The user or the page denied the microphone. */
176
+ | 'not-allowed'
177
+ /** The microphone is fine, but the browser's speech service is off or blocked (e.g. dictation disabled in Safari). */
178
+ | 'service-not-allowed' | 'no-speech' | 'audio-capture' | 'network' | 'aborted'
179
+ /** Speaking: the browser refused to play the bot's voice until the user interacts with the page. */
180
+ | 'output-blocked'
181
+ /** Speaking: the voice failed or never started (Safari on iOS sometimes neither speaks nor reports an error). */
182
+ | 'synthesis-failed' | 'unknown';
183
+ /** Where the voice failed: hearing the user (`listen`) or saying the reply (`speak`). */
184
+ export type SpeechStage = 'listen' | 'speak';
185
+ export declare class SpeechError extends Error {
186
+ readonly code: SpeechErrorCode;
187
+ /** UIs use it to tell "I couldn't hear you" from "I couldn't speak". */
188
+ readonly stage: SpeechStage;
189
+ constructor(code: SpeechErrorCode, message?: string,
190
+ /** UIs use it to tell "I couldn't hear you" from "I couldn't speak". */
191
+ stage?: SpeechStage);
192
+ /** Errors where trying the next provider makes sense. */
193
+ get recoverable(): boolean;
194
+ }
195
+ /** A turn of the recent conversation, as end-of-turn models see it. */
196
+ export type TurnHistoryEntry = {
197
+ role: 'user' | 'assistant';
198
+ text: string;
199
+ };
200
+ export type EndOfTurnInput = {
201
+ /** What the user said so far in this turn. */
202
+ partial: string;
203
+ /** Recent turns, oldest first, at most `historyTurns`. */
204
+ history: TurnHistoryEntry[];
205
+ language: string;
206
+ /** The last seconds of microphone audio (only for `input: 'audio'`). */
207
+ audio?: {
208
+ samples: Float32Array;
209
+ sampleRate: number;
210
+ };
211
+ };
212
+ /**
213
+ * Decides whether the user finished speaking or only paused (ADR 0011): a
214
+ * text classifier (LiveKit turn-detector, a BERT model, a typed-decision model,
215
+ * the backend's LLM) or an audio one (Pipecat Smart Turn). Returns the
216
+ * probability that the turn is over; the voice plugin turns it into a wait.
217
+ */
218
+ export type EndOfTurn = {
219
+ name: string;
220
+ input: 'text' | 'audio';
221
+ /** How many recent turns `predict` gets. Default 6. */
222
+ historyTurns?: number;
223
+ /** The text or audio leaves the page. */
224
+ remote?: boolean;
225
+ /** Consent purpose required to use it (ADR 0010); silence only while not granted. */
226
+ consent?: string;
227
+ isSupported(): boolean | Promise<boolean>;
228
+ /** Loads a model on demand; the plugin uses silence alone until it resolves. */
229
+ load?(): Promise<void>;
230
+ predict(input: EndOfTurnInput, signal: AbortSignal): number | Promise<number>;
231
+ };
232
+ /** A sentence the bot spoke (or is speaking), as echo filters see it. */
233
+ export type SpokenSentence = {
234
+ text: string;
235
+ /** When the speech started (epoch ms). */
236
+ startedAt: number;
237
+ /** When it ended; absent while it is still being spoken. */
238
+ endedAt?: number;
239
+ };
240
+ export type EchoInput = {
241
+ /** What the recognizer heard. */
242
+ text: string;
243
+ /** A final result (true) or a live transcript (false). */
244
+ final: boolean;
245
+ /** What the bot said recently, oldest first: the sentence being spoken and those that ended within `tail`. Never empty. */
246
+ speech: SpokenSentence[];
247
+ language: string;
248
+ };
249
+ /**
250
+ * Removes the bot's own voice from what the microphone heard: with speakers,
251
+ * the reply comes back through the recognizer and would interrupt or answer the
252
+ * bot. The voice plugin asks it while the bot speaks and for `tail` ms after,
253
+ * for every live transcript and final result, before barge-in and the turn see
254
+ * them. Must be synchronous: it runs on every partial.
255
+ */
256
+ export type EchoFilter = {
257
+ name: string;
258
+ /** How long after a sentence ends it is still passed in `speech` (ms). Default 2000. */
259
+ tail?: number;
260
+ /** Returns what the user said: `text` itself, a shorter text, or '' when it was all echo. */
261
+ filter(input: EchoInput): string;
262
+ };
263
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,yDAAyD;IACzD,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,6FAA6F;IAC7F,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB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AAI,EAAE,MAAM,CAAA;IACZ,wFAAwF;IACxF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,6FAA6F;IAC7F,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAAA;CACjC,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,20 @@
1
+ export class SpeechError extends Error {
2
+ code;
3
+ stage;
4
+ constructor(code, message,
5
+ /** UIs use it to tell "I couldn't hear you" from "I couldn't speak". */
6
+ stage = 'listen') {
7
+ super(message ?? code);
8
+ this.code = code;
9
+ this.stage = stage;
10
+ this.name = 'SpeechError';
11
+ }
12
+ /** Errors where trying the next provider makes sense. */
13
+ get recoverable() {
14
+ return (this.code === 'network' ||
15
+ this.code === 'not-supported' ||
16
+ this.code === 'audio-capture' ||
17
+ this.code === 'service-not-allowed');
18
+ }
19
+ }
20
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAuMA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAEzB,IAAI;IAGJ,KAAK;IAJhB,YACW,IAAqB,EAC9B,OAAgB;IAChB,wEAAwE;IAC/D,KAAK,GAAgB,QAAQ;QAEtC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,CAAA;oBALb,IAAI;qBAGJ,KAAK;QAGd,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;IAED,yDAAyD;IACzD,IAAI,WAAW;QACb,OAAO,CACL,IAAI,CAAC,IAAI,KAAK,SAAS;YACvB,IAAI,CAAC,IAAI,KAAK,eAAe;YAC7B,IAAI,CAAC,IAAI,KAAK,eAAe;YAC7B,IAAI,CAAC,IAAI,KAAK,qBAAqB,CACpC,CAAA;IACH,CAAC;CACF"}