@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.
Files changed (60) hide show
  1. package/README.md +136 -2
  2. package/dist/cli/helpers-cli.d.ts +2 -0
  3. package/dist/cli/helpers-cli.js +117 -0
  4. package/dist/contract/contract.d.ts +157 -0
  5. package/dist/contract/errors.d.ts +26 -0
  6. package/dist/contract/index.d.ts +10 -0
  7. package/dist/contract/index.js +64 -0
  8. package/dist/contract/session.d.ts +71 -0
  9. package/dist/contract/turns.d.ts +91 -0
  10. package/dist/contract/wire.d.ts +279 -0
  11. package/dist/desktop/conversation.d.ts +86 -0
  12. package/dist/desktop/desktop-voice.d.ts +212 -0
  13. package/dist/desktop/helper-lock.d.ts +121 -0
  14. package/dist/desktop/helper-process.d.ts +96 -0
  15. package/dist/desktop/index.d.ts +9 -0
  16. package/dist/desktop/index.js +1454 -0
  17. package/dist/desktop/macho-digest.d.ts +9 -0
  18. package/dist/index-7n7epq1a.js +47 -0
  19. package/dist/index-a7d617zr.js +295 -0
  20. package/dist/index-ght8wwpd.js +156 -0
  21. package/dist/index-m4g2tpeq.js +522 -0
  22. package/dist/index-r4hz8gk0.js +10 -0
  23. package/dist/index-tvz9s9nz.js +77 -0
  24. package/dist/index.d.ts +7 -0
  25. package/dist/index.js +96 -0
  26. package/dist/settings/index.d.ts +5 -0
  27. package/dist/settings/index.js +34 -0
  28. package/dist/settings/settings.d.ts +163 -0
  29. package/dist/web/index.d.ts +16 -0
  30. package/dist/web/index.js +1697 -0
  31. package/dist/web/stt/speech-recognition.d.ts +226 -0
  32. package/dist/web/tts/locale-match.d.ts +40 -0
  33. package/dist/web/tts/phonon.d.ts +139 -0
  34. package/dist/web/tts/player.d.ts +115 -0
  35. package/dist/web/tts/system-voices.d.ts +162 -0
  36. package/dist/web/turns.d.ts +91 -0
  37. package/package.json +68 -4
  38. package/src/cli/helpers-cli.ts +135 -0
  39. package/src/contract/contract.ts +393 -0
  40. package/src/contract/errors.ts +98 -0
  41. package/src/contract/index.ts +10 -0
  42. package/src/contract/session.ts +77 -0
  43. package/src/contract/turns.ts +48 -0
  44. package/src/contract/wire.ts +384 -0
  45. package/src/desktop/conversation.ts +347 -0
  46. package/src/desktop/desktop-voice.ts +1129 -0
  47. package/src/desktop/helper-lock.ts +550 -0
  48. package/src/desktop/helper-process.ts +408 -0
  49. package/src/desktop/index.ts +18 -0
  50. package/src/desktop/macho-digest.ts +135 -0
  51. package/src/index.ts +7 -0
  52. package/src/settings/index.ts +5 -0
  53. package/src/settings/settings.ts +478 -0
  54. package/src/web/index.ts +16 -0
  55. package/src/web/stt/speech-recognition.ts +1013 -0
  56. package/src/web/tts/locale-match.ts +131 -0
  57. package/src/web/tts/phonon.ts +386 -0
  58. package/src/web/tts/player.ts +271 -0
  59. package/src/web/tts/system-voices.ts +510 -0
  60. package/src/web/turns.ts +235 -0
@@ -0,0 +1,384 @@
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 { normalizeVoiceErrorCode, type VoiceErrorCode } from "./errors";
10
+ import type { TurnEndReason } from "./turns";
11
+
12
+ /** The wire major this SDK speaks. A helper on another major is refused, never guessed at. */
13
+ export const WIRE_VERSION = 1;
14
+ /** The wire minor that added conversation turns (`turn-*`); older helpers cannot run them. */
15
+ export const TURN_WIRE_MINOR = 2;
16
+ /** The wire minor that added model removal (`release-assets` → `asset-released`). */
17
+ export const RELEASE_ASSETS_WIRE_MINOR = 3;
18
+ /** The provider-contract major this SDK speaks. */
19
+ export const CONTRACT_MAJOR = 1;
20
+ /** One line may not exceed this many bytes (the helpers enforce the same bound on input). */
21
+ export const MAX_WIRE_LINE_BYTES = 1_000_000;
22
+
23
+ export interface VersionEvent {
24
+ readonly event: "version";
25
+ readonly wire: number;
26
+ readonly wireMinor?: number;
27
+ readonly contract: string;
28
+ readonly contractMajor: number;
29
+ readonly helper?: string;
30
+ /** The voice release the helper was built from (e.g. `0.2.0`); a lock pins it. */
31
+ readonly release?: string;
32
+ readonly id?: string;
33
+ }
34
+
35
+ export type CombinedPermission = "granted" | "denied" | "prompt" | "unavailable";
36
+ export type PermissionPart = "granted" | "denied" | "restricted" | "prompt";
37
+
38
+ export interface PermissionEvent {
39
+ readonly event: "permission";
40
+ readonly state: CombinedPermission;
41
+ readonly microphone?: PermissionPart;
42
+ readonly speech?: PermissionPart;
43
+ readonly id?: string;
44
+ }
45
+
46
+ export type EngineState = "available" | "needsAssetInstall" | "unavailableOS" | "localeUnsupported" | "engineUnavailable";
47
+ export type AssetStatus = "installed" | "notInstalled" | "downloading" | "unsupported";
48
+
49
+ /** `adea-voice-helper` status: Apple's two engines for one locale. */
50
+ export interface AppleStatusEvent {
51
+ readonly event: "status";
52
+ readonly locale: string;
53
+ readonly analyzer: EngineState;
54
+ readonly legacy: EngineState;
55
+ readonly analyzerEquivalentLocale: string;
56
+ readonly recommendedEngine: "analyzer" | "legacy" | "none";
57
+ readonly assetStatus: AssetStatus;
58
+ readonly canInstall: boolean;
59
+ readonly id?: string;
60
+ }
61
+
62
+ /** `adea-transcribe-helper` status: the local models it can see. */
63
+ export interface TranscribeStatusEvent {
64
+ readonly event: "status";
65
+ readonly engine: "transcribe";
66
+ readonly locale: string;
67
+ readonly models: readonly {
68
+ readonly path: string;
69
+ readonly architecture: string;
70
+ readonly variant: string;
71
+ readonly languages: readonly string[];
72
+ readonly streaming: boolean;
73
+ }[];
74
+ readonly ready: boolean;
75
+ readonly selected?: string;
76
+ readonly id?: string;
77
+ }
78
+
79
+ /** `adea-tts-helper` status. */
80
+ export interface SynthesisStatusEvent {
81
+ readonly event: "status";
82
+ readonly engine: "audio.cpp";
83
+ readonly locale: string;
84
+ readonly modelPath: string;
85
+ readonly voice: string;
86
+ readonly ready: boolean;
87
+ readonly reason?: string;
88
+ readonly message?: string;
89
+ readonly id?: string;
90
+ }
91
+
92
+ export interface LocaleEvent {
93
+ readonly event: "locale";
94
+ readonly locale: string;
95
+ readonly status: AssetStatus;
96
+ readonly canInstall: boolean;
97
+ readonly id?: string;
98
+ }
99
+
100
+ export interface ListDoneEvent {
101
+ readonly event: "locales-done" | "voices-done";
102
+ readonly count: number;
103
+ readonly id?: string;
104
+ }
105
+
106
+ export interface VoiceEvent {
107
+ readonly event: "voice";
108
+ /** The voice identifier (not the request id). */
109
+ readonly id: string;
110
+ readonly requestId?: string;
111
+ readonly name: string;
112
+ readonly locale: string;
113
+ readonly quality: "default" | "enhanced" | "premium" | "unknown";
114
+ readonly gender: "male" | "female" | "unknown";
115
+ readonly source?: string;
116
+ }
117
+
118
+ export interface ListeningEvent {
119
+ readonly event: "listening";
120
+ readonly engine: string;
121
+ readonly locale: string;
122
+ readonly model?: string;
123
+ readonly id?: string;
124
+ }
125
+
126
+ export interface PartialEvent {
127
+ readonly event: "partial";
128
+ readonly text?: string;
129
+ readonly finalizedText: string;
130
+ readonly volatileText: string;
131
+ readonly sequence: number;
132
+ readonly id?: string;
133
+ }
134
+
135
+ export interface FinalEvent {
136
+ readonly event: "final";
137
+ readonly text: string;
138
+ readonly id?: string;
139
+ }
140
+
141
+ export interface ErrorEvent {
142
+ readonly event: "error";
143
+ readonly code: VoiceErrorCode;
144
+ readonly message?: string;
145
+ readonly id?: string;
146
+ }
147
+
148
+ export interface CancelledEvent {
149
+ readonly event: "cancelled";
150
+ readonly id?: string;
151
+ }
152
+
153
+ export interface IdleEvent {
154
+ readonly event: "idle";
155
+ readonly command: string;
156
+ readonly id?: string;
157
+ }
158
+
159
+ export interface AssetProgressEvent {
160
+ readonly event: "asset-progress";
161
+ readonly locale: string;
162
+ readonly fraction: number | null;
163
+ readonly id?: string;
164
+ }
165
+
166
+ export interface AssetInstalledEvent {
167
+ readonly event: "asset-installed";
168
+ readonly locale: string;
169
+ readonly id?: string;
170
+ }
171
+
172
+ /**
173
+ * `release-assets`'s answer: this app's reservation of the locale's model is released (the system
174
+ * may then reclaim the model) and `status` is what the system reports afterwards. A model shared
175
+ * with system dictation can still read `installed`.
176
+ */
177
+ export interface AssetReleasedEvent {
178
+ readonly event: "asset-released";
179
+ /** The locale as requested, e.g. `es-419`. */
180
+ readonly locale: string;
181
+ /** The model's own locale, the one the reservation was held for, e.g. `es_MX`. */
182
+ readonly modelLocale: string;
183
+ /** False when this app held no reservation for the model (nothing to release). */
184
+ readonly released: boolean;
185
+ readonly status: AssetStatus;
186
+ readonly canInstall: boolean;
187
+ readonly id?: string;
188
+ }
189
+
190
+ /** The system voice speaking an utterance, as `speech-started` names it. */
191
+ export interface SpeechVoiceIdentity {
192
+ /** The system voice identifier (the `voice` a `speak` can pin). */
193
+ readonly id: string;
194
+ readonly name: string;
195
+ /** The voice's own locale, e.g. `es-MX` when `es-419` was requested. */
196
+ readonly language: string;
197
+ /**
198
+ * The same value as `language`, under the name the voice list items use. Additive: helpers
199
+ * from 0.3.0 and earlier send only `language`, and the SDK fills this in from it.
200
+ */
201
+ readonly locale: string;
202
+ readonly quality: "default" | "enhanced" | "premium" | "unknown";
203
+ }
204
+
205
+ export interface SpeechLifecycleEvent {
206
+ readonly event: "speech-started" | "speech-finished" | "speech-cancelled";
207
+ readonly id: string;
208
+ /**
209
+ * On `speech-started` only, when the `speak` named a voice or a locale: the voice that
210
+ * resolved. Additive within wire 1; older helpers omit it.
211
+ */
212
+ readonly voice?: SpeechVoiceIdentity;
213
+ }
214
+
215
+ export interface SpeechErrorEvent {
216
+ readonly event: "speech-error";
217
+ readonly code: VoiceErrorCode;
218
+ readonly message?: string;
219
+ readonly id: string;
220
+ }
221
+
222
+ export interface SpeechStateEvent {
223
+ readonly event: "speech-state";
224
+ readonly state: "paused" | "resumed";
225
+ }
226
+
227
+ export interface SpeechInterruptedEvent {
228
+ readonly event: "speech-interrupted" | "speech-route-changed";
229
+ readonly reason?: string;
230
+ }
231
+
232
+ // MARK: Conversation turns (wire 1.2)
233
+ //
234
+ // Commands: `turn-start {id, locale?, engine?, bargeIn?, halfDuplex?}`,
235
+ // `turn-respond {id, text, final?, voice?, locale?, rate?}`, `turn-end {id}`, `turn-cancel {id}`.
236
+ // Every turn ends in exactly one terminal: `turn-state` `ended` or `turn-error`; `turn-metrics`
237
+ // precedes it. A command naming a closed turn is answered with `idle`.
238
+
239
+ export type TurnWireState = "idle" | "listening" | "responding" | "speaking" | "interrupted" | "ended";
240
+
241
+ export interface TurnStateEvent {
242
+ readonly event: "turn-state";
243
+ readonly id: string;
244
+ readonly state: TurnWireState;
245
+ /** Set on `ended`. */
246
+ readonly reason?: TurnEndReason;
247
+ }
248
+
249
+ export interface TurnPartialEvent {
250
+ readonly event: "turn-partial";
251
+ readonly id: string;
252
+ readonly text?: string;
253
+ readonly finalizedText: string;
254
+ readonly volatileText: string;
255
+ readonly sequence: number;
256
+ }
257
+
258
+ export interface TurnTranscriptEvent {
259
+ readonly event: "turn-transcript";
260
+ readonly id: string;
261
+ readonly text: string;
262
+ }
263
+
264
+ export interface TurnBargeInEvent {
265
+ readonly event: "turn-barge-in";
266
+ readonly id: string;
267
+ }
268
+
269
+ export interface TurnSpeechEvent {
270
+ readonly event: "turn-speech-started" | "turn-speech-finished" | "turn-speech-cancelled";
271
+ readonly id: string;
272
+ readonly utterance: string;
273
+ }
274
+
275
+ /** Timings only, in milliseconds from `turn-start`; never text or audio. */
276
+ export interface TurnMetricsEvent {
277
+ readonly event: "turn-metrics";
278
+ readonly id: string;
279
+ readonly firstPartialMs: number | null;
280
+ readonly transcriptMs: number | null;
281
+ readonly firstAudioMs: number | null;
282
+ readonly speechFinishedMs: number | null;
283
+ }
284
+
285
+ export interface TurnErrorEvent {
286
+ readonly event: "turn-error";
287
+ readonly id: string;
288
+ readonly code: VoiceErrorCode;
289
+ readonly message?: string;
290
+ }
291
+
292
+ export type TurnWireEvent =
293
+ | TurnStateEvent
294
+ | TurnPartialEvent
295
+ | TurnTranscriptEvent
296
+ | TurnBargeInEvent
297
+ | TurnSpeechEvent
298
+ | TurnMetricsEvent
299
+ | TurnErrorEvent;
300
+
301
+ /** Whether an event is a turn's one terminal (`turn-state` `ended` or `turn-error`). */
302
+ export function isTurnTerminal(event: WireEvent): event is TurnStateEvent | TurnErrorEvent {
303
+ return event.event === "turn-error" || (event.event === "turn-state" && event.state === "ended");
304
+ }
305
+
306
+ /** A second line the local-model helpers print after `version`. */
307
+ export interface HelperIdentityEvent {
308
+ readonly event: "helper";
309
+ readonly name: string;
310
+ readonly engine: string;
311
+ readonly library?: string;
312
+ }
313
+
314
+ export type WireEvent =
315
+ | VersionEvent
316
+ | HelperIdentityEvent
317
+ | PermissionEvent
318
+ | AppleStatusEvent
319
+ | TranscribeStatusEvent
320
+ | SynthesisStatusEvent
321
+ | LocaleEvent
322
+ | ListDoneEvent
323
+ | VoiceEvent
324
+ | ListeningEvent
325
+ | PartialEvent
326
+ | FinalEvent
327
+ | ErrorEvent
328
+ | CancelledEvent
329
+ | IdleEvent
330
+ | AssetProgressEvent
331
+ | AssetInstalledEvent
332
+ | AssetReleasedEvent
333
+ | SpeechLifecycleEvent
334
+ | SpeechErrorEvent
335
+ | SpeechStateEvent
336
+ | SpeechInterruptedEvent
337
+ | TurnWireEvent;
338
+
339
+ /** A command line. `cmd` is the helpers' key; `command` is sent too for the transcribe helper. */
340
+ export interface WireCommand {
341
+ readonly cmd: string;
342
+ readonly id?: string;
343
+ readonly [field: string]: unknown;
344
+ }
345
+
346
+ /**
347
+ * Parses one stdout line. Returns `undefined` for anything that is not a JSON object with a string
348
+ * `event` (a helper's stray diagnostic line must never crash a host). Error codes are normalised
349
+ * to the snake_case vocabulary; an unknown code becomes `failed`.
350
+ */
351
+ export function parseWireLine(line: string): WireEvent | undefined {
352
+ if (line.length === 0 || line.length > MAX_WIRE_LINE_BYTES) return undefined;
353
+ let value: unknown;
354
+ try {
355
+ value = JSON.parse(line);
356
+ } catch {
357
+ return undefined;
358
+ }
359
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return undefined;
360
+ const object = value as Record<string, unknown>;
361
+ if (typeof object.event !== "string") return undefined;
362
+ if (object.event === "error" || object.event === "speech-error" || object.event === "turn-error") {
363
+ return { ...object, code: normalizeVoiceErrorCode(object.code) } as unknown as WireEvent;
364
+ }
365
+ return object as unknown as WireEvent;
366
+ }
367
+
368
+ /** Encodes one command line (no trailing newline). */
369
+ export function encodeWireCommand(command: WireCommand): string {
370
+ // The transcribe helper reads `command`; the others read `cmd`. Sending both is harmless.
371
+ return JSON.stringify({ ...command, command: command.cmd });
372
+ }
373
+
374
+ /** The request id an event answers, or `undefined` for an uncorrelated event. */
375
+ export function correlationId(event: WireEvent): string | undefined {
376
+ if (event.event === "voice") return event.requestId;
377
+ if ("id" in event && typeof event.id === "string") return event.id;
378
+ return undefined;
379
+ }
380
+
381
+ /** Whether a version handshake is one this SDK can talk to. */
382
+ export function isCompatibleHandshake(event: VersionEvent): boolean {
383
+ return event.wire === WIRE_VERSION && event.contractMajor === CONTRACT_MAJOR;
384
+ }