@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.
- package/README.md +51 -2
- package/dist/cli/helpers-cli.d.ts +2 -0
- package/dist/cli/helpers-cli.js +102 -0
- package/dist/contract/contract.d.ts +138 -0
- package/dist/contract/errors.d.ts +26 -0
- package/dist/contract/index.d.ts +9 -0
- package/dist/contract/index.js +54 -0
- package/dist/contract/session.d.ts +58 -0
- package/dist/contract/wire.d.ts +188 -0
- package/dist/desktop/desktop-voice.d.ts +152 -0
- package/dist/desktop/helper-lock.d.ts +83 -0
- package/dist/desktop/helper-process.d.ts +92 -0
- package/dist/desktop/index.d.ts +7 -0
- package/dist/desktop/index.js +1042 -0
- package/dist/index-9kerqn9r.js +150 -0
- package/dist/index-acm1yvvv.js +290 -0
- package/dist/index-r4hz8gk0.js +10 -0
- package/dist/index-rehs788p.js +42 -0
- package/dist/index-s270cw30.js +295 -0
- package/dist/index-tvz9s9nz.js +77 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +86 -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 +15 -0
- package/dist/web/index.js +1287 -0
- package/dist/web/stt/speech-recognition.d.ts +105 -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 +122 -0
- package/dist/web/turns.d.ts +101 -0
- package/package.json +68 -4
- package/src/cli/helpers-cli.ts +119 -0
- package/src/contract/contract.ts +365 -0
- package/src/contract/errors.ts +98 -0
- package/src/contract/index.ts +9 -0
- package/src/contract/session.ts +65 -0
- package/src/contract/wire.ts +263 -0
- package/src/desktop/desktop-voice.ts +933 -0
- package/src/desktop/helper-lock.ts +375 -0
- package/src/desktop/helper-process.ts +401 -0
- package/src/desktop/index.ts +16 -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 +15 -0
- package/src/web/stt/speech-recognition.ts +583 -0
- package/src/web/tts/phonon.ts +386 -0
- package/src/web/tts/player.ts +271 -0
- package/src/web/tts/system-voices.ts +401 -0
- package/src/web/turns.ts +224 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WEB_ROUTING_POLICY2
|
|
3
|
+
} from "./index-9kerqn9r.js";
|
|
4
|
+
import {
|
|
5
|
+
VoiceError2
|
|
6
|
+
} from "./index-tvz9s9nz.js";
|
|
7
|
+
|
|
8
|
+
// src/settings/settings.ts
|
|
9
|
+
var SETTINGS_SCHEMA_VERSION2 = 2;
|
|
10
|
+
var MIGRATABLE_VERSIONS = [1];
|
|
11
|
+
var DEFAULT_VOICE_SETTINGS2 = Object.freeze({
|
|
12
|
+
schemaVersion: SETTINGS_SCHEMA_VERSION2,
|
|
13
|
+
stt: Object.freeze({ networkConsent: false }),
|
|
14
|
+
tts: Object.freeze({ networkConsent: false }),
|
|
15
|
+
models: Object.freeze({ allowDownload: false, cache: true, folders: Object.freeze([]) }),
|
|
16
|
+
privacy: Object.freeze({ offlineOnly: false }),
|
|
17
|
+
dictation: Object.freeze({ autoSend: false })
|
|
18
|
+
});
|
|
19
|
+
function defaultSettings() {
|
|
20
|
+
return {
|
|
21
|
+
schemaVersion: DEFAULT_VOICE_SETTINGS2.schemaVersion,
|
|
22
|
+
stt: { ...DEFAULT_VOICE_SETTINGS2.stt },
|
|
23
|
+
tts: { ...DEFAULT_VOICE_SETTINGS2.tts },
|
|
24
|
+
models: { ...DEFAULT_VOICE_SETTINGS2.models, folders: [] },
|
|
25
|
+
privacy: { ...DEFAULT_VOICE_SETTINGS2.privacy },
|
|
26
|
+
dictation: { ...DEFAULT_VOICE_SETTINGS2.dictation }
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var MAX_LENGTH = { provider: 128, locale: 64, voice: 256, model: 256, folder: 1024 };
|
|
30
|
+
var MAX_FOLDERS = 16;
|
|
31
|
+
var RATE_RANGE = { min: 0.5, max: 2 };
|
|
32
|
+
var KNOWN_KEYS = {
|
|
33
|
+
root: ["schemaVersion", "stt", "tts", "models", "privacy", "dictation"],
|
|
34
|
+
stt: ["provider", "locale", "networkConsent", "model"],
|
|
35
|
+
tts: ["provider", "locale", "voice", "networkConsent", "rate"],
|
|
36
|
+
models: ["allowDownload", "cache", "folders"],
|
|
37
|
+
privacy: ["offlineOnly"],
|
|
38
|
+
dictation: ["autoSend"]
|
|
39
|
+
};
|
|
40
|
+
function readVoiceSettings2(raw) {
|
|
41
|
+
if (raw === null || raw === undefined || raw.trim() === "") {
|
|
42
|
+
return { settings: defaultSettings(), issues: [] };
|
|
43
|
+
}
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = JSON.parse(raw);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return {
|
|
49
|
+
settings: defaultSettings(),
|
|
50
|
+
issues: [`stored settings are not JSON: ${error instanceof Error ? error.message : String(error)}`]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return validateVoiceSettings2(parsed);
|
|
54
|
+
}
|
|
55
|
+
function validateVoiceSettings2(raw) {
|
|
56
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
|
|
57
|
+
return { settings: defaultSettings(), issues: ["settings must be an object"] };
|
|
58
|
+
}
|
|
59
|
+
const issues = [];
|
|
60
|
+
const object = raw;
|
|
61
|
+
const version = object.schemaVersion;
|
|
62
|
+
const migrating = MIGRATABLE_VERSIONS.includes(version);
|
|
63
|
+
if (version !== undefined && version !== SETTINGS_SCHEMA_VERSION2 && !migrating) {
|
|
64
|
+
issues.push(`schemaVersion ${String(version)} is not ${SETTINGS_SCHEMA_VERSION2}; using defaults`);
|
|
65
|
+
return { settings: defaultSettings(), issues };
|
|
66
|
+
}
|
|
67
|
+
unknownKeys(object, KNOWN_KEYS.root, "", issues);
|
|
68
|
+
const stt = section(object.stt, "stt", issues);
|
|
69
|
+
const tts = section(object.tts, "tts", issues);
|
|
70
|
+
const models = section(object.models, "models", issues);
|
|
71
|
+
const privacy = section(object.privacy, "privacy", issues);
|
|
72
|
+
const dictation = section(object.dictation, "dictation", issues);
|
|
73
|
+
unknownKeys(stt, KNOWN_KEYS.stt, "stt.", issues);
|
|
74
|
+
unknownKeys(tts, KNOWN_KEYS.tts, "tts.", issues);
|
|
75
|
+
unknownKeys(models, KNOWN_KEYS.models, "models.", issues);
|
|
76
|
+
unknownKeys(privacy, KNOWN_KEYS.privacy, "privacy.", issues);
|
|
77
|
+
unknownKeys(dictation, KNOWN_KEYS.dictation, "dictation.", issues);
|
|
78
|
+
const sttConsent = boolean(stt.networkConsent, "stt.networkConsent", issues, false);
|
|
79
|
+
const ttsConsent = boolean(tts.networkConsent, "tts.networkConsent", issues, false);
|
|
80
|
+
return {
|
|
81
|
+
settings: {
|
|
82
|
+
schemaVersion: SETTINGS_SCHEMA_VERSION2,
|
|
83
|
+
stt: {
|
|
84
|
+
networkConsent: sttConsent,
|
|
85
|
+
...optionalString(stt.provider, "stt.provider", issues, "provider", MAX_LENGTH.provider),
|
|
86
|
+
...optionalLocale(stt.locale, "stt.locale", issues),
|
|
87
|
+
...optionalString(stt.model, "stt.model", issues, "model", MAX_LENGTH.model)
|
|
88
|
+
},
|
|
89
|
+
tts: {
|
|
90
|
+
networkConsent: ttsConsent,
|
|
91
|
+
...optionalString(tts.provider, "tts.provider", issues, "provider", MAX_LENGTH.provider),
|
|
92
|
+
...optionalLocale(tts.locale, "tts.locale", issues),
|
|
93
|
+
...optionalString(tts.voice, "tts.voice", issues, "voice", MAX_LENGTH.voice),
|
|
94
|
+
...optionalRate(tts.rate, "tts.rate", issues)
|
|
95
|
+
},
|
|
96
|
+
models: {
|
|
97
|
+
allowDownload: boolean(models.allowDownload, "models.allowDownload", issues, false),
|
|
98
|
+
cache: boolean(models.cache, "models.cache", issues, true),
|
|
99
|
+
folders: folderList(models.folders, "models.folders", issues)
|
|
100
|
+
},
|
|
101
|
+
privacy: {
|
|
102
|
+
offlineOnly: boolean(privacy.offlineOnly, "privacy.offlineOnly", issues, false)
|
|
103
|
+
},
|
|
104
|
+
dictation: {
|
|
105
|
+
autoSend: boolean(dictation.autoSend, "dictation.autoSend", issues, false)
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
issues
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function serializeVoiceSettings2(settings) {
|
|
112
|
+
return JSON.stringify(settings);
|
|
113
|
+
}
|
|
114
|
+
function routingPolicyFor2(settings, baseOrOptions = {}) {
|
|
115
|
+
const base = isRoutingPolicy(baseOrOptions) ? baseOrOptions : baseOrOptions.base ?? WEB_ROUTING_POLICY2;
|
|
116
|
+
const overrides = { ...base.overrides };
|
|
117
|
+
if (settings.stt.provider)
|
|
118
|
+
overrides.speechToText = settings.stt.provider;
|
|
119
|
+
if (settings.tts.provider)
|
|
120
|
+
overrides.textToSpeech = settings.tts.provider;
|
|
121
|
+
return {
|
|
122
|
+
chains: { ...base.chains },
|
|
123
|
+
...Object.keys(overrides).length > 0 ? { overrides } : {},
|
|
124
|
+
allowsOptInModelInstallation: !settings.privacy.offlineOnly && (base.allowsOptInModelInstallation || settings.models.allowDownload)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function isRoutingPolicy(value) {
|
|
128
|
+
return "chains" in value;
|
|
129
|
+
}
|
|
130
|
+
function resolveLocale2(settings, kind, fallback) {
|
|
131
|
+
const chosen = kind === "speechToText" ? settings.stt.locale : settings.tts.locale;
|
|
132
|
+
return chosen ?? fallback;
|
|
133
|
+
}
|
|
134
|
+
function allowsNetworkSpeechToText2(settings) {
|
|
135
|
+
return !settings.privacy.offlineOnly && settings.stt.networkConsent;
|
|
136
|
+
}
|
|
137
|
+
function allowsNetworkSynthesis2(settings) {
|
|
138
|
+
return !settings.privacy.offlineOnly && settings.tts.networkConsent;
|
|
139
|
+
}
|
|
140
|
+
function allowsModelDownload2(settings) {
|
|
141
|
+
return !settings.privacy.offlineOnly && settings.models.allowDownload;
|
|
142
|
+
}
|
|
143
|
+
function updateVoiceSettings2(settings, patch) {
|
|
144
|
+
const merged = {
|
|
145
|
+
schemaVersion: SETTINGS_SCHEMA_VERSION2,
|
|
146
|
+
stt: { ...settings.stt, ...patch.stt },
|
|
147
|
+
tts: { ...settings.tts, ...patch.tts },
|
|
148
|
+
models: { ...settings.models, ...patch.models },
|
|
149
|
+
privacy: { ...settings.privacy, ...patch.privacy },
|
|
150
|
+
dictation: { ...settings.dictation, ...patch.dictation }
|
|
151
|
+
};
|
|
152
|
+
return validateVoiceSettings2(JSON.parse(JSON.stringify(merged))).settings;
|
|
153
|
+
}
|
|
154
|
+
var VOICE_SETTINGS_STORAGE_KEY2 = "adea:voice-settings:v2";
|
|
155
|
+
function createVoiceSettingsStore2(storage, options = {}) {
|
|
156
|
+
const key = options.key ?? VOICE_SETTINGS_STORAGE_KEY2;
|
|
157
|
+
const listeners = new Set;
|
|
158
|
+
let cached;
|
|
159
|
+
const load = () => {
|
|
160
|
+
if (cached)
|
|
161
|
+
return cached;
|
|
162
|
+
let raw = null;
|
|
163
|
+
try {
|
|
164
|
+
raw = storage?.getItem(key) ?? null;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
cached = { settings: defaultSettings(), issues: [`voice settings could not be read: ${String(error)}`] };
|
|
167
|
+
return cached;
|
|
168
|
+
}
|
|
169
|
+
cached = readVoiceSettings2(raw);
|
|
170
|
+
return cached;
|
|
171
|
+
};
|
|
172
|
+
const store = {
|
|
173
|
+
read: load,
|
|
174
|
+
write(settings) {
|
|
175
|
+
const validated = validateVoiceSettings2(JSON.parse(JSON.stringify(settings)));
|
|
176
|
+
cached = { settings: validated.settings, issues: [] };
|
|
177
|
+
try {
|
|
178
|
+
storage?.setItem(key, serializeVoiceSettings2(validated.settings));
|
|
179
|
+
} catch (error) {
|
|
180
|
+
options.onError?.(error);
|
|
181
|
+
}
|
|
182
|
+
for (const listener of listeners)
|
|
183
|
+
listener(validated.settings);
|
|
184
|
+
return validated.settings;
|
|
185
|
+
},
|
|
186
|
+
update(patch) {
|
|
187
|
+
return store.write(updateVoiceSettings2(load().settings, patch));
|
|
188
|
+
},
|
|
189
|
+
subscribe(listener) {
|
|
190
|
+
listeners.add(listener);
|
|
191
|
+
return () => listeners.delete(listener);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
return store;
|
|
195
|
+
}
|
|
196
|
+
function withLegacyDictationPreferences2(settings, legacy) {
|
|
197
|
+
return updateVoiceSettings2(settings, {
|
|
198
|
+
stt: { locale: settings.stt.locale ?? (legacy.locale?.trim() || undefined) },
|
|
199
|
+
dictation: { autoSend: settings.dictation.autoSend || legacy.autoSend === true }
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function assertUsableSettings2(result) {
|
|
203
|
+
if (result.issues.length > 0) {
|
|
204
|
+
throw new VoiceError2("failed", `voice settings: ${result.issues.join("; ")}`);
|
|
205
|
+
}
|
|
206
|
+
return result.settings;
|
|
207
|
+
}
|
|
208
|
+
function section(value, name, issues) {
|
|
209
|
+
if (value === undefined)
|
|
210
|
+
return {};
|
|
211
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
212
|
+
issues.push(`${name} must be an object; using its defaults`);
|
|
213
|
+
return {};
|
|
214
|
+
}
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
function boolean(value, path, issues, fallback) {
|
|
218
|
+
if (value === undefined)
|
|
219
|
+
return fallback;
|
|
220
|
+
if (typeof value !== "boolean") {
|
|
221
|
+
issues.push(`${path} must be a boolean; using ${fallback}`);
|
|
222
|
+
return fallback;
|
|
223
|
+
}
|
|
224
|
+
return value;
|
|
225
|
+
}
|
|
226
|
+
function unknownKeys(object, known, prefix, issues) {
|
|
227
|
+
for (const key of Object.keys(object)) {
|
|
228
|
+
if (!known.includes(key))
|
|
229
|
+
issues.push(`${prefix}${key} is not a known setting; ignoring it`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function optionalString(value, path, issues, key, maxLength) {
|
|
233
|
+
if (value === undefined)
|
|
234
|
+
return {};
|
|
235
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
236
|
+
issues.push(`${path} must be a non-empty string; ignoring it`);
|
|
237
|
+
return {};
|
|
238
|
+
}
|
|
239
|
+
const trimmed = value.trim();
|
|
240
|
+
if (trimmed.length > maxLength) {
|
|
241
|
+
issues.push(`${path} is longer than ${maxLength} characters; ignoring it`);
|
|
242
|
+
return {};
|
|
243
|
+
}
|
|
244
|
+
return { [key]: trimmed };
|
|
245
|
+
}
|
|
246
|
+
function optionalLocale(value, path, issues) {
|
|
247
|
+
const read = optionalString(value, path, issues, "locale", MAX_LENGTH.locale);
|
|
248
|
+
if (read.locale === undefined)
|
|
249
|
+
return {};
|
|
250
|
+
try {
|
|
251
|
+
const [canonical] = Intl.getCanonicalLocales(read.locale);
|
|
252
|
+
if (canonical !== undefined)
|
|
253
|
+
return { locale: canonical };
|
|
254
|
+
} catch {}
|
|
255
|
+
issues.push(`${path} "${read.locale}" is not a valid BCP-47 language tag; ignoring it`);
|
|
256
|
+
return {};
|
|
257
|
+
}
|
|
258
|
+
function optionalRate(value, path, issues) {
|
|
259
|
+
if (value === undefined)
|
|
260
|
+
return {};
|
|
261
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < RATE_RANGE.min || value > RATE_RANGE.max) {
|
|
262
|
+
issues.push(`${path} must be a number from ${RATE_RANGE.min} to ${RATE_RANGE.max}; ignoring it`);
|
|
263
|
+
return {};
|
|
264
|
+
}
|
|
265
|
+
return { rate: value };
|
|
266
|
+
}
|
|
267
|
+
function folderList(value, path, issues) {
|
|
268
|
+
if (value === undefined)
|
|
269
|
+
return [];
|
|
270
|
+
if (!Array.isArray(value)) {
|
|
271
|
+
issues.push(`${path} must be a list of folders; ignoring it`);
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
const folders = [];
|
|
275
|
+
for (const entry of value) {
|
|
276
|
+
if (typeof entry !== "string" || entry.trim() === "" || entry.length > MAX_LENGTH.folder) {
|
|
277
|
+
issues.push(`${path} has an entry that is not a folder path; ignoring it`);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const trimmed = entry.trim();
|
|
281
|
+
if (!/^(\/|[A-Za-z]:[\\/]|\\\\)/.test(trimmed) || trimmed.includes("\x00")) {
|
|
282
|
+
issues.push(`${path} "${trimmed}" is not an absolute path; ignoring it`);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (!folders.includes(trimmed))
|
|
286
|
+
folders.push(trimmed);
|
|
287
|
+
}
|
|
288
|
+
if (folders.length > MAX_FOLDERS) {
|
|
289
|
+
issues.push(`${path} keeps the first ${MAX_FOLDERS} folders`);
|
|
290
|
+
return folders.slice(0, MAX_FOLDERS);
|
|
291
|
+
}
|
|
292
|
+
return folders;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export { SETTINGS_SCHEMA_VERSION2, DEFAULT_VOICE_SETTINGS2, readVoiceSettings2, validateVoiceSettings2, serializeVoiceSettings2, routingPolicyFor2, resolveLocale2, allowsNetworkSpeechToText2, allowsNetworkSynthesis2, allowsModelDownload2, updateVoiceSettings2, VOICE_SETTINGS_STORAGE_KEY2, createVoiceSettingsStore2, withLegacyDictationPreferences2, assertUsableSettings2 };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// src/contract/errors.ts
|
|
2
|
+
var VOICE_ERROR_CODES2 = [
|
|
3
|
+
"denied",
|
|
4
|
+
"restricted",
|
|
5
|
+
"unavailable",
|
|
6
|
+
"no_speech",
|
|
7
|
+
"language_unsupported",
|
|
8
|
+
"assets_missing",
|
|
9
|
+
"assets_install_failed",
|
|
10
|
+
"assets_locale_limit",
|
|
11
|
+
"insufficient_storage",
|
|
12
|
+
"audio_overrun",
|
|
13
|
+
"busy",
|
|
14
|
+
"cancelled",
|
|
15
|
+
"bad_request",
|
|
16
|
+
"failed"
|
|
17
|
+
];
|
|
18
|
+
var WIRE_CODES = new Set(VOICE_ERROR_CODES2);
|
|
19
|
+
var LEGACY_CODES = {
|
|
20
|
+
noSpeech: "no_speech",
|
|
21
|
+
languageUnsupported: "language_unsupported",
|
|
22
|
+
assetsMissing: "assets_missing",
|
|
23
|
+
assetsInstallFailed: "assets_install_failed",
|
|
24
|
+
assetsLocaleLimit: "assets_locale_limit",
|
|
25
|
+
insufficientStorage: "insufficient_storage",
|
|
26
|
+
audioOverrun: "audio_overrun",
|
|
27
|
+
badRequest: "bad_request"
|
|
28
|
+
};
|
|
29
|
+
function knownVoiceErrorCode(value) {
|
|
30
|
+
if (typeof value !== "string")
|
|
31
|
+
return;
|
|
32
|
+
if (WIRE_CODES.has(value))
|
|
33
|
+
return value;
|
|
34
|
+
return Object.prototype.hasOwnProperty.call(LEGACY_CODES, value) ? LEGACY_CODES[value] : undefined;
|
|
35
|
+
}
|
|
36
|
+
function normalizeVoiceErrorCode2(value) {
|
|
37
|
+
return knownVoiceErrorCode(value) ?? "failed";
|
|
38
|
+
}
|
|
39
|
+
var DEFAULT_MESSAGES = {
|
|
40
|
+
denied: "Microphone or speech-recognition permission was denied.",
|
|
41
|
+
restricted: "Microphone or speech-recognition permission is restricted.",
|
|
42
|
+
unavailable: "This device or browser cannot run the selected speech engine.",
|
|
43
|
+
no_speech: "No speech was recognized before the session ended.",
|
|
44
|
+
language_unsupported: "The selected language has no on-device speech model.",
|
|
45
|
+
assets_missing: "The speech model for this language is not installed; it must be downloaded first.",
|
|
46
|
+
assets_install_failed: "Installing the speech model assets failed.",
|
|
47
|
+
assets_locale_limit: "Too many languages are reserved for on-device speech; release one before adding another.",
|
|
48
|
+
insufficient_storage: "There is not enough storage to install the speech model assets.",
|
|
49
|
+
audio_overrun: "Audio arrived faster than the speech engine could consume it.",
|
|
50
|
+
busy: "A speech session is already running.",
|
|
51
|
+
cancelled: "The operation was cancelled.",
|
|
52
|
+
bad_request: "The request was malformed or used the API incorrectly.",
|
|
53
|
+
failed: "The speech engine reported an unexpected failure."
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
class VoiceError2 extends Error {
|
|
57
|
+
code;
|
|
58
|
+
constructor(code, message = DEFAULT_MESSAGES[code]) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = "VoiceError";
|
|
61
|
+
this.code = code;
|
|
62
|
+
}
|
|
63
|
+
static wrapping(error, fallback = "failed") {
|
|
64
|
+
if (error instanceof VoiceError2)
|
|
65
|
+
return error;
|
|
66
|
+
if (error instanceof DOMException && error.name === "AbortError")
|
|
67
|
+
return new VoiceError2("cancelled");
|
|
68
|
+
if (error instanceof Error && error.name === "AbortError")
|
|
69
|
+
return new VoiceError2("cancelled");
|
|
70
|
+
const shaped = error !== null && typeof error === "object" ? error : undefined;
|
|
71
|
+
const bridged = knownVoiceErrorCode(shaped?.code);
|
|
72
|
+
const message = typeof shaped?.message === "string" ? shaped.message : String(error);
|
|
73
|
+
return new VoiceError2(bridged ?? fallback, message);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { VOICE_ERROR_CODES2, normalizeVoiceErrorCode2, VoiceError2 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@adea-ai/voice`: the root entry re-exports the platform-neutral parts (contract and settings).
|
|
3
|
+
* Platform code lives on its own subpath so a browser bundle never pulls in `node:child_process`
|
|
4
|
+
* and a desktop shell never pulls in Web Audio: `@adea-ai/voice/web`, `@adea-ai/voice/desktop`.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./contract/index";
|
|
7
|
+
export * from "./settings/index";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ENDPOINTING2
|
|
3
|
+
} from "./index-r4hz8gk0.js";
|
|
4
|
+
import {
|
|
5
|
+
SETTINGS_SCHEMA_VERSION2,
|
|
6
|
+
DEFAULT_VOICE_SETTINGS2,
|
|
7
|
+
readVoiceSettings2,
|
|
8
|
+
validateVoiceSettings2,
|
|
9
|
+
serializeVoiceSettings2,
|
|
10
|
+
routingPolicyFor2,
|
|
11
|
+
resolveLocale2,
|
|
12
|
+
allowsNetworkSpeechToText2,
|
|
13
|
+
allowsNetworkSynthesis2,
|
|
14
|
+
allowsModelDownload2,
|
|
15
|
+
updateVoiceSettings2,
|
|
16
|
+
VOICE_SETTINGS_STORAGE_KEY2,
|
|
17
|
+
createVoiceSettingsStore2,
|
|
18
|
+
withLegacyDictationPreferences2,
|
|
19
|
+
assertUsableSettings2
|
|
20
|
+
} from "./index-s270cw30.js";
|
|
21
|
+
import {
|
|
22
|
+
VOICE_CONTRACT2,
|
|
23
|
+
isCompatibleContract2,
|
|
24
|
+
VOICE_CAPABILITY_BITS2,
|
|
25
|
+
capabilitiesToMask2,
|
|
26
|
+
capabilitiesFromMask2,
|
|
27
|
+
AVAILABLE2,
|
|
28
|
+
unavailable2,
|
|
29
|
+
isAvailable2,
|
|
30
|
+
requiresModelInstallation2,
|
|
31
|
+
WEB_ROUTING_POLICY2,
|
|
32
|
+
route2
|
|
33
|
+
} from "./index-9kerqn9r.js";
|
|
34
|
+
import {
|
|
35
|
+
WIRE_VERSION2,
|
|
36
|
+
CONTRACT_MAJOR2,
|
|
37
|
+
MAX_WIRE_LINE_BYTES2,
|
|
38
|
+
parseWireLine2,
|
|
39
|
+
encodeWireCommand2,
|
|
40
|
+
correlationId2,
|
|
41
|
+
isCompatibleHandshake2
|
|
42
|
+
} from "./index-rehs788p.js";
|
|
43
|
+
import {
|
|
44
|
+
VOICE_ERROR_CODES2,
|
|
45
|
+
normalizeVoiceErrorCode2,
|
|
46
|
+
VoiceError2
|
|
47
|
+
} from "./index-tvz9s9nz.js";
|
|
48
|
+
export {
|
|
49
|
+
AVAILABLE2 as AVAILABLE,
|
|
50
|
+
CONTRACT_MAJOR2 as CONTRACT_MAJOR,
|
|
51
|
+
DEFAULT_ENDPOINTING2 as DEFAULT_ENDPOINTING,
|
|
52
|
+
DEFAULT_VOICE_SETTINGS2 as DEFAULT_VOICE_SETTINGS,
|
|
53
|
+
MAX_WIRE_LINE_BYTES2 as MAX_WIRE_LINE_BYTES,
|
|
54
|
+
SETTINGS_SCHEMA_VERSION2 as SETTINGS_SCHEMA_VERSION,
|
|
55
|
+
VOICE_CAPABILITY_BITS2 as VOICE_CAPABILITY_BITS,
|
|
56
|
+
VOICE_CONTRACT2 as VOICE_CONTRACT,
|
|
57
|
+
VOICE_ERROR_CODES2 as VOICE_ERROR_CODES,
|
|
58
|
+
VOICE_SETTINGS_STORAGE_KEY2 as VOICE_SETTINGS_STORAGE_KEY,
|
|
59
|
+
VoiceError2 as VoiceError,
|
|
60
|
+
WEB_ROUTING_POLICY2 as WEB_ROUTING_POLICY,
|
|
61
|
+
WIRE_VERSION2 as WIRE_VERSION,
|
|
62
|
+
allowsModelDownload2 as allowsModelDownload,
|
|
63
|
+
allowsNetworkSpeechToText2 as allowsNetworkSpeechToText,
|
|
64
|
+
allowsNetworkSynthesis2 as allowsNetworkSynthesis,
|
|
65
|
+
assertUsableSettings2 as assertUsableSettings,
|
|
66
|
+
capabilitiesFromMask2 as capabilitiesFromMask,
|
|
67
|
+
capabilitiesToMask2 as capabilitiesToMask,
|
|
68
|
+
correlationId2 as correlationId,
|
|
69
|
+
createVoiceSettingsStore2 as createVoiceSettingsStore,
|
|
70
|
+
encodeWireCommand2 as encodeWireCommand,
|
|
71
|
+
isAvailable2 as isAvailable,
|
|
72
|
+
isCompatibleContract2 as isCompatibleContract,
|
|
73
|
+
isCompatibleHandshake2 as isCompatibleHandshake,
|
|
74
|
+
normalizeVoiceErrorCode2 as normalizeVoiceErrorCode,
|
|
75
|
+
parseWireLine2 as parseWireLine,
|
|
76
|
+
readVoiceSettings2 as readVoiceSettings,
|
|
77
|
+
requiresModelInstallation2 as requiresModelInstallation,
|
|
78
|
+
resolveLocale2 as resolveLocale,
|
|
79
|
+
route2 as route,
|
|
80
|
+
routingPolicyFor2 as routingPolicyFor,
|
|
81
|
+
serializeVoiceSettings2 as serializeVoiceSettings,
|
|
82
|
+
unavailable2 as unavailable,
|
|
83
|
+
updateVoiceSettings2 as updateVoiceSettings,
|
|
84
|
+
validateVoiceSettings2 as validateVoiceSettings,
|
|
85
|
+
withLegacyDictationPreferences2 as withLegacyDictationPreferences
|
|
86
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SETTINGS_SCHEMA_VERSION2,
|
|
3
|
+
DEFAULT_VOICE_SETTINGS2,
|
|
4
|
+
readVoiceSettings2,
|
|
5
|
+
validateVoiceSettings2,
|
|
6
|
+
serializeVoiceSettings2,
|
|
7
|
+
routingPolicyFor2,
|
|
8
|
+
resolveLocale2,
|
|
9
|
+
allowsNetworkSpeechToText2,
|
|
10
|
+
allowsNetworkSynthesis2,
|
|
11
|
+
allowsModelDownload2,
|
|
12
|
+
updateVoiceSettings2,
|
|
13
|
+
VOICE_SETTINGS_STORAGE_KEY2,
|
|
14
|
+
createVoiceSettingsStore2,
|
|
15
|
+
withLegacyDictationPreferences2,
|
|
16
|
+
assertUsableSettings2
|
|
17
|
+
} from "../index-s270cw30.js";
|
|
18
|
+
export {
|
|
19
|
+
DEFAULT_VOICE_SETTINGS2 as DEFAULT_VOICE_SETTINGS,
|
|
20
|
+
SETTINGS_SCHEMA_VERSION2 as SETTINGS_SCHEMA_VERSION,
|
|
21
|
+
VOICE_SETTINGS_STORAGE_KEY2 as VOICE_SETTINGS_STORAGE_KEY,
|
|
22
|
+
allowsModelDownload2 as allowsModelDownload,
|
|
23
|
+
allowsNetworkSpeechToText2 as allowsNetworkSpeechToText,
|
|
24
|
+
allowsNetworkSynthesis2 as allowsNetworkSynthesis,
|
|
25
|
+
assertUsableSettings2 as assertUsableSettings,
|
|
26
|
+
createVoiceSettingsStore2 as createVoiceSettingsStore,
|
|
27
|
+
readVoiceSettings2 as readVoiceSettings,
|
|
28
|
+
resolveLocale2 as resolveLocale,
|
|
29
|
+
routingPolicyFor2 as routingPolicyFor,
|
|
30
|
+
serializeVoiceSettings2 as serializeVoiceSettings,
|
|
31
|
+
updateVoiceSettings2 as updateVoiceSettings,
|
|
32
|
+
validateVoiceSettings2 as validateVoiceSettings,
|
|
33
|
+
withLegacyDictationPreferences2 as withLegacyDictationPreferences
|
|
34
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The unified Voice settings (#32), one model for web, desktop and mobile.
|
|
3
|
+
*
|
|
4
|
+
* Settings are the only place a host stores what a person chose: which provider serves each kind,
|
|
5
|
+
* the language, the model or voice, the consents (a model download, a network speech service), the
|
|
6
|
+
* offline-only switch, the folders of models they brought themselves, and whether a dictation is
|
|
7
|
+
* sent as soon as it finishes. Everything defaults to the conservative answer: offline only, no
|
|
8
|
+
* download, no network, no provider override.
|
|
9
|
+
*
|
|
10
|
+
* Settings are **per device**: a model folder is an absolute path on one machine, and a provider
|
|
11
|
+
* available on a Mac means nothing on a phone. Persist them in device-local storage
|
|
12
|
+
* (`createVoiceSettingsStore`), never in a synced profile.
|
|
13
|
+
*
|
|
14
|
+
* The module is pure: it validates and serialises a plain object, derives the routing policy, and
|
|
15
|
+
* never touches storage. A host persists `serializeVoiceSettings()` and reads it back through
|
|
16
|
+
* `readVoiceSettings()`, which reports what it had to ignore instead of silently keeping a value
|
|
17
|
+
* it did not understand.
|
|
18
|
+
*/
|
|
19
|
+
import { type VoiceProviderKind, type VoiceRoutingPolicy } from "../contract/contract";
|
|
20
|
+
export declare const SETTINGS_SCHEMA_VERSION = 2;
|
|
21
|
+
export interface SpeechToTextSettings {
|
|
22
|
+
/** An explicit provider id, or undefined to follow the routing chain. */
|
|
23
|
+
readonly provider?: string;
|
|
24
|
+
/** A BCP-47 tag the person chose, or undefined for the browser's language. */
|
|
25
|
+
readonly locale?: string;
|
|
26
|
+
/** Whether the host may send audio to the browser's speech service. Default false. */
|
|
27
|
+
readonly networkConsent: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* A model or engine variant within the provider (`analyzer`/`legacy` for Apple, a model id for
|
|
30
|
+
* transcribe.cpp), or undefined for the provider's own choice.
|
|
31
|
+
*/
|
|
32
|
+
readonly model?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface TextToSpeechSettings {
|
|
35
|
+
readonly provider?: string;
|
|
36
|
+
readonly locale?: string;
|
|
37
|
+
readonly voice?: string;
|
|
38
|
+
/** Whether the host may use a remote platform voice. Default false. */
|
|
39
|
+
readonly networkConsent: boolean;
|
|
40
|
+
/** Speaking rate, 0.5 (slow) to 2 (fast); undefined is the voice's natural rate. */
|
|
41
|
+
readonly rate?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface ModelSettings {
|
|
44
|
+
/** A standing permission to install models the person has already agreed to. Default false. */
|
|
45
|
+
readonly allowDownload: boolean;
|
|
46
|
+
/** Keep model files in the browser cache. Default true. */
|
|
47
|
+
readonly cache: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Folders of models the person brought (BYOM), as absolute paths on this device. Models are
|
|
50
|
+
* read in place, never moved or copied, and removing a folder here never deletes a file.
|
|
51
|
+
*/
|
|
52
|
+
readonly folders: readonly string[];
|
|
53
|
+
}
|
|
54
|
+
export interface PrivacySettings {
|
|
55
|
+
/**
|
|
56
|
+
* A hard switch: no network speech service and no model download start, whatever the consents
|
|
57
|
+
* say. Default false, because the consents themselves already default to "no": this is for a
|
|
58
|
+
* person who wants a guarantee that survives a later consent click.
|
|
59
|
+
*/
|
|
60
|
+
readonly offlineOnly: boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface DictationSettings {
|
|
63
|
+
/** Send the message as soon as a dictation finishes. Default false. */
|
|
64
|
+
readonly autoSend: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface VoiceSettings {
|
|
67
|
+
readonly schemaVersion: number;
|
|
68
|
+
readonly stt: SpeechToTextSettings;
|
|
69
|
+
readonly tts: TextToSpeechSettings;
|
|
70
|
+
readonly models: ModelSettings;
|
|
71
|
+
readonly privacy: PrivacySettings;
|
|
72
|
+
readonly dictation: DictationSettings;
|
|
73
|
+
}
|
|
74
|
+
/** The defaults, deep-frozen. Functions here hand out copies, so a caller can never mutate them. */
|
|
75
|
+
export declare const DEFAULT_VOICE_SETTINGS: VoiceSettings;
|
|
76
|
+
export interface ReadSettingsResult {
|
|
77
|
+
readonly settings: VoiceSettings;
|
|
78
|
+
/** What was rejected or ignored, for a settings screen to show. Empty means a clean read. */
|
|
79
|
+
readonly issues: readonly string[];
|
|
80
|
+
}
|
|
81
|
+
/** Parses stored settings. A missing value is the default; anything malformed is reported. */
|
|
82
|
+
export declare function readVoiceSettings(raw: string | null | undefined): ReadSettingsResult;
|
|
83
|
+
/** Validates a value (from storage or a settings form) field by field. */
|
|
84
|
+
export declare function validateVoiceSettings(raw: unknown): ReadSettingsResult;
|
|
85
|
+
export declare function serializeVoiceSettings(settings: VoiceSettings): string;
|
|
86
|
+
/**
|
|
87
|
+
* The routing policy these settings imply. An explicit provider becomes an override (the caller
|
|
88
|
+
* gets that provider's truth, including "unavailable"); `allowDownload` is the only thing that
|
|
89
|
+
* opens the install path. A network consent does **not** add the service recognizer to a chain:
|
|
90
|
+
* chains stay local, and the host selects a network provider itself.
|
|
91
|
+
*/
|
|
92
|
+
export interface RoutingPolicyOptions {
|
|
93
|
+
/**
|
|
94
|
+
* The platform's routing table the settings apply to. Default `WEB_ROUTING_POLICY`; a desktop or
|
|
95
|
+
* Capacitor host passes its own table so the person's choices layer over the right chains.
|
|
96
|
+
*/
|
|
97
|
+
readonly base?: VoiceRoutingPolicy;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The routing policy these settings imply, layered over `base` (by default the web table). An
|
|
101
|
+
* explicit provider becomes an override (the caller gets that provider's truth, including
|
|
102
|
+
* "unavailable") and wins over an override already in `base`; `allowDownload` is the only thing
|
|
103
|
+
* that opens the install path. A network consent does **not** add the service recognizer to a
|
|
104
|
+
* chain: chains stay local, and the host selects a network provider itself.
|
|
105
|
+
*
|
|
106
|
+
* `base` may be passed directly (`routingPolicyFor(settings, desktopPolicy)`) or as `{ base }`.
|
|
107
|
+
*/
|
|
108
|
+
export declare function routingPolicyFor(settings: VoiceSettings, baseOrOptions?: VoiceRoutingPolicy | RoutingPolicyOptions): VoiceRoutingPolicy;
|
|
109
|
+
/** The locale to probe and start sessions with: the person's choice, else the browser's. */
|
|
110
|
+
export declare function resolveLocale(settings: VoiceSettings, kind: VoiceProviderKind, fallback: string): string;
|
|
111
|
+
/** Whether the host may construct a session with the service provider. */
|
|
112
|
+
export declare function allowsNetworkSpeechToText(settings: VoiceSettings): boolean;
|
|
113
|
+
/** Whether the host may pick a remote platform voice. */
|
|
114
|
+
export declare function allowsNetworkSynthesis(settings: VoiceSettings): boolean;
|
|
115
|
+
/** Whether a model download may start (the person allowed it and is not offline-only). */
|
|
116
|
+
export declare function allowsModelDownload(settings: VoiceSettings): boolean;
|
|
117
|
+
/** A changed copy: `update(settings, { stt: { locale: "es-419" } })`. Sections merge shallowly. */
|
|
118
|
+
export declare function updateVoiceSettings(settings: VoiceSettings, patch: VoiceSettingsPatch): VoiceSettings;
|
|
119
|
+
type Writable<T> = {
|
|
120
|
+
-readonly [K in keyof T]?: T[K] | undefined;
|
|
121
|
+
};
|
|
122
|
+
export interface VoiceSettingsPatch {
|
|
123
|
+
readonly stt?: Writable<SpeechToTextSettings>;
|
|
124
|
+
readonly tts?: Writable<TextToSpeechSettings>;
|
|
125
|
+
readonly models?: Writable<ModelSettings>;
|
|
126
|
+
readonly privacy?: Writable<PrivacySettings>;
|
|
127
|
+
readonly dictation?: Writable<DictationSettings>;
|
|
128
|
+
}
|
|
129
|
+
/** The subset of `Storage` (localStorage, a desktop preferences file) the store needs. */
|
|
130
|
+
export interface VoiceSettingsStorage {
|
|
131
|
+
getItem(key: string): string | null;
|
|
132
|
+
setItem(key: string, value: string): void;
|
|
133
|
+
}
|
|
134
|
+
export declare const VOICE_SETTINGS_STORAGE_KEY = "adea:voice-settings:v2";
|
|
135
|
+
export interface VoiceSettingsStore {
|
|
136
|
+
/** The current settings and what the last read had to drop. */
|
|
137
|
+
read(): ReadSettingsResult;
|
|
138
|
+
/** Validates and persists; returns what was stored. */
|
|
139
|
+
write(settings: VoiceSettings): VoiceSettings;
|
|
140
|
+
update(patch: VoiceSettingsPatch): VoiceSettings;
|
|
141
|
+
/** Called after every write from this store. Returns an unsubscribe. */
|
|
142
|
+
subscribe(listener: (settings: VoiceSettings) => void): () => void;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* A per-device settings store over any `getItem`/`setItem` storage. Reads never throw (a broken
|
|
146
|
+
* or blocked storage reads as defaults with an issue); writes that fail report through `onError`
|
|
147
|
+
* and keep the in-memory value, so the UI stays consistent for this session.
|
|
148
|
+
*/
|
|
149
|
+
export declare function createVoiceSettingsStore(storage: VoiceSettingsStorage | undefined, options?: {
|
|
150
|
+
readonly key?: string;
|
|
151
|
+
readonly onError?: (error: unknown) => void;
|
|
152
|
+
}): VoiceSettingsStore;
|
|
153
|
+
/**
|
|
154
|
+
* Folds an app's pre-Voice dictation preferences (a dictation language, an auto-send switch) into
|
|
155
|
+
* fresh settings, once: a value already in `settings` wins.
|
|
156
|
+
*/
|
|
157
|
+
export declare function withLegacyDictationPreferences(settings: VoiceSettings, legacy: {
|
|
158
|
+
readonly locale?: string | undefined;
|
|
159
|
+
readonly autoSend?: boolean | undefined;
|
|
160
|
+
}): VoiceSettings;
|
|
161
|
+
/** A settings file that cannot be used at all, rather than one field being dropped. */
|
|
162
|
+
export declare function assertUsableSettings(result: ReadSettingsResult): VoiceSettings;
|
|
163
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@adea-ai/voice/web`: the browser providers. Every browser global is injectable, so the policy,
|
|
3
|
+
* routing and session lifecycles run under `bun test` with no browser at all.
|
|
4
|
+
*
|
|
5
|
+
* - on-device dictation with an explicit local/network policy (`browserRecognitionLocal`,
|
|
6
|
+
* `browserRecognitionService`);
|
|
7
|
+
* - Phonon TTS on the visitor's device (`PhononProvider`), English only;
|
|
8
|
+
* - platform voices as the multilingual fallback (`SystemVoiceProvider`);
|
|
9
|
+
* - the engine-agnostic turn manager (`VoiceTurnManager`).
|
|
10
|
+
*/
|
|
11
|
+
export * from "./stt/speech-recognition";
|
|
12
|
+
export * from "./tts/phonon";
|
|
13
|
+
export * from "./tts/player";
|
|
14
|
+
export * from "./tts/system-voices";
|
|
15
|
+
export * from "./turns";
|