@adea-ai/voice 0.0.0-stage → 0.2.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 (52) hide show
  1. package/README.md +51 -2
  2. package/dist/cli/helpers-cli.d.ts +2 -0
  3. package/dist/cli/helpers-cli.js +102 -0
  4. package/dist/contract/contract.d.ts +138 -0
  5. package/dist/contract/errors.d.ts +26 -0
  6. package/dist/contract/index.d.ts +9 -0
  7. package/dist/contract/index.js +54 -0
  8. package/dist/contract/session.d.ts +58 -0
  9. package/dist/contract/wire.d.ts +188 -0
  10. package/dist/desktop/desktop-voice.d.ts +152 -0
  11. package/dist/desktop/helper-lock.d.ts +83 -0
  12. package/dist/desktop/helper-process.d.ts +92 -0
  13. package/dist/desktop/index.d.ts +7 -0
  14. package/dist/desktop/index.js +1042 -0
  15. package/dist/index-9kerqn9r.js +150 -0
  16. package/dist/index-acm1yvvv.js +290 -0
  17. package/dist/index-r4hz8gk0.js +10 -0
  18. package/dist/index-rehs788p.js +42 -0
  19. package/dist/index-s270cw30.js +295 -0
  20. package/dist/index-tvz9s9nz.js +77 -0
  21. package/dist/index.d.ts +7 -0
  22. package/dist/index.js +86 -0
  23. package/dist/settings/index.d.ts +5 -0
  24. package/dist/settings/index.js +34 -0
  25. package/dist/settings/settings.d.ts +163 -0
  26. package/dist/web/index.d.ts +15 -0
  27. package/dist/web/index.js +1287 -0
  28. package/dist/web/stt/speech-recognition.d.ts +105 -0
  29. package/dist/web/tts/phonon.d.ts +139 -0
  30. package/dist/web/tts/player.d.ts +115 -0
  31. package/dist/web/tts/system-voices.d.ts +122 -0
  32. package/dist/web/turns.d.ts +101 -0
  33. package/package.json +68 -4
  34. package/src/cli/helpers-cli.ts +119 -0
  35. package/src/contract/contract.ts +365 -0
  36. package/src/contract/errors.ts +98 -0
  37. package/src/contract/index.ts +9 -0
  38. package/src/contract/session.ts +65 -0
  39. package/src/contract/wire.ts +263 -0
  40. package/src/desktop/desktop-voice.ts +933 -0
  41. package/src/desktop/helper-lock.ts +375 -0
  42. package/src/desktop/helper-process.ts +401 -0
  43. package/src/desktop/index.ts +16 -0
  44. package/src/index.ts +7 -0
  45. package/src/settings/index.ts +5 -0
  46. package/src/settings/settings.ts +478 -0
  47. package/src/web/index.ts +15 -0
  48. package/src/web/stt/speech-recognition.ts +583 -0
  49. package/src/web/tts/phonon.ts +386 -0
  50. package/src/web/tts/player.ts +271 -0
  51. package/src/web/tts/system-voices.ts +401 -0
  52. package/src/web/turns.ts +224 -0
@@ -0,0 +1,263 @@
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
+
11
+ /** The wire major this SDK speaks. A helper on another major is refused, never guessed at. */
12
+ export const WIRE_VERSION = 1;
13
+ /** The provider-contract major this SDK speaks. */
14
+ export const CONTRACT_MAJOR = 1;
15
+ /** One line may not exceed this many bytes (the helpers enforce the same bound on input). */
16
+ export const MAX_WIRE_LINE_BYTES = 1_000_000;
17
+
18
+ export interface VersionEvent {
19
+ readonly event: "version";
20
+ readonly wire: number;
21
+ readonly wireMinor?: number;
22
+ readonly contract: string;
23
+ readonly contractMajor: number;
24
+ readonly helper?: string;
25
+ readonly id?: string;
26
+ }
27
+
28
+ export type CombinedPermission = "granted" | "denied" | "prompt" | "unavailable";
29
+ export type PermissionPart = "granted" | "denied" | "restricted" | "prompt";
30
+
31
+ export interface PermissionEvent {
32
+ readonly event: "permission";
33
+ readonly state: CombinedPermission;
34
+ readonly microphone?: PermissionPart;
35
+ readonly speech?: PermissionPart;
36
+ readonly id?: string;
37
+ }
38
+
39
+ export type EngineState = "available" | "needsAssetInstall" | "unavailableOS" | "localeUnsupported" | "engineUnavailable";
40
+ export type AssetStatus = "installed" | "notInstalled" | "downloading" | "unsupported";
41
+
42
+ /** `adea-voice-helper` status: Apple's two engines for one locale. */
43
+ export interface AppleStatusEvent {
44
+ readonly event: "status";
45
+ readonly locale: string;
46
+ readonly analyzer: EngineState;
47
+ readonly legacy: EngineState;
48
+ readonly analyzerEquivalentLocale: string;
49
+ readonly recommendedEngine: "analyzer" | "legacy" | "none";
50
+ readonly assetStatus: AssetStatus;
51
+ readonly canInstall: boolean;
52
+ readonly id?: string;
53
+ }
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
+
72
+ /** `adea-tts-helper` status. */
73
+ export interface SynthesisStatusEvent {
74
+ readonly event: "status";
75
+ readonly engine: "audio.cpp";
76
+ readonly locale: string;
77
+ readonly modelPath: string;
78
+ readonly voice: string;
79
+ readonly ready: boolean;
80
+ readonly reason?: string;
81
+ readonly message?: string;
82
+ readonly id?: string;
83
+ }
84
+
85
+ export interface LocaleEvent {
86
+ readonly event: "locale";
87
+ readonly locale: string;
88
+ readonly status: AssetStatus;
89
+ readonly canInstall: boolean;
90
+ readonly id?: string;
91
+ }
92
+
93
+ export interface ListDoneEvent {
94
+ readonly event: "locales-done" | "voices-done";
95
+ readonly count: number;
96
+ readonly id?: string;
97
+ }
98
+
99
+ export interface VoiceEvent {
100
+ readonly event: "voice";
101
+ /** The voice identifier (not the request id). */
102
+ readonly id: string;
103
+ readonly requestId?: string;
104
+ readonly name: string;
105
+ readonly locale: string;
106
+ readonly quality: "default" | "enhanced" | "premium" | "unknown";
107
+ readonly gender: "male" | "female" | "unknown";
108
+ readonly source?: string;
109
+ }
110
+
111
+ export interface ListeningEvent {
112
+ readonly event: "listening";
113
+ readonly engine: string;
114
+ readonly locale: string;
115
+ readonly model?: string;
116
+ readonly id?: string;
117
+ }
118
+
119
+ export interface PartialEvent {
120
+ readonly event: "partial";
121
+ readonly text?: string;
122
+ readonly finalizedText: string;
123
+ readonly volatileText: string;
124
+ readonly sequence: number;
125
+ readonly id?: string;
126
+ }
127
+
128
+ export interface FinalEvent {
129
+ readonly event: "final";
130
+ readonly text: string;
131
+ readonly id?: string;
132
+ }
133
+
134
+ export interface ErrorEvent {
135
+ readonly event: "error";
136
+ readonly code: VoiceErrorCode;
137
+ readonly message?: string;
138
+ readonly id?: string;
139
+ }
140
+
141
+ export interface CancelledEvent {
142
+ readonly event: "cancelled";
143
+ readonly id?: string;
144
+ }
145
+
146
+ export interface IdleEvent {
147
+ readonly event: "idle";
148
+ readonly command: string;
149
+ readonly id?: string;
150
+ }
151
+
152
+ export interface AssetProgressEvent {
153
+ readonly event: "asset-progress";
154
+ readonly locale: string;
155
+ readonly fraction: number | null;
156
+ readonly id?: string;
157
+ }
158
+
159
+ export interface AssetInstalledEvent {
160
+ readonly event: "asset-installed";
161
+ readonly locale: string;
162
+ readonly id?: string;
163
+ }
164
+
165
+ export interface SpeechLifecycleEvent {
166
+ readonly event: "speech-started" | "speech-finished" | "speech-cancelled";
167
+ readonly id: string;
168
+ }
169
+
170
+ export interface SpeechErrorEvent {
171
+ readonly event: "speech-error";
172
+ readonly code: VoiceErrorCode;
173
+ readonly message?: string;
174
+ readonly id: string;
175
+ }
176
+
177
+ export interface SpeechStateEvent {
178
+ readonly event: "speech-state";
179
+ readonly state: "paused" | "resumed";
180
+ }
181
+
182
+ export interface SpeechInterruptedEvent {
183
+ readonly event: "speech-interrupted" | "speech-route-changed";
184
+ readonly reason?: string;
185
+ }
186
+
187
+ /** A second line the local-model helpers print after `version`. */
188
+ export interface HelperIdentityEvent {
189
+ readonly event: "helper";
190
+ readonly name: string;
191
+ readonly engine: string;
192
+ readonly library?: string;
193
+ }
194
+
195
+ export type WireEvent =
196
+ | VersionEvent
197
+ | HelperIdentityEvent
198
+ | PermissionEvent
199
+ | AppleStatusEvent
200
+ | TranscribeStatusEvent
201
+ | SynthesisStatusEvent
202
+ | LocaleEvent
203
+ | ListDoneEvent
204
+ | VoiceEvent
205
+ | ListeningEvent
206
+ | PartialEvent
207
+ | FinalEvent
208
+ | ErrorEvent
209
+ | CancelledEvent
210
+ | IdleEvent
211
+ | AssetProgressEvent
212
+ | AssetInstalledEvent
213
+ | SpeechLifecycleEvent
214
+ | SpeechErrorEvent
215
+ | SpeechStateEvent
216
+ | SpeechInterruptedEvent;
217
+
218
+ /** A command line. `cmd` is the helpers' key; `command` is sent too for the transcribe helper. */
219
+ export interface WireCommand {
220
+ readonly cmd: string;
221
+ readonly id?: string;
222
+ readonly [field: string]: unknown;
223
+ }
224
+
225
+ /**
226
+ * Parses one stdout line. Returns `undefined` for anything that is not a JSON object with a string
227
+ * `event` (a helper's stray diagnostic line must never crash a host). Error codes are normalised
228
+ * to the snake_case vocabulary; an unknown code becomes `failed`.
229
+ */
230
+ export function parseWireLine(line: string): WireEvent | undefined {
231
+ if (line.length === 0 || line.length > MAX_WIRE_LINE_BYTES) return undefined;
232
+ let value: unknown;
233
+ try {
234
+ value = JSON.parse(line);
235
+ } catch {
236
+ return undefined;
237
+ }
238
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return undefined;
239
+ const object = value as Record<string, unknown>;
240
+ if (typeof object.event !== "string") return undefined;
241
+ if (object.event === "error" || object.event === "speech-error") {
242
+ return { ...object, code: normalizeVoiceErrorCode(object.code) } as unknown as WireEvent;
243
+ }
244
+ return object as unknown as WireEvent;
245
+ }
246
+
247
+ /** Encodes one command line (no trailing newline). */
248
+ export function encodeWireCommand(command: WireCommand): string {
249
+ // The transcribe helper reads `command`; the others read `cmd`. Sending both is harmless.
250
+ return JSON.stringify({ ...command, command: command.cmd });
251
+ }
252
+
253
+ /** The request id an event answers, or `undefined` for an uncorrelated event. */
254
+ export function correlationId(event: WireEvent): string | undefined {
255
+ if (event.event === "voice") return event.requestId;
256
+ if ("id" in event && typeof event.id === "string") return event.id;
257
+ return undefined;
258
+ }
259
+
260
+ /** Whether a version handshake is one this SDK can talk to. */
261
+ export function isCompatibleHandshake(event: VersionEvent): boolean {
262
+ return event.wire === WIRE_VERSION && event.contractMajor === CONTRACT_MAJOR;
263
+ }