@adea-ai/voice 0.2.0 → 0.4.1
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 +86 -1
- package/dist/cli/helpers-cli.js +17 -2
- package/dist/contract/contract.d.ts +21 -2
- package/dist/contract/index.d.ts +1 -0
- package/dist/contract/index.js +12 -2
- package/dist/contract/session.d.ts +13 -0
- package/dist/contract/turns.d.ts +91 -0
- package/dist/contract/wire.d.ts +92 -1
- package/dist/desktop/conversation.d.ts +86 -0
- package/dist/desktop/desktop-voice.d.ts +61 -1
- package/dist/desktop/helper-lock.d.ts +45 -7
- package/dist/desktop/helper-process.d.ts +4 -0
- package/dist/desktop/index.d.ts +2 -0
- package/dist/desktop/index.js +427 -15
- package/dist/desktop/macho-digest.d.ts +9 -0
- package/dist/{index-rehs788p.js → index-7n7epq1a.js} +7 -2
- package/dist/{index-s270cw30.js → index-a7d617zr.js} +1 -1
- package/dist/{index-9kerqn9r.js → index-ght8wwpd.js} +9 -3
- package/dist/{index-acm1yvvv.js → index-m4g2tpeq.js} +258 -26
- package/dist/index.js +13 -3
- package/dist/settings/index.js +1 -1
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +459 -49
- package/dist/web/stt/speech-recognition.d.ts +128 -7
- package/dist/web/tts/locale-match.d.ts +40 -0
- package/dist/web/tts/system-voices.d.ts +44 -4
- package/dist/web/turns.d.ts +15 -25
- package/package.json +1 -1
- package/src/cli/helpers-cli.ts +18 -2
- package/src/contract/contract.ts +32 -4
- package/src/contract/index.ts +1 -0
- package/src/contract/session.ts +14 -2
- package/src/contract/turns.ts +48 -0
- package/src/contract/wire.ts +123 -2
- package/src/desktop/conversation.ts +347 -0
- package/src/desktop/desktop-voice.ts +197 -1
- package/src/desktop/helper-lock.ts +195 -20
- package/src/desktop/helper-process.ts +17 -10
- package/src/desktop/index.ts +2 -0
- package/src/desktop/macho-digest.ts +135 -0
- package/src/web/index.ts +1 -0
- package/src/web/stt/speech-recognition.ts +454 -24
- package/src/web/tts/locale-match.ts +131 -0
- package/src/web/tts/system-voices.ts +144 -35
- package/src/web/turns.ts +22 -11
|
@@ -50,7 +50,10 @@ export interface SpeechRecognitionLike {
|
|
|
50
50
|
onresult: ((event: SpeechRecognitionEventLike) => void) | null;
|
|
51
51
|
onerror: ((event: SpeechRecognitionErrorEventLike) => void) | null;
|
|
52
52
|
onend: (() => void) | null;
|
|
53
|
-
|
|
53
|
+
/** The browser heard speech begin. Not every engine fires it; the first words stand in. */
|
|
54
|
+
onspeechstart?: (() => void) | null;
|
|
55
|
+
/** Chrome 137+ accepts an audio track to recognise from (a chosen microphone). */
|
|
56
|
+
start(audioTrack?: MediaStreamTrackLike): void;
|
|
54
57
|
stop(): void;
|
|
55
58
|
abort(): void;
|
|
56
59
|
}
|
|
@@ -66,6 +69,49 @@ export interface SpeechRecognitionConstructor {
|
|
|
66
69
|
langs: string[];
|
|
67
70
|
}): Promise<boolean>;
|
|
68
71
|
}
|
|
72
|
+
/** The subset of `PermissionStatus` the microphone pre-check uses. */
|
|
73
|
+
export interface PermissionStatusLike {
|
|
74
|
+
readonly state: "granted" | "denied" | "prompt" | (string & {});
|
|
75
|
+
onchange?: (() => void) | null;
|
|
76
|
+
addEventListener?(type: "change", listener: () => void): void;
|
|
77
|
+
removeEventListener?(type: "change", listener: () => void): void;
|
|
78
|
+
}
|
|
79
|
+
/** The subset of `MediaStreamTrack` a chosen microphone needs. */
|
|
80
|
+
export interface MediaStreamTrackLike {
|
|
81
|
+
readonly kind?: string;
|
|
82
|
+
readonly readyState?: string;
|
|
83
|
+
stop(): void;
|
|
84
|
+
}
|
|
85
|
+
export interface MediaStreamLike {
|
|
86
|
+
getAudioTracks(): MediaStreamTrackLike[];
|
|
87
|
+
getTracks?(): MediaStreamTrackLike[];
|
|
88
|
+
}
|
|
89
|
+
/** The parts of `navigator` dictation reads: permissions, connectivity and microphones. */
|
|
90
|
+
export interface RecognitionNavigatorLike {
|
|
91
|
+
readonly onLine?: boolean;
|
|
92
|
+
readonly permissions?: {
|
|
93
|
+
query(descriptor: {
|
|
94
|
+
name: string;
|
|
95
|
+
}): Promise<PermissionStatusLike>;
|
|
96
|
+
};
|
|
97
|
+
readonly mediaDevices?: {
|
|
98
|
+
getUserMedia(constraints: {
|
|
99
|
+
audio: boolean | {
|
|
100
|
+
deviceId: {
|
|
101
|
+
exact: string;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
}): Promise<MediaStreamLike>;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** `window`/`document` as event targets (`offline`, `pagehide`, `visibilitychange`). */
|
|
108
|
+
export interface EventTargetLike {
|
|
109
|
+
addEventListener(type: string, listener: () => void): void;
|
|
110
|
+
removeEventListener(type: string, listener: () => void): void;
|
|
111
|
+
}
|
|
112
|
+
export interface RecognitionDocumentLike extends EventTargetLike {
|
|
113
|
+
readonly visibilityState?: string;
|
|
114
|
+
}
|
|
69
115
|
export interface SpeechRecognitionEnvironment {
|
|
70
116
|
/** The constructor, or undefined where the browser has no Web Speech API. */
|
|
71
117
|
readonly SpeechRecognition?: SpeechRecognitionConstructor;
|
|
@@ -73,10 +119,80 @@ export interface SpeechRecognitionEnvironment {
|
|
|
73
119
|
readonly webkitSpeechRecognition?: SpeechRecognitionConstructor;
|
|
74
120
|
readonly now?: () => number;
|
|
75
121
|
readonly sleep?: (milliseconds: number) => Promise<void>;
|
|
122
|
+
/** Permissions, `onLine` and `mediaDevices`. Default: the global `navigator`. */
|
|
123
|
+
readonly navigator?: RecognitionNavigatorLike;
|
|
124
|
+
/** For `visibilitychange`. Default: the global `document`. */
|
|
125
|
+
readonly document?: RecognitionDocumentLike;
|
|
126
|
+
/** `window`'s listeners, for `offline` and `pagehide`. Default: the global ones. */
|
|
127
|
+
readonly addEventListener?: (type: string, listener: () => void) => void;
|
|
128
|
+
readonly removeEventListener?: (type: string, listener: () => void) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Whether `start(audioTrack)` is honoured. Browsers that predate it ignore the argument and record
|
|
131
|
+
* the default microphone, so a chosen device would be silently dropped. Default: detected as
|
|
132
|
+
* Chrome's on-device recognizer (`processLocally` on the instance), which shipped after it.
|
|
133
|
+
*/
|
|
134
|
+
readonly recognitionAcceptsAudioTrack?: boolean;
|
|
135
|
+
}
|
|
136
|
+
/** Progress of a browser model install. The browser reports states, not bytes. */
|
|
137
|
+
export interface ModelInstallProgress {
|
|
138
|
+
readonly locale: string;
|
|
139
|
+
readonly phase: "started" | "downloading" | "installed" | "failed" | "cancelled";
|
|
140
|
+
}
|
|
141
|
+
export interface InstallModelOptions {
|
|
142
|
+
/** The person agreed to the download (for example `allowsModelDownload(settings)`). */
|
|
143
|
+
readonly allowDownload: boolean;
|
|
144
|
+
/** Called on each phase change; `downloading` is observed by polling the browser's state. */
|
|
145
|
+
readonly onProgress?: (progress: ModelInstallProgress) => void;
|
|
146
|
+
/**
|
|
147
|
+
* Stops waiting and rejects with `cancelled`. The browser has no cancel for its own download, so
|
|
148
|
+
* it may finish in the background; the SDK only stops reporting and never claims it installed.
|
|
149
|
+
*/
|
|
150
|
+
readonly signal?: AbortSignal;
|
|
151
|
+
/** How often `downloading` is polled. Default 500 ms. */
|
|
152
|
+
readonly pollIntervalMs?: number;
|
|
153
|
+
/** A settings object; `privacy.offlineOnly` refuses the download whatever `allowDownload` says. */
|
|
154
|
+
readonly settings?: {
|
|
155
|
+
readonly privacy: {
|
|
156
|
+
readonly offlineOnly: boolean;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/** What dictation does when the page is hidden (`visibilitychange` to hidden, or `pagehide`). */
|
|
161
|
+
export type HiddenPagePolicy = "finalize" | "cancel" | "ignore";
|
|
162
|
+
/** Browser-specific session options on top of the shared contract. All optional. */
|
|
163
|
+
export interface WebTranscriptionSessionOptions extends TranscriptionSessionOptions {
|
|
164
|
+
/**
|
|
165
|
+
* A chosen microphone: a `deviceId` the SDK opens (and always stops on every terminal path), or a
|
|
166
|
+
* `track` the host owns (stopped at the end only with `stopOnEnd: true`). Needs a browser that
|
|
167
|
+
* honours `start(audioTrack)`, otherwise the session is refused instead of using another mic.
|
|
168
|
+
*/
|
|
169
|
+
readonly microphone?: {
|
|
170
|
+
readonly deviceId: string;
|
|
171
|
+
} | {
|
|
172
|
+
readonly track: MediaStreamTrackLike;
|
|
173
|
+
readonly stopOnEnd?: boolean;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* What to do when the browser ends recognition on its own before `end()` (Chrome on Android
|
|
177
|
+
* ignores `continuous` and stops after one utterance): `finalize` (default) reports the words so
|
|
178
|
+
* far as a clean `final`; `restart` starts the recognizer again inside the same session, so the
|
|
179
|
+
* person can keep talking until endpointing, the hard cap or `end()` finishes it.
|
|
180
|
+
*/
|
|
181
|
+
readonly onEarlyEnd?: "finalize" | "restart";
|
|
182
|
+
/** At most this many restarts per session with `onEarlyEnd: "restart"`. Default 50. */
|
|
183
|
+
readonly maxRestarts?: number;
|
|
184
|
+
/** Default `finalize`: a hidden page ends the session with one terminal event. */
|
|
185
|
+
readonly whenHidden?: HiddenPagePolicy;
|
|
186
|
+
/** A settings object; `privacy.offlineOnly` refuses the service recognizer outright. */
|
|
187
|
+
readonly settings?: {
|
|
188
|
+
readonly privacy: {
|
|
189
|
+
readonly offlineOnly: boolean;
|
|
190
|
+
};
|
|
191
|
+
};
|
|
76
192
|
}
|
|
77
193
|
/** The recognizer constructor this browser exposes, unprefixed first. */
|
|
78
194
|
export declare function recognitionConstructor(environment: SpeechRecognitionEnvironment): SpeechRecognitionConstructor | undefined;
|
|
79
|
-
export { DEFAULT_ENDPOINTING, type EndpointingOptions, type PartialTranscript, type SessionEvent, type TranscriptionProvider, type TranscriptionSession, type TranscriptionSessionOptions, } from "../../contract/session";
|
|
195
|
+
export { DEFAULT_ENDPOINTING, type EndpointingOptions, type RecognitionExecution, type PartialTranscript, type SessionEvent, type TranscriptionProvider, type TranscriptionSession, type TranscriptionSessionOptions, } from "../../contract/session";
|
|
80
196
|
import { type TranscriptionProvider, type TranscriptionSession, type TranscriptionSessionOptions } from "../../contract/session";
|
|
81
197
|
export declare const LOCAL_RECOGNITION_ID = "web.speech-recognition-local";
|
|
82
198
|
export declare const SERVICE_RECOGNITION_ID = "web.speech-recognition-service";
|
|
@@ -96,10 +212,15 @@ export declare class BrowserRecognitionProvider implements TranscriptionProvider
|
|
|
96
212
|
/**
|
|
97
213
|
* Installs the on-device model where the browser exposes an install path (#37 consent step).
|
|
98
214
|
* Downloading is never implied: the host passes `allowDownload: true` only after the person
|
|
99
|
-
* agreed to it (for example `settings.models.allowDownload`), otherwise this refuses.
|
|
215
|
+
* agreed to it (for example `settings.models.allowDownload`), otherwise this refuses. Resolves
|
|
216
|
+
* with the browser's boolean; `onProgress` and `signal` are optional.
|
|
100
217
|
*/
|
|
101
|
-
installModel(locale: string, options:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
createSession(options:
|
|
218
|
+
installModel(locale: string, options: InstallModelOptions): Promise<boolean>;
|
|
219
|
+
/** Reports `downloading` once the browser says so; the browser exposes no byte counts. */
|
|
220
|
+
private pollInstall;
|
|
221
|
+
createSession(options: WebTranscriptionSessionOptions): Promise<TranscriptionSession>;
|
|
222
|
+
private get navigator();
|
|
223
|
+
private get window();
|
|
224
|
+
/** Opens (or adopts) the chosen microphone. Nothing is opened when no device was chosen. */
|
|
225
|
+
private openMicrophone;
|
|
105
226
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Region-aware locale matching for platform voices (#36).
|
|
3
|
+
*
|
|
4
|
+
* Matching only the language subtag picks `es-ES` for an `es-419` request whenever the browser lists
|
|
5
|
+
* Spain first, which is what the 2026-11-19 acceptance run recorded in Firefox and Safari. The rule
|
|
6
|
+
* here is: **exact tag > same region group > same language**, with an explicit preference order
|
|
7
|
+
* inside a group. For Latin-American Spanish that order is `es-419`, `es-MX`, `es-US`, `es-AR`, then
|
|
8
|
+
* the other Latin-American regions, and `es-ES` only last.
|
|
9
|
+
*
|
|
10
|
+
* Pure functions over tags: no browser, no voices list.
|
|
11
|
+
*/
|
|
12
|
+
import type { VoiceLocaleMatch } from "../../contract/contract";
|
|
13
|
+
/** A parsed BCP-47 tag: language, optional script, optional region (upper case or 3 digits). */
|
|
14
|
+
export interface ParsedLocale {
|
|
15
|
+
readonly language: string;
|
|
16
|
+
readonly script?: string;
|
|
17
|
+
readonly region?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function parseLocale(tag: string): ParsedLocale;
|
|
20
|
+
/**
|
|
21
|
+
* Region groups per language, each in preference order. A region's group is the first group that
|
|
22
|
+
* lists it; the first group of a language is not privileged. Chinese groups by script as well, so
|
|
23
|
+
* `zh-Hant` finds `zh-TW` and never `zh-CN`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const REGION_GROUPS: Readonly<Record<string, readonly (readonly string[])[]>>;
|
|
26
|
+
export interface LocaleMatch {
|
|
27
|
+
readonly match: VoiceLocaleMatch;
|
|
28
|
+
/** Lower is better. Stable across calls, so it can sort a list of voices. */
|
|
29
|
+
readonly rank: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* How well a voice's language tag serves a requested locale, or undefined for another language.
|
|
33
|
+
*
|
|
34
|
+
* - exact tag (case and `_`/`-` insensitive) is `exact`, rank 0;
|
|
35
|
+
* - a voice in the requested region's group is `region`, ranked by the group's preference order;
|
|
36
|
+
* - a request without a region accepts every voice of the language as `region`;
|
|
37
|
+
* - anything else of the same language is `language`: a region-less voice (`es`) before an
|
|
38
|
+
* off-region one (`es-ES` for `es-419`).
|
|
39
|
+
*/
|
|
40
|
+
export declare function matchLocale(requested: string, voiceLang: string): LocaleMatch | undefined;
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* Phonon stays the English default; this provider answers for ES-419 and for English devices where
|
|
11
11
|
* the person declines the model download.
|
|
12
12
|
*/
|
|
13
|
-
import { type VoiceProvider, type VoiceProviderAvailability, type VoiceProviderDescriptor } from "../../contract/contract";
|
|
13
|
+
import { type VoiceLocaleMatch, type VoiceProvider, type VoiceProviderAvailability, type VoiceProviderDescriptor } from "../../contract/contract";
|
|
14
|
+
import { VoiceError } from "../../contract/errors";
|
|
14
15
|
export interface SynthesisVoiceLike {
|
|
15
16
|
readonly name: string;
|
|
16
17
|
readonly lang: string;
|
|
@@ -67,7 +68,8 @@ export interface SpeakWithPlatformVoiceOptions {
|
|
|
67
68
|
readonly volume?: number;
|
|
68
69
|
/** Whether the host has consent for a remote voice. Default false. */
|
|
69
70
|
readonly allowNetwork?: boolean;
|
|
70
|
-
|
|
71
|
+
/** Called when the audio starts, with the voice that speaks (also on `handle.voice`). */
|
|
72
|
+
readonly onStart?: (voice: ChosenVoice | undefined) => void;
|
|
71
73
|
readonly onEnd?: () => void;
|
|
72
74
|
/**
|
|
73
75
|
* Reject with `failed` if the browser never reports an end (Chrome can drop `end` events).
|
|
@@ -75,8 +77,31 @@ export interface SpeakWithPlatformVoiceOptions {
|
|
|
75
77
|
*/
|
|
76
78
|
readonly timeoutMs?: number;
|
|
77
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* How a voice was chosen:
|
|
82
|
+
* - `exact` / `region` / `language`: matched against `locale` (see `VoiceLocaleMatch`);
|
|
83
|
+
* - `named`: the host named it with `voiceName` and gave no locale to compare with;
|
|
84
|
+
* - `default`: no locale and no name, so the browser's default local voice.
|
|
85
|
+
*/
|
|
86
|
+
export type VoiceSelectionMatch = VoiceLocaleMatch | "named" | "default";
|
|
87
|
+
/** The voice a request speaks with, for a host to show ("Paulina, Spanish (Mexico), on device"). */
|
|
88
|
+
export interface ChosenVoice {
|
|
89
|
+
readonly name: string;
|
|
90
|
+
readonly voiceURI?: string;
|
|
91
|
+
readonly lang: string;
|
|
92
|
+
/** Whether the voice runs on the device. A remote voice is only chosen with `allowNetwork`. */
|
|
93
|
+
readonly localService: boolean;
|
|
94
|
+
readonly match: VoiceSelectionMatch;
|
|
95
|
+
/**
|
|
96
|
+
* True when the requested locale names a region and the only usable voice is from another region
|
|
97
|
+
* of the language (`es-ES` for `es-419`). The host should say so rather than imply a match.
|
|
98
|
+
*/
|
|
99
|
+
readonly offRegion: boolean;
|
|
100
|
+
}
|
|
78
101
|
export interface PlatformSpeechHandle {
|
|
79
102
|
readonly done: Promise<void>;
|
|
103
|
+
/** The voice that speaks this request; undefined when the request was refused before speaking. */
|
|
104
|
+
readonly voice?: ChosenVoice;
|
|
80
105
|
cancel(): void;
|
|
81
106
|
}
|
|
82
107
|
export declare const SYSTEM_VOICES_ID = "web.system-voices";
|
|
@@ -88,11 +113,25 @@ export declare class SystemVoiceProvider implements VoiceProvider {
|
|
|
88
113
|
private voicesReady;
|
|
89
114
|
constructor(environment?: SystemVoicesEnvironment);
|
|
90
115
|
private get Utterance();
|
|
91
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* Voices the browser exposes for a locale's language, split by where they run, each list in
|
|
118
|
+
* preference order: exact tag, then the requested region group (for `es-419`: es-MX, es-US,
|
|
119
|
+
* es-AR, other Latin-American regions), then the rest of the language (`es-ES` last).
|
|
120
|
+
*/
|
|
92
121
|
voices(locale: string): {
|
|
93
122
|
local: SynthesisVoiceLike[];
|
|
94
123
|
remote: SynthesisVoiceLike[];
|
|
95
124
|
};
|
|
125
|
+
/** Every voice of the locale's language with its match quality, best first. */
|
|
126
|
+
rankVoices(locale: string): Array<{
|
|
127
|
+
voice: SynthesisVoiceLike;
|
|
128
|
+
match: VoiceLocaleMatch;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* The voice `speak()` would use for these options, without speaking: lets a host show the voice
|
|
132
|
+
* (and an off-region warning) before the first utterance. A `VoiceError` when it would refuse.
|
|
133
|
+
*/
|
|
134
|
+
chooseVoice(options?: SpeakWithPlatformVoiceOptions): ChosenVoice | undefined | VoiceError;
|
|
96
135
|
/**
|
|
97
136
|
* Resolves once the browser has a voice list, or after `voicesTimeoutMs`. Chrome returns an empty
|
|
98
137
|
* list until `voiceschanged`, which would otherwise read as "no voice installed".
|
|
@@ -101,7 +140,8 @@ export declare class SystemVoiceProvider implements VoiceProvider {
|
|
|
101
140
|
availability(locale: string): Promise<VoiceProviderAvailability>;
|
|
102
141
|
/**
|
|
103
142
|
* Speaks with a platform voice. Local voices only unless `allowNetwork` is set. With `locale`,
|
|
104
|
-
* the voice is
|
|
143
|
+
* the voice is the best local voice of that language: exact tag, then the region group, then
|
|
144
|
+
* another region (flagged `offRegion` on `handle.voice`).
|
|
105
145
|
*/
|
|
106
146
|
speak(text: string, options?: SpeakWithPlatformVoiceOptions): PlatformSpeechHandle;
|
|
107
147
|
/** Whether a synthesis request is in flight. */
|
package/dist/web/turns.d.ts
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* always ends in exactly one terminal event. Starting a new turn while the assistant is still
|
|
13
13
|
* talking is the common case on a page, so it is the default, not an option.
|
|
14
14
|
*/
|
|
15
|
-
import type {
|
|
16
|
-
import {
|
|
15
|
+
import type { TranscriptionProvider } from "./stt/speech-recognition";
|
|
16
|
+
import type { TurnEvent } from "../contract/turns";
|
|
17
17
|
/** What the assistant does with its answer. The manager never knows which engine is behind it. */
|
|
18
18
|
export interface SpeechSink {
|
|
19
19
|
speak(text: string, options?: {
|
|
@@ -23,29 +23,8 @@ export interface SpeechSink {
|
|
|
23
23
|
cancel(): void;
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} | {
|
|
29
|
-
readonly type: "partial";
|
|
30
|
-
readonly partial: PartialTranscript;
|
|
31
|
-
} | {
|
|
32
|
-
readonly type: "transcript";
|
|
33
|
-
readonly text: string;
|
|
34
|
-
} | {
|
|
35
|
-
readonly type: "speaking";
|
|
36
|
-
readonly text: string;
|
|
37
|
-
} | {
|
|
38
|
-
readonly type: "speech-finished";
|
|
39
|
-
} | {
|
|
40
|
-
readonly type: "speech-cancelled";
|
|
41
|
-
} | {
|
|
42
|
-
readonly type: "barge-in";
|
|
43
|
-
} | {
|
|
44
|
-
readonly type: "failed";
|
|
45
|
-
readonly error: VoiceError;
|
|
46
|
-
} | {
|
|
47
|
-
readonly type: "cancelled";
|
|
48
|
-
};
|
|
26
|
+
/** The shared turn vocabulary (`@adea-ai/voice/contract`), re-exported for existing imports. */
|
|
27
|
+
export type { TurnEvent } from "../contract/turns";
|
|
49
28
|
export interface TurnManagerOptions {
|
|
50
29
|
readonly transcription: TranscriptionProvider;
|
|
51
30
|
readonly synthesis: SpeechSink;
|
|
@@ -99,3 +78,14 @@ export declare class VoiceTurnManager {
|
|
|
99
78
|
private forward;
|
|
100
79
|
private emit;
|
|
101
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* For hosts that create recognition sessions themselves: spread into the session options so the
|
|
83
|
+
* recognizer's speech start stops the manager's answer (`notifySpeechDetected()`).
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* const session = await provider.createSession({ locale, allowNetwork: false, ...bargeInOnSpeechStart(turns) });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function bargeInOnSpeechStart(manager: Pick<VoiceTurnManager, "notifySpeechDetected">): {
|
|
90
|
+
readonly onSpeechStart: () => void;
|
|
91
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/voice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "The Adea Voice SDK: the shared speech provider contract, unified per-device voice settings, the desktop client for the pinned Apple/transcribe.cpp/audio.cpp helpers, and the browser providers.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
package/src/cli/helpers-cli.ts
CHANGED
|
@@ -7,12 +7,15 @@
|
|
|
7
7
|
* adea-voice-helpers verify --lock <lock.json> --dir <dir> [--helpers a,b] [--target t]
|
|
8
8
|
* adea-voice-helpers url --lock <lock.json> --helper <name> [--target t]
|
|
9
9
|
* adea-voice-helpers pin --lock <lock.json> --version <x.y.z> [--base <url>]
|
|
10
|
+
* adea-voice-helpers digest <file>…
|
|
10
11
|
*
|
|
11
12
|
* `stage` fails (exit 1) when an artifact is missing or does not match its pins and leaves no
|
|
12
13
|
* half-staged directory. `verify` is the release gate: the packaged directory must hold exactly the
|
|
13
|
-
* pinned helpers, never a local build
|
|
14
|
+
* pinned helpers (by code digest once the app has signed them again), never a local build, and each
|
|
15
|
+
* must start and report the pinned release. `digest` prints a file's signature-independent code
|
|
16
|
+
* digest (the lock's `codeSha256`). Exit 2 is a usage error.
|
|
14
17
|
*/
|
|
15
|
-
import { writeFileSync } from "node:fs";
|
|
18
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
16
19
|
import {
|
|
17
20
|
HELPER_NAMES,
|
|
18
21
|
HELPER_TARGETS,
|
|
@@ -26,6 +29,7 @@ import {
|
|
|
26
29
|
type HelperName,
|
|
27
30
|
type HelperTarget,
|
|
28
31
|
} from "../desktop/helper-lock";
|
|
32
|
+
import { machoCodeDigestFile } from "../desktop/macho-digest";
|
|
29
33
|
|
|
30
34
|
const [command, ...rest] = process.argv.slice(2);
|
|
31
35
|
|
|
@@ -68,7 +72,19 @@ async function pin(lockPath: string): Promise<void> {
|
|
|
68
72
|
console.log(`voice helpers: ${lockPath} now pins ${version}`);
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
/** `digest`: one `<digest> <file>` line per file; a file that is not Mach-O is an error. */
|
|
76
|
+
function digest(files: readonly string[]): void {
|
|
77
|
+
if (files.length === 0) usage("digest needs a file");
|
|
78
|
+
for (const file of files) {
|
|
79
|
+
if (!existsSync(file)) throw new HelperLockError(`${file} does not exist`);
|
|
80
|
+
const code = machoCodeDigestFile(file);
|
|
81
|
+
if (!code) throw new HelperLockError(`${file} is not a Mach-O file this can digest`);
|
|
82
|
+
console.log(`${code} ${file}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
71
86
|
async function main(): Promise<void> {
|
|
87
|
+
if (command === "digest") return digest(rest);
|
|
72
88
|
const lockPath = flag("lock");
|
|
73
89
|
if (!command || !lockPath) usage("missing command or --lock");
|
|
74
90
|
if (command === "pin") return await pin(lockPath);
|
package/src/contract/contract.ts
CHANGED
|
@@ -135,12 +135,40 @@ export interface VoiceUnavailability {
|
|
|
135
135
|
readonly remedy?: VoiceRemedy;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/**
|
|
139
|
+
* How well an available provider matches the requested locale (additive since contract 1.0; absent
|
|
140
|
+
* means the provider does not report it, which older hosts read as a plain "available").
|
|
141
|
+
*
|
|
142
|
+
* - `exact`: the requested tag itself (`es-419` for `es-419`).
|
|
143
|
+
* - `region`: the same language in the requested region group (`es-MX` for `es-419`), or any voice
|
|
144
|
+
* of the language when the request names no region.
|
|
145
|
+
* - `language`: the language only, outside the requested region (`es-ES` for `es-419`, `pt-BR` for
|
|
146
|
+
* `pt-PT`). Usable, but a host should say so instead of presenting it as the requested variant.
|
|
147
|
+
*/
|
|
148
|
+
export type VoiceLocaleMatch = "exact" | "region" | "language";
|
|
149
|
+
|
|
138
150
|
export type VoiceProviderAvailability =
|
|
139
|
-
| {
|
|
151
|
+
| {
|
|
152
|
+
readonly status: "available";
|
|
153
|
+
/** How well the locale is matched, when the provider can tell. */
|
|
154
|
+
readonly match?: VoiceLocaleMatch;
|
|
155
|
+
/** A human note, for example which off-region variant would be used. */
|
|
156
|
+
readonly message?: string;
|
|
157
|
+
}
|
|
140
158
|
| { readonly status: "unavailable"; readonly unavailable: VoiceUnavailability };
|
|
141
159
|
|
|
142
160
|
export const AVAILABLE: VoiceProviderAvailability = { status: "available" };
|
|
143
161
|
|
|
162
|
+
/** `available`, annotated with how well the locale is matched. */
|
|
163
|
+
export function availableWithMatch(match: VoiceLocaleMatch, message?: string): VoiceProviderAvailability {
|
|
164
|
+
return message === undefined ? { status: "available", match } : { status: "available", match, message };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Available, but only in another region of the language (`pt-BR` when `pt-PT` was asked for). */
|
|
168
|
+
export function isLanguageOnly(availability: VoiceProviderAvailability): boolean {
|
|
169
|
+
return availability.status === "available" && availability.match === "language";
|
|
170
|
+
}
|
|
171
|
+
|
|
144
172
|
export function unavailable(
|
|
145
173
|
reason: VoiceUnavailabilityReason,
|
|
146
174
|
message: string,
|
|
@@ -151,7 +179,7 @@ export function unavailable(
|
|
|
151
179
|
|
|
152
180
|
export function isAvailable(
|
|
153
181
|
availability: VoiceProviderAvailability,
|
|
154
|
-
): availability is { readonly status: "available" } {
|
|
182
|
+
): availability is Extract<VoiceProviderAvailability, { readonly status: "available" }> {
|
|
155
183
|
return availability.status === "available";
|
|
156
184
|
}
|
|
157
185
|
|
|
@@ -247,7 +275,7 @@ export async function route(request: RouteRequest): Promise<VoiceRoutingDecision
|
|
|
247
275
|
route: null,
|
|
248
276
|
candidates: [],
|
|
249
277
|
missing: [],
|
|
250
|
-
availability: unavailable("unsupportedPlatform", `no ${request.kind} provider is defined for
|
|
278
|
+
availability: unavailable("unsupportedPlatform", `no ${request.kind} provider is defined for this platform`, {
|
|
251
279
|
kind: "chooseAnotherProvider",
|
|
252
280
|
detail: "run on a platform the Voice SDK has a provider for",
|
|
253
281
|
}),
|
|
@@ -284,7 +312,7 @@ export async function route(request: RouteRequest): Promise<VoiceRoutingDecision
|
|
|
284
312
|
: mostActionable(candidates) ??
|
|
285
313
|
unavailable(
|
|
286
314
|
"providerNotRegistered",
|
|
287
|
-
`no ${request.kind} provider from
|
|
315
|
+
`this build registers no ${request.kind} provider from its routing chain (${chain.join(", ")})`,
|
|
288
316
|
{ kind: "chooseAnotherProvider", detail: "install a build that includes the provider" },
|
|
289
317
|
);
|
|
290
318
|
|
package/src/contract/index.ts
CHANGED
package/src/contract/session.ts
CHANGED
|
@@ -12,10 +12,17 @@ export interface PartialTranscript {
|
|
|
12
12
|
readonly sequence: number;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Where recognition actually ran for a result, recorded at runtime: `local` only when the engine
|
|
17
|
+
* ran on the device (for the browser, `processLocally` held for the whole session), `service` when
|
|
18
|
+
* audio went to a recognition service. Optional: providers that cannot tell leave it out.
|
|
19
|
+
*/
|
|
20
|
+
export type RecognitionExecution = "local" | "service";
|
|
21
|
+
|
|
15
22
|
export type SessionEvent =
|
|
16
23
|
| { readonly type: "partial"; readonly partial: PartialTranscript }
|
|
17
|
-
| { readonly type: "final"; readonly text: string }
|
|
18
|
-
| { readonly type: "failed"; readonly error: VoiceError }
|
|
24
|
+
| { readonly type: "final"; readonly text: string; readonly execution?: RecognitionExecution }
|
|
25
|
+
| { readonly type: "failed"; readonly error: VoiceError; readonly execution?: RecognitionExecution }
|
|
19
26
|
| { readonly type: "cancelled" };
|
|
20
27
|
|
|
21
28
|
export interface EndpointingOptions {
|
|
@@ -44,6 +51,11 @@ export interface TranscriptionSessionOptions {
|
|
|
44
51
|
/** Whether this host has the person's consent to send audio to the browser's service. */
|
|
45
52
|
readonly allowNetwork: boolean;
|
|
46
53
|
readonly endpointing?: EndpointingOptions;
|
|
54
|
+
/**
|
|
55
|
+
* Called when the recognizer hears speech start (the browser's `speechstart`, or the first words
|
|
56
|
+
* where that event is missing). `VoiceTurnManager` wires it to `notifySpeechDetected()` itself.
|
|
57
|
+
*/
|
|
58
|
+
readonly onSpeechStart?: () => void;
|
|
47
59
|
}
|
|
48
60
|
|
|
49
61
|
/** One running recognition session: the browser-facing half of the shared contract. */
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The conversation-turn vocabulary every platform reports (#34): the browser `VoiceTurnManager`
|
|
3
|
+
* and the desktop `DesktopVoice.conversation()` emit the same events, so one UI can render either.
|
|
4
|
+
*
|
|
5
|
+
* A turn is one person→assistant exchange: listen, transcript, answer, and the person may talk
|
|
6
|
+
* over the answer. Fields a platform cannot supply are optional (the browser manager has no
|
|
7
|
+
* utterance ids or helper metrics); `turn` names the turn on platforms that run several per
|
|
8
|
+
* conversation.
|
|
9
|
+
*/
|
|
10
|
+
import type { VoiceError } from "./errors";
|
|
11
|
+
import type { PartialTranscript } from "./session";
|
|
12
|
+
|
|
13
|
+
/** Why a turn ended without an error. */
|
|
14
|
+
export type TurnEndReason = "completed" | "cancelled" | "barge-in" | "superseded";
|
|
15
|
+
|
|
16
|
+
/** One turn's timings in milliseconds from its start. Never text or audio. */
|
|
17
|
+
export interface TurnMetrics {
|
|
18
|
+
readonly firstPartialMs: number | null;
|
|
19
|
+
readonly transcriptMs: number | null;
|
|
20
|
+
/** When the answer's first utterance started playing. */
|
|
21
|
+
readonly firstAudioMs: number | null;
|
|
22
|
+
readonly speechFinishedMs: number | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type TurnEvent =
|
|
26
|
+
/** The microphone is open. */
|
|
27
|
+
| { readonly type: "listening"; readonly turn?: string }
|
|
28
|
+
| { readonly type: "partial"; readonly partial: PartialTranscript; readonly turn?: string }
|
|
29
|
+
/** The transcript is final; the host produces the answer next. */
|
|
30
|
+
| { readonly type: "transcript"; readonly text: string; readonly turn?: string }
|
|
31
|
+
/** Waiting on the host's answer (after the transcript, or between streamed chunks). */
|
|
32
|
+
| { readonly type: "responding"; readonly turn?: string }
|
|
33
|
+
/** The answer is playing. `text` is the chunk the browser manager was given. */
|
|
34
|
+
| { readonly type: "speaking"; readonly text?: string; readonly turn?: string }
|
|
35
|
+
| { readonly type: "speech-started"; readonly utterance?: string; readonly turn?: string }
|
|
36
|
+
| { readonly type: "speech-finished"; readonly utterance?: string; readonly turn?: string }
|
|
37
|
+
| { readonly type: "speech-cancelled"; readonly utterance?: string; readonly turn?: string }
|
|
38
|
+
/** The person talked over the answer; it was stopped (a request cancel, not a mute). */
|
|
39
|
+
| { readonly type: "barge-in"; readonly turn?: string }
|
|
40
|
+
/** The answer was stopped from outside the turn (a system interruption); the turn is open. */
|
|
41
|
+
| { readonly type: "idle"; readonly turn?: string }
|
|
42
|
+
| { readonly type: "metrics"; readonly metrics: TurnMetrics; readonly turn?: string }
|
|
43
|
+
/** Terminal: the turn is over. */
|
|
44
|
+
| { readonly type: "ended"; readonly reason: TurnEndReason; readonly turn?: string }
|
|
45
|
+
/** Terminal: the turn failed. */
|
|
46
|
+
| { readonly type: "failed"; readonly error: VoiceError; readonly turn?: string }
|
|
47
|
+
/** Terminal for the whole conversation (the browser manager's `cancel()`). */
|
|
48
|
+
| { readonly type: "cancelled"; readonly turn?: string };
|