@adea-ai/voice 0.0.0-stage → 0.4.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.
- package/README.md +136 -2
- package/dist/cli/helpers-cli.d.ts +2 -0
- package/dist/cli/helpers-cli.js +117 -0
- package/dist/contract/contract.d.ts +157 -0
- package/dist/contract/errors.d.ts +26 -0
- package/dist/contract/index.d.ts +10 -0
- package/dist/contract/index.js +64 -0
- package/dist/contract/session.d.ts +71 -0
- package/dist/contract/turns.d.ts +91 -0
- package/dist/contract/wire.d.ts +279 -0
- package/dist/desktop/conversation.d.ts +86 -0
- package/dist/desktop/desktop-voice.d.ts +212 -0
- package/dist/desktop/helper-lock.d.ts +121 -0
- package/dist/desktop/helper-process.d.ts +96 -0
- package/dist/desktop/index.d.ts +9 -0
- package/dist/desktop/index.js +1454 -0
- package/dist/desktop/macho-digest.d.ts +9 -0
- package/dist/index-7n7epq1a.js +47 -0
- package/dist/index-a7d617zr.js +295 -0
- package/dist/index-ght8wwpd.js +156 -0
- package/dist/index-m4g2tpeq.js +522 -0
- package/dist/index-r4hz8gk0.js +10 -0
- package/dist/index-tvz9s9nz.js +77 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +96 -0
- package/dist/settings/index.d.ts +5 -0
- package/dist/settings/index.js +34 -0
- package/dist/settings/settings.d.ts +163 -0
- package/dist/web/index.d.ts +16 -0
- package/dist/web/index.js +1697 -0
- package/dist/web/stt/speech-recognition.d.ts +226 -0
- package/dist/web/tts/locale-match.d.ts +40 -0
- package/dist/web/tts/phonon.d.ts +139 -0
- package/dist/web/tts/player.d.ts +115 -0
- package/dist/web/tts/system-voices.d.ts +162 -0
- package/dist/web/turns.d.ts +91 -0
- package/package.json +68 -4
- package/src/cli/helpers-cli.ts +135 -0
- package/src/contract/contract.ts +393 -0
- package/src/contract/errors.ts +98 -0
- package/src/contract/index.ts +10 -0
- package/src/contract/session.ts +77 -0
- package/src/contract/turns.ts +48 -0
- package/src/contract/wire.ts +384 -0
- package/src/desktop/conversation.ts +347 -0
- package/src/desktop/desktop-voice.ts +1129 -0
- package/src/desktop/helper-lock.ts +550 -0
- package/src/desktop/helper-process.ts +408 -0
- package/src/desktop/index.ts +18 -0
- package/src/desktop/macho-digest.ts +135 -0
- package/src/index.ts +7 -0
- package/src/settings/index.ts +5 -0
- package/src/settings/settings.ts +478 -0
- package/src/web/index.ts +16 -0
- package/src/web/stt/speech-recognition.ts +1013 -0
- package/src/web/tts/locale-match.ts +131 -0
- package/src/web/tts/phonon.ts +386 -0
- package/src/web/tts/player.ts +271 -0
- package/src/web/tts/system-voices.ts +510 -0
- package/src/web/turns.ts +235 -0
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
/** Why a turn ended without an error. */
|
|
13
|
+
export type TurnEndReason = "completed" | "cancelled" | "barge-in" | "superseded";
|
|
14
|
+
/** One turn's timings in milliseconds from its start. Never text or audio. */
|
|
15
|
+
export interface TurnMetrics {
|
|
16
|
+
readonly firstPartialMs: number | null;
|
|
17
|
+
readonly transcriptMs: number | null;
|
|
18
|
+
/** When the answer's first utterance started playing. */
|
|
19
|
+
readonly firstAudioMs: number | null;
|
|
20
|
+
readonly speechFinishedMs: number | null;
|
|
21
|
+
}
|
|
22
|
+
export type TurnEvent =
|
|
23
|
+
/** The microphone is open. */
|
|
24
|
+
{
|
|
25
|
+
readonly type: "listening";
|
|
26
|
+
readonly turn?: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "partial";
|
|
29
|
+
readonly partial: PartialTranscript;
|
|
30
|
+
readonly turn?: string;
|
|
31
|
+
}
|
|
32
|
+
/** The transcript is final; the host produces the answer next. */
|
|
33
|
+
| {
|
|
34
|
+
readonly type: "transcript";
|
|
35
|
+
readonly text: string;
|
|
36
|
+
readonly turn?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Waiting on the host's answer (after the transcript, or between streamed chunks). */
|
|
39
|
+
| {
|
|
40
|
+
readonly type: "responding";
|
|
41
|
+
readonly turn?: string;
|
|
42
|
+
}
|
|
43
|
+
/** The answer is playing. `text` is the chunk the browser manager was given. */
|
|
44
|
+
| {
|
|
45
|
+
readonly type: "speaking";
|
|
46
|
+
readonly text?: string;
|
|
47
|
+
readonly turn?: string;
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "speech-started";
|
|
50
|
+
readonly utterance?: string;
|
|
51
|
+
readonly turn?: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly type: "speech-finished";
|
|
54
|
+
readonly utterance?: string;
|
|
55
|
+
readonly turn?: string;
|
|
56
|
+
} | {
|
|
57
|
+
readonly type: "speech-cancelled";
|
|
58
|
+
readonly utterance?: string;
|
|
59
|
+
readonly turn?: string;
|
|
60
|
+
}
|
|
61
|
+
/** The person talked over the answer; it was stopped (a request cancel, not a mute). */
|
|
62
|
+
| {
|
|
63
|
+
readonly type: "barge-in";
|
|
64
|
+
readonly turn?: string;
|
|
65
|
+
}
|
|
66
|
+
/** The answer was stopped from outside the turn (a system interruption); the turn is open. */
|
|
67
|
+
| {
|
|
68
|
+
readonly type: "idle";
|
|
69
|
+
readonly turn?: string;
|
|
70
|
+
} | {
|
|
71
|
+
readonly type: "metrics";
|
|
72
|
+
readonly metrics: TurnMetrics;
|
|
73
|
+
readonly turn?: string;
|
|
74
|
+
}
|
|
75
|
+
/** Terminal: the turn is over. */
|
|
76
|
+
| {
|
|
77
|
+
readonly type: "ended";
|
|
78
|
+
readonly reason: TurnEndReason;
|
|
79
|
+
readonly turn?: string;
|
|
80
|
+
}
|
|
81
|
+
/** Terminal: the turn failed. */
|
|
82
|
+
| {
|
|
83
|
+
readonly type: "failed";
|
|
84
|
+
readonly error: VoiceError;
|
|
85
|
+
readonly turn?: string;
|
|
86
|
+
}
|
|
87
|
+
/** Terminal for the whole conversation (the browser manager's `cancel()`). */
|
|
88
|
+
| {
|
|
89
|
+
readonly type: "cancelled";
|
|
90
|
+
readonly turn?: string;
|
|
91
|
+
};
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The desktop helpers' JSON-lines wire protocol, typed once for every host.
|
|
3
|
+
*
|
|
4
|
+
* `adea-voice-helper` (Apple speech), `adea-transcribe-helper` (transcribe.cpp) and
|
|
5
|
+
* `adea-tts-helper` (audio.cpp) speak one vocabulary: one UTF-8 JSON object per line, commands
|
|
6
|
+
* carry `cmd` and an optional `id`, and every response to a command echoes that `id`. A host never
|
|
7
|
+
* parses these lines itself; `@adea-ai/voice/desktop` does, and maps them to the session contract.
|
|
8
|
+
*/
|
|
9
|
+
import { type VoiceErrorCode } from "./errors";
|
|
10
|
+
import type { TurnEndReason } from "./turns";
|
|
11
|
+
/** The wire major this SDK speaks. A helper on another major is refused, never guessed at. */
|
|
12
|
+
export declare const WIRE_VERSION = 1;
|
|
13
|
+
/** The wire minor that added conversation turns (`turn-*`); older helpers cannot run them. */
|
|
14
|
+
export declare const TURN_WIRE_MINOR = 2;
|
|
15
|
+
/** The wire minor that added model removal (`release-assets` → `asset-released`). */
|
|
16
|
+
export declare const RELEASE_ASSETS_WIRE_MINOR = 3;
|
|
17
|
+
/** The provider-contract major this SDK speaks. */
|
|
18
|
+
export declare const CONTRACT_MAJOR = 1;
|
|
19
|
+
/** One line may not exceed this many bytes (the helpers enforce the same bound on input). */
|
|
20
|
+
export declare const MAX_WIRE_LINE_BYTES = 1000000;
|
|
21
|
+
export interface VersionEvent {
|
|
22
|
+
readonly event: "version";
|
|
23
|
+
readonly wire: number;
|
|
24
|
+
readonly wireMinor?: number;
|
|
25
|
+
readonly contract: string;
|
|
26
|
+
readonly contractMajor: number;
|
|
27
|
+
readonly helper?: string;
|
|
28
|
+
/** The voice release the helper was built from (e.g. `0.2.0`); a lock pins it. */
|
|
29
|
+
readonly release?: string;
|
|
30
|
+
readonly id?: string;
|
|
31
|
+
}
|
|
32
|
+
export type CombinedPermission = "granted" | "denied" | "prompt" | "unavailable";
|
|
33
|
+
export type PermissionPart = "granted" | "denied" | "restricted" | "prompt";
|
|
34
|
+
export interface PermissionEvent {
|
|
35
|
+
readonly event: "permission";
|
|
36
|
+
readonly state: CombinedPermission;
|
|
37
|
+
readonly microphone?: PermissionPart;
|
|
38
|
+
readonly speech?: PermissionPart;
|
|
39
|
+
readonly id?: string;
|
|
40
|
+
}
|
|
41
|
+
export type EngineState = "available" | "needsAssetInstall" | "unavailableOS" | "localeUnsupported" | "engineUnavailable";
|
|
42
|
+
export type AssetStatus = "installed" | "notInstalled" | "downloading" | "unsupported";
|
|
43
|
+
/** `adea-voice-helper` status: Apple's two engines for one locale. */
|
|
44
|
+
export interface AppleStatusEvent {
|
|
45
|
+
readonly event: "status";
|
|
46
|
+
readonly locale: string;
|
|
47
|
+
readonly analyzer: EngineState;
|
|
48
|
+
readonly legacy: EngineState;
|
|
49
|
+
readonly analyzerEquivalentLocale: string;
|
|
50
|
+
readonly recommendedEngine: "analyzer" | "legacy" | "none";
|
|
51
|
+
readonly assetStatus: AssetStatus;
|
|
52
|
+
readonly canInstall: boolean;
|
|
53
|
+
readonly id?: string;
|
|
54
|
+
}
|
|
55
|
+
/** `adea-transcribe-helper` status: the local models it can see. */
|
|
56
|
+
export interface TranscribeStatusEvent {
|
|
57
|
+
readonly event: "status";
|
|
58
|
+
readonly engine: "transcribe";
|
|
59
|
+
readonly locale: string;
|
|
60
|
+
readonly models: readonly {
|
|
61
|
+
readonly path: string;
|
|
62
|
+
readonly architecture: string;
|
|
63
|
+
readonly variant: string;
|
|
64
|
+
readonly languages: readonly string[];
|
|
65
|
+
readonly streaming: boolean;
|
|
66
|
+
}[];
|
|
67
|
+
readonly ready: boolean;
|
|
68
|
+
readonly selected?: string;
|
|
69
|
+
readonly id?: string;
|
|
70
|
+
}
|
|
71
|
+
/** `adea-tts-helper` status. */
|
|
72
|
+
export interface SynthesisStatusEvent {
|
|
73
|
+
readonly event: "status";
|
|
74
|
+
readonly engine: "audio.cpp";
|
|
75
|
+
readonly locale: string;
|
|
76
|
+
readonly modelPath: string;
|
|
77
|
+
readonly voice: string;
|
|
78
|
+
readonly ready: boolean;
|
|
79
|
+
readonly reason?: string;
|
|
80
|
+
readonly message?: string;
|
|
81
|
+
readonly id?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface LocaleEvent {
|
|
84
|
+
readonly event: "locale";
|
|
85
|
+
readonly locale: string;
|
|
86
|
+
readonly status: AssetStatus;
|
|
87
|
+
readonly canInstall: boolean;
|
|
88
|
+
readonly id?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface ListDoneEvent {
|
|
91
|
+
readonly event: "locales-done" | "voices-done";
|
|
92
|
+
readonly count: number;
|
|
93
|
+
readonly id?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface VoiceEvent {
|
|
96
|
+
readonly event: "voice";
|
|
97
|
+
/** The voice identifier (not the request id). */
|
|
98
|
+
readonly id: string;
|
|
99
|
+
readonly requestId?: string;
|
|
100
|
+
readonly name: string;
|
|
101
|
+
readonly locale: string;
|
|
102
|
+
readonly quality: "default" | "enhanced" | "premium" | "unknown";
|
|
103
|
+
readonly gender: "male" | "female" | "unknown";
|
|
104
|
+
readonly source?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface ListeningEvent {
|
|
107
|
+
readonly event: "listening";
|
|
108
|
+
readonly engine: string;
|
|
109
|
+
readonly locale: string;
|
|
110
|
+
readonly model?: string;
|
|
111
|
+
readonly id?: string;
|
|
112
|
+
}
|
|
113
|
+
export interface PartialEvent {
|
|
114
|
+
readonly event: "partial";
|
|
115
|
+
readonly text?: string;
|
|
116
|
+
readonly finalizedText: string;
|
|
117
|
+
readonly volatileText: string;
|
|
118
|
+
readonly sequence: number;
|
|
119
|
+
readonly id?: string;
|
|
120
|
+
}
|
|
121
|
+
export interface FinalEvent {
|
|
122
|
+
readonly event: "final";
|
|
123
|
+
readonly text: string;
|
|
124
|
+
readonly id?: string;
|
|
125
|
+
}
|
|
126
|
+
export interface ErrorEvent {
|
|
127
|
+
readonly event: "error";
|
|
128
|
+
readonly code: VoiceErrorCode;
|
|
129
|
+
readonly message?: string;
|
|
130
|
+
readonly id?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface CancelledEvent {
|
|
133
|
+
readonly event: "cancelled";
|
|
134
|
+
readonly id?: string;
|
|
135
|
+
}
|
|
136
|
+
export interface IdleEvent {
|
|
137
|
+
readonly event: "idle";
|
|
138
|
+
readonly command: string;
|
|
139
|
+
readonly id?: string;
|
|
140
|
+
}
|
|
141
|
+
export interface AssetProgressEvent {
|
|
142
|
+
readonly event: "asset-progress";
|
|
143
|
+
readonly locale: string;
|
|
144
|
+
readonly fraction: number | null;
|
|
145
|
+
readonly id?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface AssetInstalledEvent {
|
|
148
|
+
readonly event: "asset-installed";
|
|
149
|
+
readonly locale: string;
|
|
150
|
+
readonly id?: string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* `release-assets`'s answer: this app's reservation of the locale's model is released (the system
|
|
154
|
+
* may then reclaim the model) and `status` is what the system reports afterwards. A model shared
|
|
155
|
+
* with system dictation can still read `installed`.
|
|
156
|
+
*/
|
|
157
|
+
export interface AssetReleasedEvent {
|
|
158
|
+
readonly event: "asset-released";
|
|
159
|
+
/** The locale as requested, e.g. `es-419`. */
|
|
160
|
+
readonly locale: string;
|
|
161
|
+
/** The model's own locale, the one the reservation was held for, e.g. `es_MX`. */
|
|
162
|
+
readonly modelLocale: string;
|
|
163
|
+
/** False when this app held no reservation for the model (nothing to release). */
|
|
164
|
+
readonly released: boolean;
|
|
165
|
+
readonly status: AssetStatus;
|
|
166
|
+
readonly canInstall: boolean;
|
|
167
|
+
readonly id?: string;
|
|
168
|
+
}
|
|
169
|
+
/** The system voice speaking an utterance, as `speech-started` names it. */
|
|
170
|
+
export interface SpeechVoiceIdentity {
|
|
171
|
+
/** The system voice identifier (the `voice` a `speak` can pin). */
|
|
172
|
+
readonly id: string;
|
|
173
|
+
readonly name: string;
|
|
174
|
+
/** The voice's own locale, e.g. `es-MX` when `es-419` was requested. */
|
|
175
|
+
readonly language: string;
|
|
176
|
+
/**
|
|
177
|
+
* The same value as `language`, under the name the voice list items use. Additive: helpers
|
|
178
|
+
* from 0.3.0 and earlier send only `language`, and the SDK fills this in from it.
|
|
179
|
+
*/
|
|
180
|
+
readonly locale: string;
|
|
181
|
+
readonly quality: "default" | "enhanced" | "premium" | "unknown";
|
|
182
|
+
}
|
|
183
|
+
export interface SpeechLifecycleEvent {
|
|
184
|
+
readonly event: "speech-started" | "speech-finished" | "speech-cancelled";
|
|
185
|
+
readonly id: string;
|
|
186
|
+
/**
|
|
187
|
+
* On `speech-started` only, when the `speak` named a voice or a locale: the voice that
|
|
188
|
+
* resolved. Additive within wire 1; older helpers omit it.
|
|
189
|
+
*/
|
|
190
|
+
readonly voice?: SpeechVoiceIdentity;
|
|
191
|
+
}
|
|
192
|
+
export interface SpeechErrorEvent {
|
|
193
|
+
readonly event: "speech-error";
|
|
194
|
+
readonly code: VoiceErrorCode;
|
|
195
|
+
readonly message?: string;
|
|
196
|
+
readonly id: string;
|
|
197
|
+
}
|
|
198
|
+
export interface SpeechStateEvent {
|
|
199
|
+
readonly event: "speech-state";
|
|
200
|
+
readonly state: "paused" | "resumed";
|
|
201
|
+
}
|
|
202
|
+
export interface SpeechInterruptedEvent {
|
|
203
|
+
readonly event: "speech-interrupted" | "speech-route-changed";
|
|
204
|
+
readonly reason?: string;
|
|
205
|
+
}
|
|
206
|
+
export type TurnWireState = "idle" | "listening" | "responding" | "speaking" | "interrupted" | "ended";
|
|
207
|
+
export interface TurnStateEvent {
|
|
208
|
+
readonly event: "turn-state";
|
|
209
|
+
readonly id: string;
|
|
210
|
+
readonly state: TurnWireState;
|
|
211
|
+
/** Set on `ended`. */
|
|
212
|
+
readonly reason?: TurnEndReason;
|
|
213
|
+
}
|
|
214
|
+
export interface TurnPartialEvent {
|
|
215
|
+
readonly event: "turn-partial";
|
|
216
|
+
readonly id: string;
|
|
217
|
+
readonly text?: string;
|
|
218
|
+
readonly finalizedText: string;
|
|
219
|
+
readonly volatileText: string;
|
|
220
|
+
readonly sequence: number;
|
|
221
|
+
}
|
|
222
|
+
export interface TurnTranscriptEvent {
|
|
223
|
+
readonly event: "turn-transcript";
|
|
224
|
+
readonly id: string;
|
|
225
|
+
readonly text: string;
|
|
226
|
+
}
|
|
227
|
+
export interface TurnBargeInEvent {
|
|
228
|
+
readonly event: "turn-barge-in";
|
|
229
|
+
readonly id: string;
|
|
230
|
+
}
|
|
231
|
+
export interface TurnSpeechEvent {
|
|
232
|
+
readonly event: "turn-speech-started" | "turn-speech-finished" | "turn-speech-cancelled";
|
|
233
|
+
readonly id: string;
|
|
234
|
+
readonly utterance: string;
|
|
235
|
+
}
|
|
236
|
+
/** Timings only, in milliseconds from `turn-start`; never text or audio. */
|
|
237
|
+
export interface TurnMetricsEvent {
|
|
238
|
+
readonly event: "turn-metrics";
|
|
239
|
+
readonly id: string;
|
|
240
|
+
readonly firstPartialMs: number | null;
|
|
241
|
+
readonly transcriptMs: number | null;
|
|
242
|
+
readonly firstAudioMs: number | null;
|
|
243
|
+
readonly speechFinishedMs: number | null;
|
|
244
|
+
}
|
|
245
|
+
export interface TurnErrorEvent {
|
|
246
|
+
readonly event: "turn-error";
|
|
247
|
+
readonly id: string;
|
|
248
|
+
readonly code: VoiceErrorCode;
|
|
249
|
+
readonly message?: string;
|
|
250
|
+
}
|
|
251
|
+
export type TurnWireEvent = TurnStateEvent | TurnPartialEvent | TurnTranscriptEvent | TurnBargeInEvent | TurnSpeechEvent | TurnMetricsEvent | TurnErrorEvent;
|
|
252
|
+
/** Whether an event is a turn's one terminal (`turn-state` `ended` or `turn-error`). */
|
|
253
|
+
export declare function isTurnTerminal(event: WireEvent): event is TurnStateEvent | TurnErrorEvent;
|
|
254
|
+
/** A second line the local-model helpers print after `version`. */
|
|
255
|
+
export interface HelperIdentityEvent {
|
|
256
|
+
readonly event: "helper";
|
|
257
|
+
readonly name: string;
|
|
258
|
+
readonly engine: string;
|
|
259
|
+
readonly library?: string;
|
|
260
|
+
}
|
|
261
|
+
export type WireEvent = VersionEvent | HelperIdentityEvent | PermissionEvent | AppleStatusEvent | TranscribeStatusEvent | SynthesisStatusEvent | LocaleEvent | ListDoneEvent | VoiceEvent | ListeningEvent | PartialEvent | FinalEvent | ErrorEvent | CancelledEvent | IdleEvent | AssetProgressEvent | AssetInstalledEvent | AssetReleasedEvent | SpeechLifecycleEvent | SpeechErrorEvent | SpeechStateEvent | SpeechInterruptedEvent | TurnWireEvent;
|
|
262
|
+
/** A command line. `cmd` is the helpers' key; `command` is sent too for the transcribe helper. */
|
|
263
|
+
export interface WireCommand {
|
|
264
|
+
readonly cmd: string;
|
|
265
|
+
readonly id?: string;
|
|
266
|
+
readonly [field: string]: unknown;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Parses one stdout line. Returns `undefined` for anything that is not a JSON object with a string
|
|
270
|
+
* `event` (a helper's stray diagnostic line must never crash a host). Error codes are normalised
|
|
271
|
+
* to the snake_case vocabulary; an unknown code becomes `failed`.
|
|
272
|
+
*/
|
|
273
|
+
export declare function parseWireLine(line: string): WireEvent | undefined;
|
|
274
|
+
/** Encodes one command line (no trailing newline). */
|
|
275
|
+
export declare function encodeWireCommand(command: WireCommand): string;
|
|
276
|
+
/** The request id an event answers, or `undefined` for an uncorrelated event. */
|
|
277
|
+
export declare function correlationId(event: WireEvent): string | undefined;
|
|
278
|
+
/** Whether a version handshake is one this SDK can talk to. */
|
|
279
|
+
export declare function isCompatibleHandshake(event: VersionEvent): boolean;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { TurnEvent } from "../contract/turns";
|
|
2
|
+
import { type HelperConnection } from "./helper-process";
|
|
3
|
+
export interface ConversationRespondOptions {
|
|
4
|
+
/** Whether this is the answer's last chunk. Default true: one call is one whole answer. */
|
|
5
|
+
readonly final?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** A running conversation. */
|
|
8
|
+
export interface DesktopConversation {
|
|
9
|
+
readonly provider: string;
|
|
10
|
+
readonly locale: string;
|
|
11
|
+
/**
|
|
12
|
+
* Every turn's events in order, each tagged with `turn`. Finishes after the conversation's
|
|
13
|
+
* last terminal: a `failed` turn, `cancelled` (from `cancel()` or the helper), or the `ended`
|
|
14
|
+
* of the last turn after `end()`. Can be read once.
|
|
15
|
+
*/
|
|
16
|
+
events(): AsyncIterable<TurnEvent>;
|
|
17
|
+
/**
|
|
18
|
+
* Speaks (part of) the current turn's answer. Chunks queue without gaps, so a streaming model's
|
|
19
|
+
* text can be spoken as it arrives; send `{ final: true }` (an empty text is fine) to finish
|
|
20
|
+
* the answer. Responding while the person is still talking closes the microphone.
|
|
21
|
+
*/
|
|
22
|
+
respond(textChunk: string, options?: ConversationRespondOptions): Promise<void>;
|
|
23
|
+
/** Starts the next turn now; while the answer plays this is a barge-in. */
|
|
24
|
+
listen(): Promise<void>;
|
|
25
|
+
/** Push-to-talk release: stop needing audio; the transcript of what was heard follows. */
|
|
26
|
+
stopListening(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Finishes after the current exchange: no further turns start. A turn waiting for an answer
|
|
29
|
+
* closes now; one that is listening finalizes first (then `end()` again, or `respond()`).
|
|
30
|
+
*/
|
|
31
|
+
end(): Promise<void>;
|
|
32
|
+
/** Stops everything now: speech, microphone, further turns. Ends with `cancelled`. Idempotent. */
|
|
33
|
+
cancel(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export interface ConversationOptions {
|
|
36
|
+
readonly connection: HelperConnection;
|
|
37
|
+
readonly provider: string;
|
|
38
|
+
readonly locale: string;
|
|
39
|
+
readonly engine: "analyzer" | "legacy" | undefined;
|
|
40
|
+
readonly bargeIn: boolean;
|
|
41
|
+
readonly halfDuplex: boolean;
|
|
42
|
+
readonly continuous: boolean;
|
|
43
|
+
/** Voice fields sent with every `turn-respond` (already on the helper's scale). */
|
|
44
|
+
readonly voice: {
|
|
45
|
+
readonly voice?: string;
|
|
46
|
+
readonly locale?: string;
|
|
47
|
+
readonly rate?: number;
|
|
48
|
+
};
|
|
49
|
+
/** After `cancel()`, how long the helper gets to report the terminal before it is restarted. */
|
|
50
|
+
readonly terminalGraceMs: number;
|
|
51
|
+
readonly onStuck: () => void;
|
|
52
|
+
readonly onFinished: () => void;
|
|
53
|
+
}
|
|
54
|
+
export declare class Conversation implements DesktopConversation {
|
|
55
|
+
private readonly options;
|
|
56
|
+
readonly provider: string;
|
|
57
|
+
readonly locale: string;
|
|
58
|
+
private current;
|
|
59
|
+
private readonly queue;
|
|
60
|
+
private waiter;
|
|
61
|
+
private consumed;
|
|
62
|
+
private finished;
|
|
63
|
+
private ending;
|
|
64
|
+
private cancelling;
|
|
65
|
+
private graceTimer;
|
|
66
|
+
constructor(options: ConversationOptions);
|
|
67
|
+
get isFinished(): boolean;
|
|
68
|
+
/** Starts the first turn; resolves once the microphone is open, rejects if the turn failed. */
|
|
69
|
+
begin(): Promise<void>;
|
|
70
|
+
events(): AsyncIterable<TurnEvent>;
|
|
71
|
+
respond(textChunk: string, options?: ConversationRespondOptions): Promise<void>;
|
|
72
|
+
listen(): Promise<void>;
|
|
73
|
+
stopListening(): Promise<void>;
|
|
74
|
+
end(): Promise<void>;
|
|
75
|
+
cancel(): Promise<void>;
|
|
76
|
+
private startTurn;
|
|
77
|
+
/** Maps one helper line of this turn to the shared vocabulary. */
|
|
78
|
+
private forward;
|
|
79
|
+
private closeTurn;
|
|
80
|
+
/** What the conversation does once a turn has ended. */
|
|
81
|
+
private afterTerminal;
|
|
82
|
+
/** How each turn ended (`failed` for an error), until the conversation has acted on it. */
|
|
83
|
+
private readonly reasons;
|
|
84
|
+
private finish;
|
|
85
|
+
private push;
|
|
86
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@adea-ai/voice/desktop`: the one desktop speech client every Adea app uses.
|
|
3
|
+
*
|
|
4
|
+
* It runs the pinned helpers the app bundles — `adea-voice-helper` (Apple speech on macOS),
|
|
5
|
+
* `adea-transcribe-helper` (transcribe.cpp) and `adea-tts-helper` (audio.cpp) — and exposes them
|
|
6
|
+
* as providers of the shared contract. Routing, availability reasons, error codes, cancellation and
|
|
7
|
+
* the privacy rules live here and in the helpers; an app only renders what this returns.
|
|
8
|
+
*
|
|
9
|
+
* Rules it keeps for every host:
|
|
10
|
+
* - a helper that is missing from the build is an explicit `providerNotRegistered`, never a
|
|
11
|
+
* silent substitute; a helper on another wire/contract major is refused;
|
|
12
|
+
* - one dictation at a time; a second is `busy`;
|
|
13
|
+
* - every dictation ends in exactly one terminal event (`final`, `failed` or `cancelled`), even if
|
|
14
|
+
* the helper crashes or stops answering (the process is then killed and restarted on demand);
|
|
15
|
+
* - no network: every desktop provider runs on the device, and model installs happen only through
|
|
16
|
+
* `installAssets`, which a person starts.
|
|
17
|
+
*/
|
|
18
|
+
import { type VoiceProviderAvailability, type VoiceProviderDescriptor, type VoiceProviderKind, type VoiceRoutingDecision, type VoiceRoutingPolicy } from "../contract/contract";
|
|
19
|
+
import type { PartialTranscript, TranscriptionSession } from "../contract/session";
|
|
20
|
+
import type { CombinedPermission, LocaleEvent, PermissionPart, SpeechVoiceIdentity, TranscribeStatusEvent, VoiceEvent } from "../contract/wire";
|
|
21
|
+
import { type VoiceSettings } from "../settings/settings";
|
|
22
|
+
import { type DesktopConversation } from "./conversation";
|
|
23
|
+
import { type HelperSpawner } from "./helper-process";
|
|
24
|
+
export declare const APPLE_ANALYZER_ID = "apple.analyzer";
|
|
25
|
+
export declare const APPLE_LEGACY_ID = "apple.legacy";
|
|
26
|
+
export declare const APPLE_VOICES_ID = "apple.system-voices";
|
|
27
|
+
export declare const TRANSCRIBE_CPP_ID = "transcribe.cpp";
|
|
28
|
+
export declare const AUDIO_CPP_ID = "audio.cpp";
|
|
29
|
+
export type DesktopOS = "darwin" | "win32" | "linux";
|
|
30
|
+
/**
|
|
31
|
+
* The SDK-wide desktop table (docs/provider-contract.md, "Default matrix"). transcribe.cpp is the
|
|
32
|
+
* one optional desktop STT engine on macOS: a person selects it, it is never a silent fallback.
|
|
33
|
+
*/
|
|
34
|
+
export declare function desktopRoutingPolicy(os: DesktopOS): VoiceRoutingPolicy;
|
|
35
|
+
export declare const DESKTOP_DESCRIPTORS: Readonly<Record<string, VoiceProviderDescriptor>>;
|
|
36
|
+
export interface DesktopHelperPaths {
|
|
37
|
+
/** `adea-voice-helper` (macOS). `null`/absent: not in this build. */
|
|
38
|
+
readonly voice?: string | null;
|
|
39
|
+
/** `adea-transcribe-helper`. */
|
|
40
|
+
readonly transcribe?: string | null;
|
|
41
|
+
/** `adea-tts-helper`. */
|
|
42
|
+
readonly tts?: string | null;
|
|
43
|
+
}
|
|
44
|
+
export interface DesktopVoiceOptions {
|
|
45
|
+
readonly helpers: DesktopHelperPaths;
|
|
46
|
+
readonly os?: DesktopOS;
|
|
47
|
+
readonly spawn?: HelperSpawner;
|
|
48
|
+
/** Extra environment for the helpers (never secrets: the helpers need none). */
|
|
49
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
50
|
+
readonly log?: (message: string) => void;
|
|
51
|
+
/** A dictation never runs longer than this. Default 75 s (the helper's own cap is 60 s). */
|
|
52
|
+
readonly maxListenMs?: number;
|
|
53
|
+
/** After `end`/`cancel`, how long the helper gets to send the terminal event. Default 5 s. */
|
|
54
|
+
readonly terminalGraceMs?: number;
|
|
55
|
+
}
|
|
56
|
+
export type PermissionState = CombinedPermission;
|
|
57
|
+
export interface PermissionReport {
|
|
58
|
+
/** The combined answer for dictation. */
|
|
59
|
+
readonly state: PermissionState;
|
|
60
|
+
readonly microphone: PermissionPart | "unknown";
|
|
61
|
+
readonly speech: PermissionPart | "unknown";
|
|
62
|
+
}
|
|
63
|
+
export interface ProviderStatus {
|
|
64
|
+
readonly id: string;
|
|
65
|
+
readonly displayName: string;
|
|
66
|
+
readonly kind: VoiceProviderKind;
|
|
67
|
+
/** Whether this build bundles the provider's helper. */
|
|
68
|
+
readonly bundled: boolean;
|
|
69
|
+
readonly availability: VoiceProviderAvailability;
|
|
70
|
+
}
|
|
71
|
+
export interface VoiceCapabilities {
|
|
72
|
+
readonly os: DesktopOS;
|
|
73
|
+
readonly speechToText: VoiceRoutingDecision;
|
|
74
|
+
readonly textToSpeech: VoiceRoutingDecision;
|
|
75
|
+
readonly providers: readonly ProviderStatus[];
|
|
76
|
+
readonly permission: PermissionReport;
|
|
77
|
+
/** Local models transcribe.cpp can see (BYOM folders included). */
|
|
78
|
+
readonly localModels: TranscribeStatusEvent["models"];
|
|
79
|
+
}
|
|
80
|
+
export interface DictationRequest {
|
|
81
|
+
readonly settings: VoiceSettings;
|
|
82
|
+
/** BCP-47; defaults to the settings' locale, then the system language. */
|
|
83
|
+
readonly locale?: string;
|
|
84
|
+
readonly onPartial?: (partial: PartialTranscript & {
|
|
85
|
+
readonly text: string;
|
|
86
|
+
}) => void;
|
|
87
|
+
readonly signal?: AbortSignal;
|
|
88
|
+
}
|
|
89
|
+
/** A running dictation: the shared session contract plus the resolved route. */
|
|
90
|
+
export interface DesktopDictation extends TranscriptionSession {
|
|
91
|
+
readonly provider: string;
|
|
92
|
+
readonly locale: string;
|
|
93
|
+
/** Resolves with the final text; rejects with `VoiceError` (`cancelled`, `no_speech`, …). */
|
|
94
|
+
readonly result: Promise<string>;
|
|
95
|
+
}
|
|
96
|
+
export interface SpeakRequest {
|
|
97
|
+
readonly settings: VoiceSettings;
|
|
98
|
+
readonly text: string;
|
|
99
|
+
readonly locale?: string;
|
|
100
|
+
readonly voice?: string;
|
|
101
|
+
readonly rate?: number;
|
|
102
|
+
/** `replace` (default) stops what is playing; `after-current` queues. */
|
|
103
|
+
readonly queue?: "replace" | "after-current";
|
|
104
|
+
}
|
|
105
|
+
export type SpeechOutcome = "finished" | "cancelled";
|
|
106
|
+
/** What the helper reports when audio starts. */
|
|
107
|
+
export interface SpeechStart {
|
|
108
|
+
/**
|
|
109
|
+
* The voice that resolved for the request (`speech-started.voice`), when the helper reports it
|
|
110
|
+
* (Apple helper builds after 0.2.0 do, for a `speak` that named a voice or a locale).
|
|
111
|
+
*/
|
|
112
|
+
readonly voice?: SpeechVoiceIdentity;
|
|
113
|
+
}
|
|
114
|
+
export interface DesktopSpeech {
|
|
115
|
+
readonly id: string;
|
|
116
|
+
readonly provider: string;
|
|
117
|
+
/**
|
|
118
|
+
* Resolves when the helper reports `speech-started` (audio begins), with the voice it resolved.
|
|
119
|
+
* Resolves `undefined` if the speech ends, is cancelled or fails before it started; never
|
|
120
|
+
* rejects.
|
|
121
|
+
*/
|
|
122
|
+
readonly started: Promise<SpeechStart | undefined>;
|
|
123
|
+
/** Resolves when playback ends or is cancelled; rejects with `VoiceError` on failure. */
|
|
124
|
+
readonly done: Promise<SpeechOutcome>;
|
|
125
|
+
cancel(): Promise<void>;
|
|
126
|
+
}
|
|
127
|
+
export interface ConversationRequest {
|
|
128
|
+
readonly settings: VoiceSettings;
|
|
129
|
+
/** BCP-47 for listening; defaults to the settings' locale, then the system language. */
|
|
130
|
+
readonly locale?: string;
|
|
131
|
+
/** Starting a turn while the answer plays stops it (a request cancel). Default true. */
|
|
132
|
+
readonly bargeIn?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* The microphone stays closed while the answer plays, so the assistant never hears itself.
|
|
135
|
+
* Default true; turn it off only with echo cancellation (a headset).
|
|
136
|
+
*/
|
|
137
|
+
readonly halfDuplex?: boolean;
|
|
138
|
+
/** Start the next turn by itself once an answer has played. Default true (hands-free). */
|
|
139
|
+
readonly continuous?: boolean;
|
|
140
|
+
readonly signal?: AbortSignal;
|
|
141
|
+
}
|
|
142
|
+
export interface DesktopVoiceInfo {
|
|
143
|
+
readonly id: string;
|
|
144
|
+
readonly name: string;
|
|
145
|
+
readonly locale: string;
|
|
146
|
+
readonly quality: VoiceEvent["quality"];
|
|
147
|
+
readonly provider: string;
|
|
148
|
+
}
|
|
149
|
+
export interface LocaleAsset {
|
|
150
|
+
readonly locale: string;
|
|
151
|
+
readonly status: LocaleEvent["status"];
|
|
152
|
+
readonly canInstall: boolean;
|
|
153
|
+
}
|
|
154
|
+
export interface InstallRequest {
|
|
155
|
+
readonly locale: string;
|
|
156
|
+
readonly onProgress?: (fraction: number | null) => void;
|
|
157
|
+
readonly signal?: AbortSignal;
|
|
158
|
+
}
|
|
159
|
+
export interface ReleaseRequest {
|
|
160
|
+
/** BCP-47 locale whose Apple model to remove, e.g. `es-419` (released as its model locale, `es_MX`). */
|
|
161
|
+
readonly locale: string;
|
|
162
|
+
}
|
|
163
|
+
/** What `releaseAssets` did, and the locale's model state afterwards. */
|
|
164
|
+
export interface ReleasedAsset {
|
|
165
|
+
readonly locale: string;
|
|
166
|
+
/** The model's own locale in BCP-47 (`es-MX` for `es-419`). */
|
|
167
|
+
readonly modelLocale: string;
|
|
168
|
+
/** False when this app held no reservation for the model (nothing was released). */
|
|
169
|
+
readonly released: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* The status the system reports after the release. Usually `notInstalled`; a model shared with
|
|
172
|
+
* system dictation can stay `installed` until the OS reclaims it.
|
|
173
|
+
*/
|
|
174
|
+
readonly status: LocaleEvent["status"];
|
|
175
|
+
readonly canInstall: boolean;
|
|
176
|
+
}
|
|
177
|
+
export interface DesktopVoice {
|
|
178
|
+
/** Which helpers this build bundles (synchronous, no process started). */
|
|
179
|
+
bundled(): Readonly<Record<"voice" | "transcribe" | "tts", boolean>>;
|
|
180
|
+
capabilities(settings: VoiceSettings, locale?: string): Promise<VoiceCapabilities>;
|
|
181
|
+
permission(options?: {
|
|
182
|
+
readonly request?: boolean;
|
|
183
|
+
}): Promise<PermissionReport>;
|
|
184
|
+
listen(request: DictationRequest): Promise<DesktopDictation>;
|
|
185
|
+
speak(request: SpeakRequest): Promise<DesktopSpeech>;
|
|
186
|
+
stopSpeaking(): Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Starts a voice conversation (Octy-style turns with streamed answers and barge-in) and
|
|
189
|
+
* resolves once the first turn is listening. Runs on `adea-voice-helper` (Apple speech, wire
|
|
190
|
+
* 1.2+): a route to another engine is a typed `unavailable`.
|
|
191
|
+
*/
|
|
192
|
+
conversation(request: ConversationRequest): Promise<DesktopConversation>;
|
|
193
|
+
voices(settings: VoiceSettings, locale?: string): Promise<readonly DesktopVoiceInfo[]>;
|
|
194
|
+
locales(): Promise<readonly LocaleAsset[]>;
|
|
195
|
+
installAssets(request: InstallRequest): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Removes an Apple on-device speech model: releases this app's reservation of it so the OS may
|
|
198
|
+
* reclaim the storage. Nothing is deleted directly; the system decides when the files go.
|
|
199
|
+
* Needs a voice helper on wire 1.3+ (`unavailable` otherwise).
|
|
200
|
+
*/
|
|
201
|
+
releaseAssets(request: ReleaseRequest): Promise<ReleasedAsset>;
|
|
202
|
+
/** Stops every helper. The instance can be used again; helpers restart on demand. */
|
|
203
|
+
dispose(): Promise<void>;
|
|
204
|
+
}
|
|
205
|
+
export declare function createDesktopVoice(options: DesktopVoiceOptions): DesktopVoice;
|
|
206
|
+
/**
|
|
207
|
+
* Apple's engine variant (`stt.model` `analyzer`/`legacy`) is a provider choice: with no explicit
|
|
208
|
+
* provider it pins that engine, so "Modern" or "Compatibility" in settings is what dictation runs.
|
|
209
|
+
*/
|
|
210
|
+
export declare function withModelChoice(settings: VoiceSettings): VoiceSettings;
|
|
211
|
+
/** Finalized + volatile text, with exactly one space between them where needed. */
|
|
212
|
+
export declare function joinTranscript(finalizedText: string, volatileText: string): string;
|