@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
package/README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@adea-ai/voice`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The one TypeScript SDK every Adea app uses for speech. Apps render; this package owns the protocol
|
|
4
|
+
parsing, error vocabulary, routing, fallback and privacy rules, so no app re-implements them.
|
|
5
|
+
|
|
6
|
+
| Entry | Runs in | What it is |
|
|
7
|
+
|---|---|---|
|
|
8
|
+
| `@adea-ai/voice/contract` | anywhere | Provider descriptors, typed availability and routing (#19), the snake_case `VoiceErrorCode` set every helper, plugin and browser provider shares, the dictation session shape, and the desktop helpers' JSON-lines wire types |
|
|
9
|
+
| `@adea-ai/voice/settings` | anywhere | The unified, versioned, per-device Voice settings (#32): provider/model/voice/locale per kind, consents, offline-only, BYOM folders, dictation auto-send, and a store over any `getItem`/`setItem` storage |
|
|
10
|
+
| `@adea-ai/voice/desktop` | Bun/Node (desktop shell) | `createDesktopVoice()`: the client for the pinned `adea-voice-helper`, `adea-transcribe-helper` and `adea-tts-helper`, plus the helper lock (`stageVoiceHelpers`, `verifyStagedVoiceHelpers`) |
|
|
11
|
+
| `@adea-ai/voice/web` | browser | On-device browser dictation with an explicit network policy, Phonon TTS, platform voices, and the turn manager |
|
|
12
|
+
|
|
13
|
+
The root entry re-exports `contract` and `settings`. Browser entries never import `node:` modules.
|
|
14
|
+
|
|
15
|
+
## Desktop
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createDesktopVoice } from "@adea-ai/voice/desktop";
|
|
19
|
+
import { createVoiceSettingsStore } from "@adea-ai/voice/settings";
|
|
20
|
+
|
|
21
|
+
const voice = createDesktopVoice({ helpers: { voice: "/path/to/adea-voice-helper" } });
|
|
22
|
+
const { settings } = createVoiceSettingsStore(localStorage).read();
|
|
23
|
+
|
|
24
|
+
const capabilities = await voice.capabilities(settings); // routing decisions + reasons
|
|
25
|
+
const dictation = await voice.listen({ settings, onPartial: (p) => render(p.text) });
|
|
26
|
+
const text = await dictation.result; // or dictation.cancel()
|
|
27
|
+
|
|
28
|
+
const speech = await voice.speak({ settings, text: "Hola", locale: "es-419" });
|
|
29
|
+
await speech.done; // "finished" | "cancelled"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Guarantees: a helper missing from the build is `providerNotRegistered`, never a substitute; a helper
|
|
33
|
+
on another wire/contract major is refused; one dictation at a time (`busy`); every dictation ends in
|
|
34
|
+
exactly one terminal event even when a helper crashes or stops answering; nothing goes to the
|
|
35
|
+
network and nothing downloads unless a person starts `installAssets`.
|
|
36
|
+
|
|
37
|
+
## Pinning the helpers in an app
|
|
38
|
+
|
|
39
|
+
Each Voice release publishes the signed macOS helpers as `.tar.gz` artifacts with their sha256 at
|
|
40
|
+
`https://adea.dev/releases/voice/<helper>/<version>/`, and the matching lock at
|
|
41
|
+
`https://adea.dev/releases/voice/voice-helpers-<version>.lock.json`. An app commits that lock and:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
adea-voice-helpers stage --lock voice-helpers.lock.json --out build/voice-helpers # build
|
|
45
|
+
adea-voice-helpers verify --lock voice-helpers.lock.json --dir <app>/voice-helpers # release gate
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`stage` fails on a missing artifact or any digest mismatch and leaves nothing half-staged; `verify`
|
|
49
|
+
fails the release unless the packaged helpers are exactly the pinned ones (a `--local` developer
|
|
50
|
+
staging is refused).
|
|
51
|
+
|
|
52
|
+
Build and test: `bun install && bun test && bunx tsc --noEmit && bun run build`.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import {
|
|
3
|
+
HELPER_NAMES2,
|
|
4
|
+
HELPER_TARGETS2,
|
|
5
|
+
HelperLockError2,
|
|
6
|
+
validateHelperLock2,
|
|
7
|
+
readHelperLock2,
|
|
8
|
+
helperArtifactUrl2,
|
|
9
|
+
currentHelperTarget2,
|
|
10
|
+
stageVoiceHelpers2,
|
|
11
|
+
verifyStagedVoiceHelpers2
|
|
12
|
+
} from "../index-acm1yvvv.js";
|
|
13
|
+
|
|
14
|
+
// src/cli/helpers-cli.ts
|
|
15
|
+
import { writeFileSync } from "node:fs";
|
|
16
|
+
var [command, ...rest] = process.argv.slice(2);
|
|
17
|
+
function flag(name) {
|
|
18
|
+
const index = rest.indexOf(`--${name}`);
|
|
19
|
+
return index >= 0 ? rest[index + 1] : undefined;
|
|
20
|
+
}
|
|
21
|
+
function usage(message) {
|
|
22
|
+
console.error(`adea-voice-helpers: ${message}`);
|
|
23
|
+
console.error("usage: adea-voice-helpers stage|verify|url --lock <lock.json> …");
|
|
24
|
+
process.exit(2);
|
|
25
|
+
}
|
|
26
|
+
function target() {
|
|
27
|
+
const value = flag("target") ?? currentHelperTarget2();
|
|
28
|
+
if (!value || !HELPER_TARGETS2.includes(value))
|
|
29
|
+
usage(`no helper target for this machine; pass --target`);
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function helpers(lockHelpers) {
|
|
33
|
+
const value = flag("helpers");
|
|
34
|
+
const names = value ? value.split(",").map((name) => name.trim()).filter(Boolean) : lockHelpers;
|
|
35
|
+
for (const name of names) {
|
|
36
|
+
if (!HELPER_NAMES2.includes(name))
|
|
37
|
+
usage(`unknown helper ${name}`);
|
|
38
|
+
}
|
|
39
|
+
return names;
|
|
40
|
+
}
|
|
41
|
+
async function pin(lockPath) {
|
|
42
|
+
const version = flag("version") ?? usage("pin needs --version");
|
|
43
|
+
const base = flag("base") ?? "https://adea.dev/releases/voice/";
|
|
44
|
+
const url = `${base}voice-helpers-${version}.lock.json`;
|
|
45
|
+
const response = await fetch(url);
|
|
46
|
+
if (!response.ok)
|
|
47
|
+
throw new HelperLockError2(`GET ${url} answered ${response.status}: is ${version} released?`);
|
|
48
|
+
const lock = validateHelperLock2(await response.json());
|
|
49
|
+
if (lock.version !== version)
|
|
50
|
+
throw new HelperLockError2(`${url} pins ${lock.version}, not ${version}`);
|
|
51
|
+
writeFileSync(lockPath, `${JSON.stringify(lock, null, 2)}
|
|
52
|
+
`);
|
|
53
|
+
console.log(`voice helpers: ${lockPath} now pins ${version}`);
|
|
54
|
+
}
|
|
55
|
+
async function main() {
|
|
56
|
+
const lockPath = flag("lock");
|
|
57
|
+
if (!command || !lockPath)
|
|
58
|
+
usage("missing command or --lock");
|
|
59
|
+
if (command === "pin")
|
|
60
|
+
return await pin(lockPath);
|
|
61
|
+
const lock = readHelperLock2(lockPath);
|
|
62
|
+
const selectedTarget = target();
|
|
63
|
+
const pinned = Object.entries(lock.helpers).filter(([, targets]) => targets?.[selectedTarget]).map(([name]) => name);
|
|
64
|
+
switch (command) {
|
|
65
|
+
case "stage": {
|
|
66
|
+
const out = flag("out") ?? usage("stage needs --out");
|
|
67
|
+
const record = await stageVoiceHelpers2({
|
|
68
|
+
lock,
|
|
69
|
+
target: selectedTarget,
|
|
70
|
+
outDir: out,
|
|
71
|
+
helpers: helpers(pinned),
|
|
72
|
+
cacheDir: flag("cache"),
|
|
73
|
+
localDir: flag("local"),
|
|
74
|
+
handshake: rest.includes("--no-handshake") ? false : undefined,
|
|
75
|
+
log: (message) => console.log(`voice helpers: ${message}`)
|
|
76
|
+
});
|
|
77
|
+
console.log(`voice helpers: staged ${Object.keys(record.helpers).join(", ")} ${record.version} for ${record.target}`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
case "verify": {
|
|
81
|
+
const dir = flag("dir") ?? usage("verify needs --dir");
|
|
82
|
+
verifyStagedVoiceHelpers2({ lock, target: selectedTarget, dir, helpers: helpers(pinned) });
|
|
83
|
+
console.log(`voice helpers: ${dir} holds the pinned ${lock.version} helpers for ${selectedTarget}`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
case "url": {
|
|
87
|
+
const helper = flag("helper") ?? usage("url needs --helper");
|
|
88
|
+
console.log(helperArtifactUrl2(lock, helpers([helper])[0], selectedTarget));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
default:
|
|
92
|
+
usage(`unknown command ${command}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
main().catch((error) => {
|
|
96
|
+
if (error instanceof HelperLockError2) {
|
|
97
|
+
console.error(`adea-voice-helpers: ${error.message}`);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
console.error(error);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared Voice provider contract in TypeScript (issue #19).
|
|
3
|
+
*
|
|
4
|
+
* Field names and values mirror the Swift implementation in `Sources/AdeaVoice/VoiceProvider.swift`
|
|
5
|
+
* so a web adapter, a Capacitor bridge and the desktop helper describe the same provider, the same
|
|
6
|
+
* reasons and the same routing decision. The version is checked, not assumed: a provider on another
|
|
7
|
+
* contract major is refused rather than reinterpreted.
|
|
8
|
+
*
|
|
9
|
+
* Browser specifics live above this layer (`browserSttProvider`, `phononProvider`, `systemVoices`),
|
|
10
|
+
* not in it.
|
|
11
|
+
*/
|
|
12
|
+
/** The contract this build speaks. Compatibility is by major version only. */
|
|
13
|
+
export declare const VOICE_CONTRACT: {
|
|
14
|
+
readonly major: 1;
|
|
15
|
+
readonly minor: 0;
|
|
16
|
+
};
|
|
17
|
+
export interface VoiceContract {
|
|
18
|
+
readonly major: number;
|
|
19
|
+
readonly minor: number;
|
|
20
|
+
}
|
|
21
|
+
/** Whether a provider speaking `candidate` can be used by an SDK speaking `supported`. */
|
|
22
|
+
export declare function isCompatibleContract(candidate: VoiceContract, supported?: VoiceContract): boolean;
|
|
23
|
+
export type VoiceProviderKind = "speechToText" | "textToSpeech";
|
|
24
|
+
export type VoicePlatform = "macOS" | "iOS" | "windows" | "linux" | "android" | "web";
|
|
25
|
+
export type VoiceExecutionLocation = "onDevice" | "systemProvided" | "network";
|
|
26
|
+
/** Code and asset licences stay separate: a permissive runtime can carry non-commercial weights. */
|
|
27
|
+
export interface VoiceAssetLicense {
|
|
28
|
+
readonly spdxIdentifier: string;
|
|
29
|
+
readonly commercialUse: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Capability, not availability: what the provider can do when it can run here. */
|
|
32
|
+
export interface VoiceProviderCapabilities {
|
|
33
|
+
readonly streamingPartials?: boolean;
|
|
34
|
+
readonly trueCancellation?: boolean;
|
|
35
|
+
readonly modelInstallation?: boolean;
|
|
36
|
+
readonly localeSelection?: boolean;
|
|
37
|
+
readonly voiceSelection?: boolean;
|
|
38
|
+
readonly utteranceQueueing?: boolean;
|
|
39
|
+
readonly wordBoundaryPause?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The capability bits in wire order: bit `i` is `1 << i`. Same order as the Swift
|
|
43
|
+
* `VoiceProviderCapabilities` option set (`Sources/AdeaVoice/VoiceProvider.swift`); the integer
|
|
44
|
+
* mask is what every other surface (helper, Capacitor, Android) carries. Append only.
|
|
45
|
+
*/
|
|
46
|
+
export declare const VOICE_CAPABILITY_BITS: readonly ["streamingPartials", "trueCancellation", "modelInstallation", "localeSelection", "voiceSelection", "utteranceQueueing", "wordBoundaryPause"];
|
|
47
|
+
/** The integer bit mask for a capabilities object (the wire form). */
|
|
48
|
+
export declare function capabilitiesToMask(capabilities: VoiceProviderCapabilities): number;
|
|
49
|
+
/**
|
|
50
|
+
* A capabilities object from an integer bit mask. Every known flag is present (true or false);
|
|
51
|
+
* bits this build does not know are ignored, as a higher contract minor may add them.
|
|
52
|
+
*/
|
|
53
|
+
export declare function capabilitiesFromMask(mask: number): Required<VoiceProviderCapabilities>;
|
|
54
|
+
/** Static identity and constraints. Safe to cache and log. */
|
|
55
|
+
export interface VoiceProviderDescriptor {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly displayName: string;
|
|
58
|
+
readonly kind: VoiceProviderKind;
|
|
59
|
+
readonly platforms: readonly VoicePlatform[];
|
|
60
|
+
readonly execution: VoiceExecutionLocation;
|
|
61
|
+
readonly contract: VoiceContract;
|
|
62
|
+
readonly requiresModelDownload: boolean;
|
|
63
|
+
readonly modelFamilies: readonly string[];
|
|
64
|
+
readonly licenses: readonly VoiceAssetLicense[];
|
|
65
|
+
readonly capabilities: VoiceProviderCapabilities;
|
|
66
|
+
}
|
|
67
|
+
/** The closed set of reasons a provider cannot serve a request right now. */
|
|
68
|
+
export type VoiceUnavailabilityReason = "unsupportedOperatingSystem" | "unsupportedPlatform" | "unsupportedDevice" | "unsupportedLocale" | "modelNotInstalled" | "modelDownloadDisabled" | "licenseNotAccepted" | "networkRequired" | "permissionDenied" | "contractIncompatible" | "providerNotRegistered" | "engineFailed";
|
|
69
|
+
export type VoiceRemedyKind = "installModel" | "switchLocale" | "upgradeOperatingSystem" | "acceptLicense" | "grantPermission" | "chooseAnotherProvider" | "none";
|
|
70
|
+
export interface VoiceRemedy {
|
|
71
|
+
readonly kind: VoiceRemedyKind;
|
|
72
|
+
readonly detail: string;
|
|
73
|
+
}
|
|
74
|
+
export interface VoiceUnavailability {
|
|
75
|
+
readonly reason: VoiceUnavailabilityReason;
|
|
76
|
+
readonly message: string;
|
|
77
|
+
readonly remedy?: VoiceRemedy;
|
|
78
|
+
}
|
|
79
|
+
export type VoiceProviderAvailability = {
|
|
80
|
+
readonly status: "available";
|
|
81
|
+
} | {
|
|
82
|
+
readonly status: "unavailable";
|
|
83
|
+
readonly unavailable: VoiceUnavailability;
|
|
84
|
+
};
|
|
85
|
+
export declare const AVAILABLE: VoiceProviderAvailability;
|
|
86
|
+
export declare function unavailable(reason: VoiceUnavailabilityReason, message: string, remedy?: VoiceRemedy): VoiceProviderAvailability;
|
|
87
|
+
export declare function isAvailable(availability: VoiceProviderAvailability): availability is {
|
|
88
|
+
readonly status: "available";
|
|
89
|
+
};
|
|
90
|
+
/** One candidate for one request: the descriptor plus its truth here and now. */
|
|
91
|
+
export interface VoiceRoute {
|
|
92
|
+
readonly kind: VoiceProviderKind;
|
|
93
|
+
readonly locale: string;
|
|
94
|
+
readonly descriptor: VoiceProviderDescriptor;
|
|
95
|
+
readonly availability: VoiceProviderAvailability;
|
|
96
|
+
}
|
|
97
|
+
/** "Install, then start": both reasons mean an explicit install would resolve the route. */
|
|
98
|
+
export declare function requiresModelInstallation(route: VoiceRoute): boolean;
|
|
99
|
+
export interface VoiceRoutingDecision {
|
|
100
|
+
readonly kind: VoiceProviderKind;
|
|
101
|
+
readonly locale: string;
|
|
102
|
+
/** The selected provider, or null when none can serve the request. */
|
|
103
|
+
readonly route: VoiceRoute | null;
|
|
104
|
+
/** The registered candidates in policy order, each with its own truth. */
|
|
105
|
+
readonly candidates: readonly VoiceRoute[];
|
|
106
|
+
/** Chain identifiers this build does not register. */
|
|
107
|
+
readonly missing: readonly string[];
|
|
108
|
+
/** The selected provider's truth, or the most actionable failure when nothing resolved. */
|
|
109
|
+
readonly availability: VoiceProviderAvailability;
|
|
110
|
+
}
|
|
111
|
+
/** A provider: static descriptor, prompt-free probe, and a typed availability per locale. */
|
|
112
|
+
export interface VoiceProvider {
|
|
113
|
+
readonly descriptor: VoiceProviderDescriptor;
|
|
114
|
+
availability(locale: string): Promise<VoiceProviderAvailability>;
|
|
115
|
+
}
|
|
116
|
+
/** Routing is data: an ordered chain per kind, an explicit override, and one policy flag. */
|
|
117
|
+
export interface VoiceRoutingPolicy {
|
|
118
|
+
/** Ordered provider ids per kind. The first usable one wins. */
|
|
119
|
+
readonly chains: Partial<Record<VoiceProviderKind, readonly string[]>>;
|
|
120
|
+
/** An explicit choice replaces the chain: the caller gets that provider's truth, no substitute. */
|
|
121
|
+
readonly overrides?: Partial<Record<VoiceProviderKind, string>>;
|
|
122
|
+
/** Whether a provider whose models are absent may be selected so the host can install them. */
|
|
123
|
+
readonly allowsOptInModelInstallation: boolean;
|
|
124
|
+
}
|
|
125
|
+
/** The browser routing table: local recognition only, Phonon first for synthesis. */
|
|
126
|
+
export declare const WEB_ROUTING_POLICY: VoiceRoutingPolicy;
|
|
127
|
+
export interface RouteRequest {
|
|
128
|
+
readonly kind: VoiceProviderKind;
|
|
129
|
+
readonly locale: string;
|
|
130
|
+
readonly providers: readonly VoiceProvider[];
|
|
131
|
+
readonly policy?: VoiceRoutingPolicy;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Resolves one request. A provider on another contract major, a network provider in a chain, or a
|
|
135
|
+
* provider whose models are absent are all reported with their own reason; nothing is substituted
|
|
136
|
+
* and nothing is downloaded.
|
|
137
|
+
*/
|
|
138
|
+
export declare function route(request: RouteRequest): Promise<VoiceRoutingDecision>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error codes the Voice SDK reports on every platform, as values.
|
|
3
|
+
*
|
|
4
|
+
* These are the **wire strings**: the same snake_case codes the desktop helper, the Capacitor
|
|
5
|
+
* bridge and the Android plugin send, so an adapter matches one code across a native helper, a
|
|
6
|
+
* Capacitor bridge and a browser provider without a translation table. Additive only: a code is
|
|
7
|
+
* never renamed or reused for another meaning. `normalizeVoiceErrorCode` accepts the legacy
|
|
8
|
+
* camelCase spellings (Swift enum case names, earlier builds of this package) for stored values.
|
|
9
|
+
*/
|
|
10
|
+
export declare const VOICE_ERROR_CODES: readonly ["denied", "restricted", "unavailable", "no_speech", "language_unsupported", "assets_missing", "assets_install_failed", "assets_locale_limit", "insufficient_storage", "audio_overrun", "busy", "cancelled", "bad_request", "failed"];
|
|
11
|
+
export type VoiceErrorCode = (typeof VOICE_ERROR_CODES)[number];
|
|
12
|
+
/**
|
|
13
|
+
* Maps any value received from a bridge, a helper or storage to a wire code: snake_case codes pass
|
|
14
|
+
* through, legacy camelCase codes are translated, and anything else becomes `failed`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function normalizeVoiceErrorCode(value: unknown): VoiceErrorCode;
|
|
17
|
+
/** The typed failure every public browser operation reports. */
|
|
18
|
+
export declare class VoiceError extends Error {
|
|
19
|
+
readonly code: VoiceErrorCode;
|
|
20
|
+
constructor(code: VoiceErrorCode, message?: string);
|
|
21
|
+
/**
|
|
22
|
+
* Preserve a typed error, map an abort to `cancelled`, keep a recognisable `code` from a bridge
|
|
23
|
+
* error, and fold anything else into `fallback`.
|
|
24
|
+
*/
|
|
25
|
+
static wrapping(error: unknown, fallback?: VoiceErrorCode): VoiceError;
|
|
26
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@adea-ai/voice/contract`: the shared provider contract — descriptors, typed availability,
|
|
3
|
+
* routing, the snake_case error vocabulary, the dictation session shape and the desktop helpers'
|
|
4
|
+
* wire protocol. Pure TypeScript: safe in a browser, a worker, Bun or Node.
|
|
5
|
+
*/
|
|
6
|
+
export * from "./contract";
|
|
7
|
+
export * from "./errors";
|
|
8
|
+
export * from "./session";
|
|
9
|
+
export * from "./wire";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ENDPOINTING2
|
|
3
|
+
} from "../index-r4hz8gk0.js";
|
|
4
|
+
import {
|
|
5
|
+
VOICE_CONTRACT2,
|
|
6
|
+
isCompatibleContract2,
|
|
7
|
+
VOICE_CAPABILITY_BITS2,
|
|
8
|
+
capabilitiesToMask2,
|
|
9
|
+
capabilitiesFromMask2,
|
|
10
|
+
AVAILABLE2,
|
|
11
|
+
unavailable2,
|
|
12
|
+
isAvailable2,
|
|
13
|
+
requiresModelInstallation2,
|
|
14
|
+
WEB_ROUTING_POLICY2,
|
|
15
|
+
route2
|
|
16
|
+
} from "../index-9kerqn9r.js";
|
|
17
|
+
import {
|
|
18
|
+
WIRE_VERSION2,
|
|
19
|
+
CONTRACT_MAJOR2,
|
|
20
|
+
MAX_WIRE_LINE_BYTES2,
|
|
21
|
+
parseWireLine2,
|
|
22
|
+
encodeWireCommand2,
|
|
23
|
+
correlationId2,
|
|
24
|
+
isCompatibleHandshake2
|
|
25
|
+
} from "../index-rehs788p.js";
|
|
26
|
+
import {
|
|
27
|
+
VOICE_ERROR_CODES2,
|
|
28
|
+
normalizeVoiceErrorCode2,
|
|
29
|
+
VoiceError2
|
|
30
|
+
} from "../index-tvz9s9nz.js";
|
|
31
|
+
export {
|
|
32
|
+
AVAILABLE2 as AVAILABLE,
|
|
33
|
+
CONTRACT_MAJOR2 as CONTRACT_MAJOR,
|
|
34
|
+
DEFAULT_ENDPOINTING2 as DEFAULT_ENDPOINTING,
|
|
35
|
+
MAX_WIRE_LINE_BYTES2 as MAX_WIRE_LINE_BYTES,
|
|
36
|
+
VOICE_CAPABILITY_BITS2 as VOICE_CAPABILITY_BITS,
|
|
37
|
+
VOICE_CONTRACT2 as VOICE_CONTRACT,
|
|
38
|
+
VOICE_ERROR_CODES2 as VOICE_ERROR_CODES,
|
|
39
|
+
VoiceError2 as VoiceError,
|
|
40
|
+
WEB_ROUTING_POLICY2 as WEB_ROUTING_POLICY,
|
|
41
|
+
WIRE_VERSION2 as WIRE_VERSION,
|
|
42
|
+
capabilitiesFromMask2 as capabilitiesFromMask,
|
|
43
|
+
capabilitiesToMask2 as capabilitiesToMask,
|
|
44
|
+
correlationId2 as correlationId,
|
|
45
|
+
encodeWireCommand2 as encodeWireCommand,
|
|
46
|
+
isAvailable2 as isAvailable,
|
|
47
|
+
isCompatibleContract2 as isCompatibleContract,
|
|
48
|
+
isCompatibleHandshake2 as isCompatibleHandshake,
|
|
49
|
+
normalizeVoiceErrorCode2 as normalizeVoiceErrorCode,
|
|
50
|
+
parseWireLine2 as parseWireLine,
|
|
51
|
+
requiresModelInstallation2 as requiresModelInstallation,
|
|
52
|
+
route2 as route,
|
|
53
|
+
unavailable2 as unavailable
|
|
54
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The platform-neutral dictation session contract: the shape every speech-to-text provider hands a
|
|
3
|
+
* host, whether it runs in a browser, behind the desktop helper or in a mobile plugin.
|
|
4
|
+
*/
|
|
5
|
+
import type { VoiceProvider } from "./contract";
|
|
6
|
+
import type { VoiceError } from "./errors";
|
|
7
|
+
export interface PartialTranscript {
|
|
8
|
+
readonly finalizedText: string;
|
|
9
|
+
readonly volatileText: string;
|
|
10
|
+
/** Monotonic per session, starting at 0 on the first partial. */
|
|
11
|
+
readonly sequence: number;
|
|
12
|
+
}
|
|
13
|
+
export type SessionEvent = {
|
|
14
|
+
readonly type: "partial";
|
|
15
|
+
readonly partial: PartialTranscript;
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "final";
|
|
18
|
+
readonly text: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "failed";
|
|
21
|
+
readonly error: VoiceError;
|
|
22
|
+
} | {
|
|
23
|
+
readonly type: "cancelled";
|
|
24
|
+
};
|
|
25
|
+
export interface EndpointingOptions {
|
|
26
|
+
/** Stop after this much silence following new words. Default 1.6 s. */
|
|
27
|
+
readonly silenceLimitSeconds: number;
|
|
28
|
+
/** Fail with `no_speech` if no words arrive within this time. Default 8 s. */
|
|
29
|
+
readonly noSpeechTimeoutSeconds: number;
|
|
30
|
+
/** Hard cap on one session; `null` means none. Default 60 s. */
|
|
31
|
+
readonly maxDurationSeconds: number | null;
|
|
32
|
+
/** Wait this long for a final result after audio stops. Default 3 s. */
|
|
33
|
+
readonly finalizationDeadlineSeconds: number;
|
|
34
|
+
/** Endpointing resolution. Default 0.25 s. */
|
|
35
|
+
readonly tickIntervalSeconds: number;
|
|
36
|
+
}
|
|
37
|
+
export declare const DEFAULT_ENDPOINTING: EndpointingOptions;
|
|
38
|
+
export interface TranscriptionSessionOptions {
|
|
39
|
+
readonly locale: string;
|
|
40
|
+
/** Whether this host has the person's consent to send audio to the browser's service. */
|
|
41
|
+
readonly allowNetwork: boolean;
|
|
42
|
+
readonly endpointing?: EndpointingOptions;
|
|
43
|
+
}
|
|
44
|
+
/** One running recognition session: the browser-facing half of the shared contract. */
|
|
45
|
+
export interface TranscriptionSession {
|
|
46
|
+
/** The session's events. Exactly one terminal event, then the iterator finishes. */
|
|
47
|
+
events(): AsyncIterable<SessionEvent>;
|
|
48
|
+
/** Whether recognition is running on the device (proven) or through a service. */
|
|
49
|
+
readonly execution: "onDevice" | "network";
|
|
50
|
+
/** Stop needing audio and finalize: yields `final` (or `failed`) by the deadline. */
|
|
51
|
+
end(): Promise<void>;
|
|
52
|
+
/** Tear down now: yields `cancelled` and releases the recognizer. Idempotent. */
|
|
53
|
+
cancel(): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
export interface TranscriptionProvider extends VoiceProvider {
|
|
56
|
+
/** Creates a session. Throws `VoiceError` before any audio when the combination is refused. */
|
|
57
|
+
createSession(options: TranscriptionSessionOptions): Promise<TranscriptionSession>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
/** The wire major this SDK speaks. A helper on another major is refused, never guessed at. */
|
|
11
|
+
export declare const WIRE_VERSION = 1;
|
|
12
|
+
/** The provider-contract major this SDK speaks. */
|
|
13
|
+
export declare const CONTRACT_MAJOR = 1;
|
|
14
|
+
/** One line may not exceed this many bytes (the helpers enforce the same bound on input). */
|
|
15
|
+
export declare const MAX_WIRE_LINE_BYTES = 1000000;
|
|
16
|
+
export interface VersionEvent {
|
|
17
|
+
readonly event: "version";
|
|
18
|
+
readonly wire: number;
|
|
19
|
+
readonly wireMinor?: number;
|
|
20
|
+
readonly contract: string;
|
|
21
|
+
readonly contractMajor: number;
|
|
22
|
+
readonly helper?: string;
|
|
23
|
+
readonly id?: string;
|
|
24
|
+
}
|
|
25
|
+
export type CombinedPermission = "granted" | "denied" | "prompt" | "unavailable";
|
|
26
|
+
export type PermissionPart = "granted" | "denied" | "restricted" | "prompt";
|
|
27
|
+
export interface PermissionEvent {
|
|
28
|
+
readonly event: "permission";
|
|
29
|
+
readonly state: CombinedPermission;
|
|
30
|
+
readonly microphone?: PermissionPart;
|
|
31
|
+
readonly speech?: PermissionPart;
|
|
32
|
+
readonly id?: string;
|
|
33
|
+
}
|
|
34
|
+
export type EngineState = "available" | "needsAssetInstall" | "unavailableOS" | "localeUnsupported" | "engineUnavailable";
|
|
35
|
+
export type AssetStatus = "installed" | "notInstalled" | "downloading" | "unsupported";
|
|
36
|
+
/** `adea-voice-helper` status: Apple's two engines for one locale. */
|
|
37
|
+
export interface AppleStatusEvent {
|
|
38
|
+
readonly event: "status";
|
|
39
|
+
readonly locale: string;
|
|
40
|
+
readonly analyzer: EngineState;
|
|
41
|
+
readonly legacy: EngineState;
|
|
42
|
+
readonly analyzerEquivalentLocale: string;
|
|
43
|
+
readonly recommendedEngine: "analyzer" | "legacy" | "none";
|
|
44
|
+
readonly assetStatus: AssetStatus;
|
|
45
|
+
readonly canInstall: boolean;
|
|
46
|
+
readonly id?: string;
|
|
47
|
+
}
|
|
48
|
+
/** `adea-transcribe-helper` status: the local models it can see. */
|
|
49
|
+
export interface TranscribeStatusEvent {
|
|
50
|
+
readonly event: "status";
|
|
51
|
+
readonly engine: "transcribe";
|
|
52
|
+
readonly locale: string;
|
|
53
|
+
readonly models: readonly {
|
|
54
|
+
readonly path: string;
|
|
55
|
+
readonly architecture: string;
|
|
56
|
+
readonly variant: string;
|
|
57
|
+
readonly languages: readonly string[];
|
|
58
|
+
readonly streaming: boolean;
|
|
59
|
+
}[];
|
|
60
|
+
readonly ready: boolean;
|
|
61
|
+
readonly selected?: string;
|
|
62
|
+
readonly id?: string;
|
|
63
|
+
}
|
|
64
|
+
/** `adea-tts-helper` status. */
|
|
65
|
+
export interface SynthesisStatusEvent {
|
|
66
|
+
readonly event: "status";
|
|
67
|
+
readonly engine: "audio.cpp";
|
|
68
|
+
readonly locale: string;
|
|
69
|
+
readonly modelPath: string;
|
|
70
|
+
readonly voice: string;
|
|
71
|
+
readonly ready: boolean;
|
|
72
|
+
readonly reason?: string;
|
|
73
|
+
readonly message?: string;
|
|
74
|
+
readonly id?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface LocaleEvent {
|
|
77
|
+
readonly event: "locale";
|
|
78
|
+
readonly locale: string;
|
|
79
|
+
readonly status: AssetStatus;
|
|
80
|
+
readonly canInstall: boolean;
|
|
81
|
+
readonly id?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface ListDoneEvent {
|
|
84
|
+
readonly event: "locales-done" | "voices-done";
|
|
85
|
+
readonly count: number;
|
|
86
|
+
readonly id?: string;
|
|
87
|
+
}
|
|
88
|
+
export interface VoiceEvent {
|
|
89
|
+
readonly event: "voice";
|
|
90
|
+
/** The voice identifier (not the request id). */
|
|
91
|
+
readonly id: string;
|
|
92
|
+
readonly requestId?: string;
|
|
93
|
+
readonly name: string;
|
|
94
|
+
readonly locale: string;
|
|
95
|
+
readonly quality: "default" | "enhanced" | "premium" | "unknown";
|
|
96
|
+
readonly gender: "male" | "female" | "unknown";
|
|
97
|
+
readonly source?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface ListeningEvent {
|
|
100
|
+
readonly event: "listening";
|
|
101
|
+
readonly engine: string;
|
|
102
|
+
readonly locale: string;
|
|
103
|
+
readonly model?: string;
|
|
104
|
+
readonly id?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface PartialEvent {
|
|
107
|
+
readonly event: "partial";
|
|
108
|
+
readonly text?: string;
|
|
109
|
+
readonly finalizedText: string;
|
|
110
|
+
readonly volatileText: string;
|
|
111
|
+
readonly sequence: number;
|
|
112
|
+
readonly id?: string;
|
|
113
|
+
}
|
|
114
|
+
export interface FinalEvent {
|
|
115
|
+
readonly event: "final";
|
|
116
|
+
readonly text: string;
|
|
117
|
+
readonly id?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface ErrorEvent {
|
|
120
|
+
readonly event: "error";
|
|
121
|
+
readonly code: VoiceErrorCode;
|
|
122
|
+
readonly message?: string;
|
|
123
|
+
readonly id?: string;
|
|
124
|
+
}
|
|
125
|
+
export interface CancelledEvent {
|
|
126
|
+
readonly event: "cancelled";
|
|
127
|
+
readonly id?: string;
|
|
128
|
+
}
|
|
129
|
+
export interface IdleEvent {
|
|
130
|
+
readonly event: "idle";
|
|
131
|
+
readonly command: string;
|
|
132
|
+
readonly id?: string;
|
|
133
|
+
}
|
|
134
|
+
export interface AssetProgressEvent {
|
|
135
|
+
readonly event: "asset-progress";
|
|
136
|
+
readonly locale: string;
|
|
137
|
+
readonly fraction: number | null;
|
|
138
|
+
readonly id?: string;
|
|
139
|
+
}
|
|
140
|
+
export interface AssetInstalledEvent {
|
|
141
|
+
readonly event: "asset-installed";
|
|
142
|
+
readonly locale: string;
|
|
143
|
+
readonly id?: string;
|
|
144
|
+
}
|
|
145
|
+
export interface SpeechLifecycleEvent {
|
|
146
|
+
readonly event: "speech-started" | "speech-finished" | "speech-cancelled";
|
|
147
|
+
readonly id: string;
|
|
148
|
+
}
|
|
149
|
+
export interface SpeechErrorEvent {
|
|
150
|
+
readonly event: "speech-error";
|
|
151
|
+
readonly code: VoiceErrorCode;
|
|
152
|
+
readonly message?: string;
|
|
153
|
+
readonly id: string;
|
|
154
|
+
}
|
|
155
|
+
export interface SpeechStateEvent {
|
|
156
|
+
readonly event: "speech-state";
|
|
157
|
+
readonly state: "paused" | "resumed";
|
|
158
|
+
}
|
|
159
|
+
export interface SpeechInterruptedEvent {
|
|
160
|
+
readonly event: "speech-interrupted" | "speech-route-changed";
|
|
161
|
+
readonly reason?: string;
|
|
162
|
+
}
|
|
163
|
+
/** A second line the local-model helpers print after `version`. */
|
|
164
|
+
export interface HelperIdentityEvent {
|
|
165
|
+
readonly event: "helper";
|
|
166
|
+
readonly name: string;
|
|
167
|
+
readonly engine: string;
|
|
168
|
+
readonly library?: string;
|
|
169
|
+
}
|
|
170
|
+
export type WireEvent = VersionEvent | HelperIdentityEvent | PermissionEvent | AppleStatusEvent | TranscribeStatusEvent | SynthesisStatusEvent | LocaleEvent | ListDoneEvent | VoiceEvent | ListeningEvent | PartialEvent | FinalEvent | ErrorEvent | CancelledEvent | IdleEvent | AssetProgressEvent | AssetInstalledEvent | SpeechLifecycleEvent | SpeechErrorEvent | SpeechStateEvent | SpeechInterruptedEvent;
|
|
171
|
+
/** A command line. `cmd` is the helpers' key; `command` is sent too for the transcribe helper. */
|
|
172
|
+
export interface WireCommand {
|
|
173
|
+
readonly cmd: string;
|
|
174
|
+
readonly id?: string;
|
|
175
|
+
readonly [field: string]: unknown;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Parses one stdout line. Returns `undefined` for anything that is not a JSON object with a string
|
|
179
|
+
* `event` (a helper's stray diagnostic line must never crash a host). Error codes are normalised
|
|
180
|
+
* to the snake_case vocabulary; an unknown code becomes `failed`.
|
|
181
|
+
*/
|
|
182
|
+
export declare function parseWireLine(line: string): WireEvent | undefined;
|
|
183
|
+
/** Encodes one command line (no trailing newline). */
|
|
184
|
+
export declare function encodeWireCommand(command: WireCommand): string;
|
|
185
|
+
/** The request id an event answers, or `undefined` for an uncorrelated event. */
|
|
186
|
+
export declare function correlationId(event: WireEvent): string | undefined;
|
|
187
|
+
/** Whether a version handshake is one this SDK can talk to. */
|
|
188
|
+
export declare function isCompatibleHandshake(event: VersionEvent): boolean;
|