@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
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
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-a7d617zr.js";
21
+ import {
22
+ VOICE_CONTRACT2,
23
+ isCompatibleContract2,
24
+ VOICE_CAPABILITY_BITS2,
25
+ capabilitiesToMask2,
26
+ capabilitiesFromMask2,
27
+ AVAILABLE2,
28
+ availableWithMatch2,
29
+ isLanguageOnly2,
30
+ unavailable2,
31
+ isAvailable2,
32
+ requiresModelInstallation2,
33
+ WEB_ROUTING_POLICY2,
34
+ route2
35
+ } from "./index-ght8wwpd.js";
36
+ import {
37
+ WIRE_VERSION2,
38
+ TURN_WIRE_MINOR2,
39
+ RELEASE_ASSETS_WIRE_MINOR2,
40
+ CONTRACT_MAJOR2,
41
+ MAX_WIRE_LINE_BYTES2,
42
+ isTurnTerminal2,
43
+ parseWireLine2,
44
+ encodeWireCommand2,
45
+ correlationId2,
46
+ isCompatibleHandshake2
47
+ } from "./index-7n7epq1a.js";
48
+ import {
49
+ VOICE_ERROR_CODES2,
50
+ normalizeVoiceErrorCode2,
51
+ VoiceError2
52
+ } from "./index-tvz9s9nz.js";
53
+ export {
54
+ AVAILABLE2 as AVAILABLE,
55
+ CONTRACT_MAJOR2 as CONTRACT_MAJOR,
56
+ DEFAULT_ENDPOINTING2 as DEFAULT_ENDPOINTING,
57
+ DEFAULT_VOICE_SETTINGS2 as DEFAULT_VOICE_SETTINGS,
58
+ MAX_WIRE_LINE_BYTES2 as MAX_WIRE_LINE_BYTES,
59
+ RELEASE_ASSETS_WIRE_MINOR2 as RELEASE_ASSETS_WIRE_MINOR,
60
+ SETTINGS_SCHEMA_VERSION2 as SETTINGS_SCHEMA_VERSION,
61
+ TURN_WIRE_MINOR2 as TURN_WIRE_MINOR,
62
+ VOICE_CAPABILITY_BITS2 as VOICE_CAPABILITY_BITS,
63
+ VOICE_CONTRACT2 as VOICE_CONTRACT,
64
+ VOICE_ERROR_CODES2 as VOICE_ERROR_CODES,
65
+ VOICE_SETTINGS_STORAGE_KEY2 as VOICE_SETTINGS_STORAGE_KEY,
66
+ VoiceError2 as VoiceError,
67
+ WEB_ROUTING_POLICY2 as WEB_ROUTING_POLICY,
68
+ WIRE_VERSION2 as WIRE_VERSION,
69
+ allowsModelDownload2 as allowsModelDownload,
70
+ allowsNetworkSpeechToText2 as allowsNetworkSpeechToText,
71
+ allowsNetworkSynthesis2 as allowsNetworkSynthesis,
72
+ assertUsableSettings2 as assertUsableSettings,
73
+ availableWithMatch2 as availableWithMatch,
74
+ capabilitiesFromMask2 as capabilitiesFromMask,
75
+ capabilitiesToMask2 as capabilitiesToMask,
76
+ correlationId2 as correlationId,
77
+ createVoiceSettingsStore2 as createVoiceSettingsStore,
78
+ encodeWireCommand2 as encodeWireCommand,
79
+ isAvailable2 as isAvailable,
80
+ isCompatibleContract2 as isCompatibleContract,
81
+ isCompatibleHandshake2 as isCompatibleHandshake,
82
+ isLanguageOnly2 as isLanguageOnly,
83
+ isTurnTerminal2 as isTurnTerminal,
84
+ normalizeVoiceErrorCode2 as normalizeVoiceErrorCode,
85
+ parseWireLine2 as parseWireLine,
86
+ readVoiceSettings2 as readVoiceSettings,
87
+ requiresModelInstallation2 as requiresModelInstallation,
88
+ resolveLocale2 as resolveLocale,
89
+ route2 as route,
90
+ routingPolicyFor2 as routingPolicyFor,
91
+ serializeVoiceSettings2 as serializeVoiceSettings,
92
+ unavailable2 as unavailable,
93
+ updateVoiceSettings2 as updateVoiceSettings,
94
+ validateVoiceSettings2 as validateVoiceSettings,
95
+ withLegacyDictationPreferences2 as withLegacyDictationPreferences
96
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * `@adea-ai/voice/settings`: the unified, versioned, per-device Voice settings (#32). Pure: it
3
+ * validates, migrates and serialises, and persists only through the storage a host hands it.
4
+ */
5
+ export * from "./settings";
@@ -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-a7d617zr.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,16 @@
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/locale-match";
14
+ export * from "./tts/player";
15
+ export * from "./tts/system-voices";
16
+ export * from "./turns";