@hyperwindmill/caretaker-cli 0.29.0 → 0.31.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/dist/agents/dispatch.d.ts.map +1 -1
- package/dist/agents/dispatch.js +4 -1
- package/dist/cli/web/server.d.ts.map +1 -1
- package/dist/cli/web/server.js +29 -7
- package/dist/cli/web/session_scope.d.ts +11 -0
- package/dist/cli/web/session_scope.d.ts.map +1 -0
- package/dist/cli/web/session_scope.js +13 -0
- package/dist/cli/web/turn_guard.d.ts +9 -0
- package/dist/cli/web/turn_guard.d.ts.map +1 -0
- package/dist/cli/web/turn_guard.js +18 -0
- package/dist/cli/web/voice_backend.d.ts +4 -0
- package/dist/cli/web/voice_backend.d.ts.map +1 -1
- package/dist/cli/web/voice_backend.js +14 -3
- package/dist/cli/web/voice_builtin.d.ts +3 -0
- package/dist/cli/web/voice_builtin.d.ts.map +1 -0
- package/dist/cli/web/voice_builtin.js +74 -0
- package/dist/cli/web/voice_proxy.d.ts +36 -1
- package/dist/cli/web/voice_proxy.d.ts.map +1 -1
- package/dist/cli/web/voice_proxy.js +201 -30
- package/dist/commands/loader.js +2 -2
- package/dist/harness/tools/builtin/index.d.ts.map +1 -1
- package/dist/harness/tools/builtin/index.js +4 -0
- package/dist/harness/tools/builtin/set_workspace.d.ts +3 -0
- package/dist/harness/tools/builtin/set_workspace.d.ts.map +1 -0
- package/dist/harness/tools/builtin/set_workspace.js +71 -0
- package/dist/plugins/manifest.d.ts +1 -1
- package/dist/plugins/manifest.js +1 -1
- package/dist/session/store.d.ts +6 -0
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +11 -0
- package/dist/session/types.d.ts +5 -0
- package/dist/session/types.d.ts.map +1 -1
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +3 -1
- package/dist/voice/pocket/catalog.d.ts +24 -0
- package/dist/voice/pocket/catalog.d.ts.map +1 -0
- package/dist/voice/pocket/catalog.js +152 -0
- package/dist/voice/pocket/engine.d.ts +17 -0
- package/dist/voice/pocket/engine.d.ts.map +1 -0
- package/dist/voice/pocket/engine.js +145 -0
- package/dist/voice/pocket/inference.d.ts +36 -0
- package/dist/voice/pocket/inference.d.ts.map +1 -0
- package/dist/voice/pocket/inference.js +228 -0
- package/dist/voice/pocket/install.d.ts +68 -0
- package/dist/voice/pocket/install.d.ts.map +1 -0
- package/dist/voice/pocket/install.js +329 -0
- package/dist/voice/pocket/tokenizer.d.ts +42 -0
- package/dist/voice/pocket/tokenizer.d.ts.map +1 -0
- package/dist/voice/pocket/tokenizer.js +279 -0
- package/dist/voice/pocket/voices.d.ts +9 -0
- package/dist/voice/pocket/voices.d.ts.map +1 -0
- package/dist/voice/pocket/voices.js +88 -0
- package/dist/voice/pronunciation.d.ts +16 -0
- package/dist/voice/pronunciation.d.ts.map +1 -0
- package/dist/voice/pronunciation.js +54 -0
- package/dist/voice/whisper/catalog.d.ts +15 -0
- package/dist/voice/whisper/catalog.d.ts.map +1 -0
- package/dist/voice/whisper/catalog.js +53 -0
- package/dist/voice/whisper/decoder.d.ts +3 -0
- package/dist/voice/whisper/decoder.d.ts.map +1 -0
- package/dist/voice/whisper/decoder.js +48 -0
- package/dist/voice/whisper/engine.d.ts +8 -0
- package/dist/voice/whisper/engine.d.ts.map +1 -0
- package/dist/voice/whisper/engine.js +77 -0
- package/dist/voice/whisper/features.d.ts +10 -0
- package/dist/voice/whisper/features.d.ts.map +1 -0
- package/dist/voice/whisper/features.js +149 -0
- package/dist/voice/whisper/inference.d.ts +17 -0
- package/dist/voice/whisper/inference.d.ts.map +1 -0
- package/dist/voice/whisper/inference.js +257 -0
- package/dist/voice/whisper/wav.d.ts +5 -0
- package/dist/voice/whisper/wav.d.ts.map +1 -0
- package/dist/voice/whisper/wav.js +48 -0
- package/dist/webview/standalone.js +1777 -743
- package/dist/webview/standalone.js.map +4 -4
- package/package.json +3 -3
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Pinned catalog for the built-in Pocket TTS engine: model bundles (Hugging Face), the
|
|
2
|
+
// ONNX runtime (npm registry tarballs) and the choice of who drives the graphs.
|
|
3
|
+
//
|
|
4
|
+
// INFERENCE_SOURCE = 'own-loop'. The npm `pocket-tts` package (1.0.0, MIT) was read, not
|
|
5
|
+
// run, and fails all three conditions. (1) It targets a different export, the community
|
|
6
|
+
// `KevinAHM/pocket-tts-onnx` repo (tokenizer.model, bos_before_voice.npy, a mimi encoder),
|
|
7
|
+
// not the schema-3 bundles of `Alias-Alias/pocket-3-3-0-tts-onnx` (explicit state_N /
|
|
8
|
+
// next_state_N tensors, tokenizer.json, voices.bin). (2) Local mode requires a reference
|
|
9
|
+
// WAV and encodes it (cloning); it never reads voices.bin or built-in voices. (3) It loads
|
|
10
|
+
// the runtime with a bare `import("onnxruntime-node")` (local/runtime.js) and exposes no
|
|
11
|
+
// way to pass a session factory or module, so it could not see our downloaded runtime.
|
|
12
|
+
// We therefore drive the four graphs ourselves; see the engine, which sits behind the
|
|
13
|
+
// small interface of the spec so the source can still be swapped.
|
|
14
|
+
export const POCKET_BASE_URL = 'https://huggingface.co/Alias-Alias/pocket-3-3-0-tts-onnx/resolve';
|
|
15
|
+
export const POCKET_REVISION = '71a4d6d11a76e26b98709fa163477c77d16bdbdb';
|
|
16
|
+
// `dir` is the bundle's subdirectory in the repo (also its language code). `nativeVoice`
|
|
17
|
+
// is the voice suggested first in the UI. The bundles ship no per-language native voices:
|
|
18
|
+
// every language carries the same eight official voices (each with a language-specific
|
|
19
|
+
// state in its own voices.bin), so the default is one shared voice.
|
|
20
|
+
export const POCKET_LANGUAGES = {
|
|
21
|
+
english: {
|
|
22
|
+
code: 'en',
|
|
23
|
+
dir: 'en',
|
|
24
|
+
nativeVoice: 'alba',
|
|
25
|
+
files: [
|
|
26
|
+
{ name: 'bundle.json', sha256: 'ccbb828d6dceee19688ee6eee884bb8de16edcc0f21fac5ed713a8739d978b2e', bytes: 13438 },
|
|
27
|
+
{ name: 'tokenizer.json', sha256: 'f498428e1eafee50492f7be13dc9bfafcfc12e508cd0eb1b01c92ecd5d8c6687', bytes: 245020 },
|
|
28
|
+
{ name: 'voices.bin', sha256: '720343118b8ec5177397d3898d43b0d13c7948f76794956610e5f0e795100cf1', bytes: 52404520 },
|
|
29
|
+
{ name: 'text_conditioner_int8.onnx', sha256: 'a060f0926e87a12309c54a681dde9daba8e32821e1e2348224fd6c30a3a7a28b', bytes: 16388338 },
|
|
30
|
+
{ name: 'flow_lm_main_int8.onnx', sha256: 'c9328891492caaa7580284d81d47d01679f570f297023d68fc4c7ce503113dc8', bytes: 76397201 },
|
|
31
|
+
{ name: 'flow_lm_flow_int8.onnx', sha256: '7edfcbccb1d40a84b2b59ac1e921963287471ff0cb266603d7fd4282a131d716', bytes: 10040048 },
|
|
32
|
+
{ name: 'mimi_decoder_int8.onnx', sha256: 'b27d1c38b96947a08bc54a7b660b553866a47b3b368b2170b89b09f5c7f35b56', bytes: 22638621 },
|
|
33
|
+
{ name: 'LICENSE-upstream.txt', sha256: '23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3', bytes: 1023 },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
french: {
|
|
37
|
+
code: 'fr',
|
|
38
|
+
dir: 'fr',
|
|
39
|
+
nativeVoice: 'alba',
|
|
40
|
+
files: [
|
|
41
|
+
{ name: 'bundle.json', sha256: '0894c2fc533b0a94d1f120fa9f959f4125ccff2443ac5362925989a5fcdd7fae', bytes: 13638 },
|
|
42
|
+
{ name: 'tokenizer.json', sha256: '6211acffe9cb95172f71f0051f18e26ea305b2b32ea00b331ee976551c70887f', bytes: 246403 },
|
|
43
|
+
{ name: 'voices.bin', sha256: 'a43532290caa733c6670bc52427f0ed9f709c43867049f3e511f85568fcf9c5c', bytes: 52404520 },
|
|
44
|
+
{ name: 'text_conditioner_int8.onnx', sha256: '6127b51df140da0123123aa929a9453fc9a63a7cfebdc33f8a1f3fb46c5f2139', bytes: 16388338 },
|
|
45
|
+
{ name: 'flow_lm_main_int8.onnx', sha256: '1c6611cc3d524843e990e3abfdc15ce84f16f7a9250b5970b0255df4759fe70b', bytes: 76397201 },
|
|
46
|
+
{ name: 'flow_lm_flow_int8.onnx', sha256: '8c72996bdcae9ea4a981b6afc0a40986523525aaa5491c09ef9546c14becd272', bytes: 10040048 },
|
|
47
|
+
{ name: 'mimi_decoder_int8.onnx', sha256: 'd7b00abae02b2916f0be6d42bfbe14e87e0b4f1aaa25b1d5778a1f128edb6bb6', bytes: 22638621 },
|
|
48
|
+
{ name: 'LICENSE-upstream.txt', sha256: '23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3', bytes: 1023 },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
german: {
|
|
52
|
+
code: 'de',
|
|
53
|
+
dir: 'de',
|
|
54
|
+
nativeVoice: 'alba',
|
|
55
|
+
files: [
|
|
56
|
+
{ name: 'bundle.json', sha256: '7e43fa70568f3a1800a7dfeab6b3f97e2b5f1ff682c11db9cf22103d53f5fea5', bytes: 13623 },
|
|
57
|
+
{ name: 'tokenizer.json', sha256: '2d77849811e3d1b6ae80e5b11b203f57e1847901104d8a0573b34f46f8dddb53', bytes: 245966 },
|
|
58
|
+
{ name: 'voices.bin', sha256: 'a45485ca28c8f046f6e45089d7b01ea45e9a2d36f1ac4cb0947a956b27f4a70d', bytes: 52404520 },
|
|
59
|
+
{ name: 'text_conditioner_int8.onnx', sha256: '0479f6bc635fedf130086c357d013a6a0c54568b301d9b255ffd67d732965378', bytes: 16388338 },
|
|
60
|
+
{ name: 'flow_lm_main_int8.onnx', sha256: '96cb9a628438ca4b26d7ed3160d79bd8ad2e0f097d08a8faea95e00c944ea84e', bytes: 76397201 },
|
|
61
|
+
{ name: 'flow_lm_flow_int8.onnx', sha256: '6198087a456287420d14b98083cd534bee3e92fa107dca1324f03a27c65c8315', bytes: 10040048 },
|
|
62
|
+
{ name: 'mimi_decoder_int8.onnx', sha256: '3d0f9574384d73c91404514b933e239333d9580bc42c8fcc161e5402ff67d6b9', bytes: 22638621 },
|
|
63
|
+
{ name: 'LICENSE-upstream.txt', sha256: '23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3', bytes: 1023 },
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
spanish: {
|
|
67
|
+
code: 'es',
|
|
68
|
+
dir: 'es',
|
|
69
|
+
nativeVoice: 'alba',
|
|
70
|
+
files: [
|
|
71
|
+
{ name: 'bundle.json', sha256: '196151a61b907afb2b0ccb4570a4c39993de69d705b371d38ae459120f6aac23', bytes: 13654 },
|
|
72
|
+
{ name: 'tokenizer.json', sha256: '9ade09bbdc64ab2b59952b90773fa0890b780ece4fd5aef0d36a00c6ad5f0531', bytes: 246610 },
|
|
73
|
+
{ name: 'voices.bin', sha256: '49a8e4d3562074a1e8d041edb4fad3877b327daf4cd898893ff10273216ae178', bytes: 52404520 },
|
|
74
|
+
{ name: 'text_conditioner_int8.onnx', sha256: '8e98c0abd4ba06fde1db0decb75e3b211e6097ba15854fc9266aa1d16feaeae4', bytes: 16388338 },
|
|
75
|
+
{ name: 'flow_lm_main_int8.onnx', sha256: 'f37c8b4a2409de010f638529daf947b863396a78b8b659a77ed6e35362174629', bytes: 76397201 },
|
|
76
|
+
{ name: 'flow_lm_flow_int8.onnx', sha256: 'b3f028c3cdd909ffa10dffa8055edc9147f273e43bda852733e6a4a36cc3d292', bytes: 10040048 },
|
|
77
|
+
{ name: 'mimi_decoder_int8.onnx', sha256: 'f2f1b6e380a6388557768534d24036cb8b549b9f4eb49bedbb7ed3c4fb06336a', bytes: 22638621 },
|
|
78
|
+
{ name: 'LICENSE-upstream.txt', sha256: '23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3', bytes: 1023 },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
portuguese: {
|
|
82
|
+
code: 'pt',
|
|
83
|
+
dir: 'pt',
|
|
84
|
+
nativeVoice: 'alba',
|
|
85
|
+
files: [
|
|
86
|
+
{ name: 'bundle.json', sha256: '4b23a635bd375e5d476416cc960ad7488aabd4441aea2861eaf54d98734ea34b', bytes: 13624 },
|
|
87
|
+
{ name: 'tokenizer.json', sha256: 'b33e269f7f042a763080d71ba087d74d2f6759674b238a723c028e436b1a25ab', bytes: 247014 },
|
|
88
|
+
{ name: 'voices.bin', sha256: '402d569dcb5d25c5b93cae6995d6d4d499cf1bfc591ed8edf2ce50547a8b3651', bytes: 52404520 },
|
|
89
|
+
{ name: 'text_conditioner_int8.onnx', sha256: '22ee9182a3dadc37ba06cdf3ff9c0e0ac0622f006a2eb29d2f5e0a13ba642d3e', bytes: 16388338 },
|
|
90
|
+
{ name: 'flow_lm_main_int8.onnx', sha256: '15357eb39cbd574bc4193fef960d6b332a861c84bfcf99e9417316bac129d1d8', bytes: 76397201 },
|
|
91
|
+
{ name: 'flow_lm_flow_int8.onnx', sha256: 'f2e2a3da0fb5c1e6b472f1921459f7e6c051fa54c25e08186b46d559d620b379', bytes: 10040048 },
|
|
92
|
+
{ name: 'mimi_decoder_int8.onnx', sha256: '6974a4330bbbfe91fcc46084b26e769c8eefd6121bd3ad42e84861f9f05854b2', bytes: 22638621 },
|
|
93
|
+
{ name: 'LICENSE-upstream.txt', sha256: '23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3', bytes: 1023 },
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
italian: {
|
|
97
|
+
code: 'it',
|
|
98
|
+
dir: 'it',
|
|
99
|
+
nativeVoice: 'alba',
|
|
100
|
+
files: [
|
|
101
|
+
{ name: 'bundle.json', sha256: '5dce446b175a8b9fd8766bde7ce3ee15fb396f2228b77777028c26eb88acfc4f', bytes: 13624 },
|
|
102
|
+
{ name: 'tokenizer.json', sha256: '4bc1c0d4d54f9480183e94c94cfabf74fd89b0912537d4ef607d1982c4a381ec', bytes: 246586 },
|
|
103
|
+
{ name: 'voices.bin', sha256: 'cf8f292f5d91d887f8370ebbd4329928421a87f564d475f53a7d456bf144acac', bytes: 52404520 },
|
|
104
|
+
{ name: 'text_conditioner_int8.onnx', sha256: 'f716f278fa279495889fbe8f4426da68d4ca5112b962121991ec8fed002ff090', bytes: 16388338 },
|
|
105
|
+
{ name: 'flow_lm_main_int8.onnx', sha256: '80c1ebae13a0033f7746f2b7a886e3d7fa3523c9d7be2122bec9412ad82c46b8', bytes: 76397201 },
|
|
106
|
+
{ name: 'flow_lm_flow_int8.onnx', sha256: 'b4da5f938b81d895eee0a8c6267162c6466382b761114affb96049db9e649431', bytes: 10040048 },
|
|
107
|
+
{ name: 'mimi_decoder_int8.onnx', sha256: 'c258c72d1b8079eb16a08fc9c6a255e918d897f53f784abcb5eaae2f3a0e9344', bytes: 22638621 },
|
|
108
|
+
{ name: 'LICENSE-upstream.txt', sha256: '23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3', bytes: 1023 },
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
dutch: {
|
|
112
|
+
code: 'nl',
|
|
113
|
+
dir: 'nl',
|
|
114
|
+
nativeVoice: 'alba',
|
|
115
|
+
files: [
|
|
116
|
+
{ name: 'bundle.json', sha256: '48581badbfe176db6df37ac0f784893fe2c681ae1e845263c4cd36106d8c1705', bytes: 13624 },
|
|
117
|
+
{ name: 'tokenizer.json', sha256: 'e6f610b98c427641b4ab0e1024dca7843e3d6b620871a14b204932e42c5a1736', bytes: 245206 },
|
|
118
|
+
{ name: 'voices.bin', sha256: '1e7f812d5824a931fef68337291896bd88521c9f031d545877e7f46b144ed38c', bytes: 52404520 },
|
|
119
|
+
{ name: 'text_conditioner_int8.onnx', sha256: '3bd2960e2ea136a8f870149f4238789f6dbcc54c1b643a4639b7be028e52fbb2', bytes: 16388338 },
|
|
120
|
+
{ name: 'flow_lm_main_int8.onnx', sha256: 'b6ae39189f6881ec0d87fa50ac690db239c6759c110e179714752b8b5d36e75c', bytes: 76397201 },
|
|
121
|
+
{ name: 'flow_lm_flow_int8.onnx', sha256: 'd0b3e7da6ef29c0c0a2e6f721b9c3b3835b93c3f3f2854f5882e11222f7450ea', bytes: 10040048 },
|
|
122
|
+
{ name: 'mimi_decoder_int8.onnx', sha256: '2cf5feebf7ba7486491c87a49036b0afae3093546aff3f5a46ec5e967b6c3ca5', bytes: 22638621 },
|
|
123
|
+
{ name: 'LICENSE-upstream.txt', sha256: '23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3', bytes: 1023 },
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
// Built-in voice names stored in every bundle's voices.bin (bundle.json `predefined_voices`).
|
|
128
|
+
export const POCKET_VOICES = [
|
|
129
|
+
'alba',
|
|
130
|
+
'azelma',
|
|
131
|
+
'cosette',
|
|
132
|
+
'eponine',
|
|
133
|
+
'fantine',
|
|
134
|
+
'javert',
|
|
135
|
+
'jean',
|
|
136
|
+
'marius',
|
|
137
|
+
];
|
|
138
|
+
export const ORT_VERSION = '1.31.1';
|
|
139
|
+
// The node package bundles the native binding for every platform (~115 MB compressed);
|
|
140
|
+
// `postinstall` only fetches optional CUDA binaries and is never run.
|
|
141
|
+
export const ORT_TARBALLS = {
|
|
142
|
+
node: {
|
|
143
|
+
url: 'https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.31.1.tgz',
|
|
144
|
+
integrity: 'sha512-ijnSghbDHVWaQ2nDPmVccPlCHI8kH1Mx1aJ4a/qzRP16bBcVs4E3EqZQKZCkhWnbqN1tuQWxagimFtDpbPYYQw==',
|
|
145
|
+
},
|
|
146
|
+
common: {
|
|
147
|
+
url: 'https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.31.1.tgz',
|
|
148
|
+
integrity: 'sha512-F+nnYNiQtmNJ95V6R/isBJqiVpdANCrsMEg1OaF+Bkbl3GAtzWLR7Ng17Ld0QtYtYJyotOHPJzOQn1Y6PLZjpg==',
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
export const POCKET_SAMPLE_RATE = 24000;
|
|
152
|
+
export const INFERENCE_SOURCE = 'own-loop';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BuiltinSpeaker } from '../../cli/web/voice_proxy.js';
|
|
2
|
+
import { type PocketLanguage } from './catalog.js';
|
|
3
|
+
import { type OrtModule, type PocketModel } from './inference.js';
|
|
4
|
+
export type { PocketModel } from './inference.js';
|
|
5
|
+
export type ModelLoader = (lang: PocketLanguage) => Promise<PocketModel>;
|
|
6
|
+
export declare const PCM_CONTENT_TYPE = "audio/pcm;rate=24000;channels=1";
|
|
7
|
+
/** True once the native runtime is loaded into this process (its files are then in use). */
|
|
8
|
+
export declare const runtimeLoaded: () => boolean;
|
|
9
|
+
/** onnxruntime-node from the downloaded runtime. Throws a readable error when it is
|
|
10
|
+
* missing or cannot load on this system (the reason is kept for `runtimeLoadError`). */
|
|
11
|
+
export declare function loadOnnxRuntime(): OrtModule;
|
|
12
|
+
/** Why the installed runtime cannot load, probing it once if never tried. */
|
|
13
|
+
export declare function runtimeLoadError(): string | undefined;
|
|
14
|
+
export declare function setModelLoaderForTest(l: ModelLoader | null): void;
|
|
15
|
+
export declare function releasePocketModels(): Promise<void>;
|
|
16
|
+
export declare const speakBuiltin: BuiltinSpeaker;
|
|
17
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/voice/pocket/engine.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAuD,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AACxG,OAAO,EAAqB,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGrF,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAEzE,eAAO,MAAM,gBAAgB,oCAAoD,CAAC;AAKlF,4FAA4F;AAC5F,eAAO,MAAM,aAAa,eAAqB,CAAC;AAEhD;yFACyF;AACzF,wBAAgB,eAAe,IAAI,SAAS,CAY3C;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CASrD;AASD,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAEjE;AA4BD,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAIzD;AAaD,eAAO,MAAM,YAAY,EAAE,cAsD1B,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// The built-in voice engine: one warm Pocket model per language, calls on a model
|
|
2
|
+
// serialized, PCM int16 LE streamed back as it is generated. The ONNX runtime is the
|
|
3
|
+
// one the installer downloaded, loaded by absolute path (never a package dependency).
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import { POCKET_LANGUAGES, POCKET_SAMPLE_RATE, POCKET_VOICES } from './catalog.js';
|
|
8
|
+
import { createPocketModel } from './inference.js';
|
|
9
|
+
import { bundleDir, runtimeEntry } from './install.js';
|
|
10
|
+
export const PCM_CONTENT_TYPE = `audio/pcm;rate=${POCKET_SAMPLE_RATE};channels=1`;
|
|
11
|
+
let ort = null;
|
|
12
|
+
let lastLoadError;
|
|
13
|
+
/** True once the native runtime is loaded into this process (its files are then in use). */
|
|
14
|
+
export const runtimeLoaded = () => ort !== null;
|
|
15
|
+
/** onnxruntime-node from the downloaded runtime. Throws a readable error when it is
|
|
16
|
+
* missing or cannot load on this system (the reason is kept for `runtimeLoadError`). */
|
|
17
|
+
export function loadOnnxRuntime() {
|
|
18
|
+
if (ort)
|
|
19
|
+
return ort;
|
|
20
|
+
const entry = runtimeEntry();
|
|
21
|
+
if (!existsSync(entry))
|
|
22
|
+
throw new Error('The built-in voice runtime is not installed.');
|
|
23
|
+
try {
|
|
24
|
+
ort = createRequire(entry)(entry);
|
|
25
|
+
lastLoadError = undefined;
|
|
26
|
+
return ort;
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
lastLoadError = e instanceof Error ? e.message : String(e);
|
|
30
|
+
throw new Error(`The built-in voice runtime could not be loaded: ${lastLoadError}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Why the installed runtime cannot load, probing it once if never tried. */
|
|
34
|
+
export function runtimeLoadError() {
|
|
35
|
+
if (!ort && existsSync(runtimeEntry())) {
|
|
36
|
+
try {
|
|
37
|
+
loadOnnxRuntime();
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
/* recorded in lastLoadError */
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return lastLoadError;
|
|
44
|
+
}
|
|
45
|
+
// ponytail: physical cores capped at 4 — measured on a 6-core Zen 1: 4 threads
|
|
46
|
+
// slightly beat 6, 12 halved the speed. Make it a setting if other machines disagree.
|
|
47
|
+
const threads = () => Math.min(4, Math.max(1, Math.floor(os.availableParallelism() / 2)));
|
|
48
|
+
const defaultLoader = async (lang) => createPocketModel(loadOnnxRuntime(), bundleDir(lang), { threads: threads() });
|
|
49
|
+
let loader = defaultLoader;
|
|
50
|
+
export function setModelLoaderForTest(l) {
|
|
51
|
+
loader = l ?? defaultLoader;
|
|
52
|
+
}
|
|
53
|
+
const slots = new Map();
|
|
54
|
+
function closeSlot(s) {
|
|
55
|
+
void s.tail
|
|
56
|
+
.then(() => s.model)
|
|
57
|
+
.then((m) => m.close())
|
|
58
|
+
.catch(() => { });
|
|
59
|
+
}
|
|
60
|
+
function slotFor(lang) {
|
|
61
|
+
let s = slots.get(lang);
|
|
62
|
+
if (s)
|
|
63
|
+
return s;
|
|
64
|
+
for (const [other, o] of slots) {
|
|
65
|
+
slots.delete(other);
|
|
66
|
+
closeSlot(o);
|
|
67
|
+
}
|
|
68
|
+
s = { model: loader(lang), tail: Promise.resolve() };
|
|
69
|
+
s.model.catch(() => slots.get(lang) === s && slots.delete(lang));
|
|
70
|
+
slots.set(lang, s);
|
|
71
|
+
return s;
|
|
72
|
+
}
|
|
73
|
+
export async function releasePocketModels() {
|
|
74
|
+
const all = [...slots.values()];
|
|
75
|
+
slots.clear();
|
|
76
|
+
await Promise.all(all.map((s) => s.tail.then(() => s.model).then((m) => m.close()).catch(() => { })));
|
|
77
|
+
}
|
|
78
|
+
function toPcm16(samples) {
|
|
79
|
+
const out = new DataView(new ArrayBuffer(samples.length * 2));
|
|
80
|
+
for (let i = 0; i < samples.length; i++) {
|
|
81
|
+
const s = Math.max(-1, Math.min(1, samples[i]));
|
|
82
|
+
out.setInt16(i * 2, Math.round(s < 0 ? s * 32768 : s * 32767), true);
|
|
83
|
+
}
|
|
84
|
+
return new Uint8Array(out.buffer);
|
|
85
|
+
}
|
|
86
|
+
const text = (status, body) => new Response(body, { status });
|
|
87
|
+
export const speakBuiltin = async (voice, input, signal) => {
|
|
88
|
+
const lang = voice.ttsLanguage;
|
|
89
|
+
const spec = Object.hasOwn(POCKET_LANGUAGES, lang ?? '') ? POCKET_LANGUAGES[lang] : null;
|
|
90
|
+
if (!spec)
|
|
91
|
+
return text(400, `Unknown built-in voice language: ${voice.ttsLanguage ?? '(none)'}.`);
|
|
92
|
+
if (!existsSync(runtimeEntry()))
|
|
93
|
+
return text(409, 'The built-in voice runtime is not installed. Install a language in Settings → Voice.');
|
|
94
|
+
if (!existsSync(bundleDir(lang)))
|
|
95
|
+
return text(409, `The ${lang} built-in voice is not installed. Install it in Settings → Voice.`);
|
|
96
|
+
const name = voice.ttsVoice && POCKET_VOICES.includes(voice.ttsVoice) ? voice.ttsVoice : spec.nativeVoice;
|
|
97
|
+
// Take a turn on this language's model: calls run one at a time, in arrival order.
|
|
98
|
+
const slot = slotFor(lang);
|
|
99
|
+
let release;
|
|
100
|
+
const prev = slot.tail;
|
|
101
|
+
slot.tail = new Promise((r) => (release = r));
|
|
102
|
+
await prev;
|
|
103
|
+
let model;
|
|
104
|
+
try {
|
|
105
|
+
model = await slot.model;
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
release();
|
|
109
|
+
return text(500, e instanceof Error ? e.message : String(e));
|
|
110
|
+
}
|
|
111
|
+
if (signal.aborted) {
|
|
112
|
+
release();
|
|
113
|
+
return new Response(null, { status: 204 });
|
|
114
|
+
}
|
|
115
|
+
const ac = new AbortController();
|
|
116
|
+
const onAbort = () => ac.abort();
|
|
117
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
118
|
+
const body = new ReadableStream({
|
|
119
|
+
start(controller) {
|
|
120
|
+
void (async () => {
|
|
121
|
+
try {
|
|
122
|
+
for await (const frame of model.synthesize(input, name, ac.signal)) {
|
|
123
|
+
if (ac.signal.aborted)
|
|
124
|
+
break;
|
|
125
|
+
controller.enqueue(toPcm16(frame));
|
|
126
|
+
}
|
|
127
|
+
if (!ac.signal.aborted)
|
|
128
|
+
controller.close();
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
if (!ac.signal.aborted)
|
|
132
|
+
controller.error(e);
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
signal.removeEventListener('abort', onAbort);
|
|
136
|
+
release();
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
},
|
|
140
|
+
cancel() {
|
|
141
|
+
ac.abort();
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return new Response(body, { headers: { 'content-type': PCM_CONTENT_TYPE } });
|
|
145
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface PocketModel {
|
|
2
|
+
readonly sampleRate: number;
|
|
3
|
+
synthesize(text: string, voice: string, signal: AbortSignal): AsyncIterable<Float32Array>;
|
|
4
|
+
close(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export interface OrtTensor {
|
|
7
|
+
readonly data: unknown;
|
|
8
|
+
readonly dims: readonly number[];
|
|
9
|
+
}
|
|
10
|
+
export interface OrtSession {
|
|
11
|
+
run(feeds: Record<string, OrtTensor>): Promise<Record<string, OrtTensor>>;
|
|
12
|
+
release(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface OrtModule {
|
|
15
|
+
InferenceSession: {
|
|
16
|
+
create(path: string, options?: {
|
|
17
|
+
intraOpNumThreads?: number;
|
|
18
|
+
interOpNumThreads?: number;
|
|
19
|
+
executionMode?: 'sequential' | 'parallel';
|
|
20
|
+
}): Promise<OrtSession>;
|
|
21
|
+
};
|
|
22
|
+
Tensor: new (type: 'float32' | 'int64' | 'bool', data: Float32Array | BigInt64Array | Uint8Array, dims: readonly number[]) => OrtTensor;
|
|
23
|
+
}
|
|
24
|
+
export declare const POCKET_GRAPHS: {
|
|
25
|
+
readonly textConditioner: "text_conditioner_int8.onnx";
|
|
26
|
+
readonly flowMain: "flow_lm_main_int8.onnx";
|
|
27
|
+
readonly flowStep: "flow_lm_flow_int8.onnx";
|
|
28
|
+
readonly mimi: "mimi_decoder_int8.onnx";
|
|
29
|
+
};
|
|
30
|
+
export declare const POCKET_VOICES_FILE = "voices.bin";
|
|
31
|
+
export declare const DEFAULT_FRAMES_PER_DECODE = 4;
|
|
32
|
+
export declare function createPocketModel(ort: OrtModule, bundleDir: string, opts: {
|
|
33
|
+
threads: number;
|
|
34
|
+
framesPerDecode?: number;
|
|
35
|
+
}): Promise<PocketModel>;
|
|
36
|
+
//# sourceMappingURL=inference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference.d.ts","sourceRoot":"","sources":["../../../src/voice/pocket/inference.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;IAC1F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAGD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AACD,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAC1E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AACD,MAAM,WAAW,SAAS;IACxB,gBAAgB,EAAE;QAChB,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;YACR,iBAAiB,CAAC,EAAE,MAAM,CAAC;YAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;YAC3B,aAAa,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;SAC3C,GACA,OAAO,CAAC,UAAU,CAAC,CAAC;KACxB,CAAC;IACF,MAAM,EAAE,KACN,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,EAClC,IAAI,EAAE,YAAY,GAAG,aAAa,GAAG,UAAU,EAC/C,IAAI,EAAE,SAAS,MAAM,EAAE,KACpB,SAAS,CAAC;CAChB;AAGD,eAAO,MAAM,aAAa;;;;;CAKhB,CAAC;AACX,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAiD/C,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,GAClD,OAAO,CAAC,WAAW,CAAC,CAmCtB"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Own inference loop over one Pocket TTS schema-3 ONNX bundle (four graphs with explicit
|
|
2
|
+
// streaming state), following upstream pocket_tts at the bundle's upstream commit:
|
|
3
|
+
// tokenizer -> text conditioner -> flow LM main (prompted with the text on top of the
|
|
4
|
+
// voice's KV cache) -> per frame: flow step(s) on gaussian noise -> mimi decoder.
|
|
5
|
+
// The ONNX runtime is passed in (downloaded at runtime, never a package dependency).
|
|
6
|
+
import { readFile } from 'node:fs/promises';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { UnigramTokenizer, prepareChunks } from './tokenizer.js';
|
|
9
|
+
import { padInto, parseVoices } from './voices.js';
|
|
10
|
+
// Not named in bundle.json; these are the bundle's file names (see catalog.ts).
|
|
11
|
+
export const POCKET_GRAPHS = {
|
|
12
|
+
textConditioner: 'text_conditioner_int8.onnx',
|
|
13
|
+
flowMain: 'flow_lm_main_int8.onnx',
|
|
14
|
+
flowStep: 'flow_lm_flow_int8.onnx',
|
|
15
|
+
mimi: 'mimi_decoder_int8.onnx',
|
|
16
|
+
};
|
|
17
|
+
export const POCKET_VOICES_FILE = 'voices.bin';
|
|
18
|
+
// upstream TTSModel._TOKENS_PER_SECOND_ESTIMATE / _GEN_SECONDS_PADDING
|
|
19
|
+
const TOKENS_PER_SECOND = 3;
|
|
20
|
+
// The bundle's eos_threshold (-4, upstream's float default) is crossed by these int8
|
|
21
|
+
// graphs at random points mid-sentence, cutting the rest of it. Measured on the Italian
|
|
22
|
+
// bundle: real ends score 1.9..28, spurious crossings -3.9..-0.9 (as early as 2 s into a
|
|
23
|
+
// 6 s sentence). Only a confident crossing ends a chunk; maxGen still bounds it.
|
|
24
|
+
const CONFIDENT_EOS_LOGIT = 0;
|
|
25
|
+
// Some voices still signal the end a moment before the last syllable is out; a few
|
|
26
|
+
// more frames (80 ms each) keep it, at the cost of a slightly longer pause.
|
|
27
|
+
const EXTRA_FRAMES_AFTER_EOS = 4;
|
|
28
|
+
const GEN_SECONDS_PADDING = 2;
|
|
29
|
+
// Latent frames decoded per mimi call. A mimi call has a large fixed cost (it rewrites its
|
|
30
|
+
// whole streaming KV cache, measured ~70 ms on the reference machine against ~6 ms per
|
|
31
|
+
// extra frame), so decoding one frame at a time runs below real time; 4 frames keep
|
|
32
|
+
// generation ahead of playback from the first group on (~1.5x real time there).
|
|
33
|
+
export const DEFAULT_FRAMES_PER_DECODE = 4;
|
|
34
|
+
export async function createPocketModel(ort, bundleDir, opts) {
|
|
35
|
+
const bundle = JSON.parse(await readFile(join(bundleDir, 'bundle.json'), 'utf8'));
|
|
36
|
+
if (bundle.schema_version !== 3)
|
|
37
|
+
throw new Error(`unsupported Pocket bundle schema ${bundle.schema_version}`);
|
|
38
|
+
if (!bundle.voice_state_includes_bos)
|
|
39
|
+
throw new Error('Pocket bundle voices without BOS are not supported');
|
|
40
|
+
const tokenizer = new UnigramTokenizer(JSON.parse(await readFile(join(bundleDir, bundle.tokenizer_file), 'utf8')));
|
|
41
|
+
const voices = parseVoices(await readFile(join(bundleDir, POCKET_VOICES_FILE)));
|
|
42
|
+
const sessionOptions = {
|
|
43
|
+
intraOpNumThreads: Math.max(1, opts.threads),
|
|
44
|
+
interOpNumThreads: 1,
|
|
45
|
+
executionMode: 'sequential',
|
|
46
|
+
};
|
|
47
|
+
const sessions = [];
|
|
48
|
+
try {
|
|
49
|
+
for (const file of Object.values(POCKET_GRAPHS)) {
|
|
50
|
+
sessions.push(await ort.InferenceSession.create(join(bundleDir, file), sessionOptions));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
await Promise.allSettled(sessions.map((s) => s.release()));
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
const [textConditioner, flowMain, flowStep, mimi] = sessions;
|
|
58
|
+
const framesPerDecode = Math.max(1, opts.framesPerDecode ?? DEFAULT_FRAMES_PER_DECODE);
|
|
59
|
+
return new Model(ort, bundle, tokenizer, voices, { textConditioner, flowMain, flowStep, mimi }, framesPerDecode);
|
|
60
|
+
}
|
|
61
|
+
class Model {
|
|
62
|
+
ort;
|
|
63
|
+
bundle;
|
|
64
|
+
tokenizer;
|
|
65
|
+
voices;
|
|
66
|
+
s;
|
|
67
|
+
framesPerDecode;
|
|
68
|
+
sampleRate;
|
|
69
|
+
// The padded flow state of the last voice used (~50 MB each, so only one is kept).
|
|
70
|
+
voiceFeeds = null;
|
|
71
|
+
mimiInitial;
|
|
72
|
+
closed = false;
|
|
73
|
+
constructor(ort, bundle, tokenizer, voices, s, framesPerDecode) {
|
|
74
|
+
this.ort = ort;
|
|
75
|
+
this.bundle = bundle;
|
|
76
|
+
this.tokenizer = tokenizer;
|
|
77
|
+
this.voices = voices;
|
|
78
|
+
this.s = s;
|
|
79
|
+
this.framesPerDecode = framesPerDecode;
|
|
80
|
+
this.sampleRate = bundle.sample_rate;
|
|
81
|
+
this.mimiInitial = Object.fromEntries(bundle.mimi_state_manifest.map((e) => [e.input_name, this.filled(e)]));
|
|
82
|
+
}
|
|
83
|
+
async *synthesize(text, voice, signal) {
|
|
84
|
+
if (this.closed)
|
|
85
|
+
throw new Error('Pocket model is closed');
|
|
86
|
+
const voiceState = this.voiceState(voice);
|
|
87
|
+
for (const chunk of prepareChunks(text, this.tokenizer, this.bundle)) {
|
|
88
|
+
if (signal.aborted)
|
|
89
|
+
return;
|
|
90
|
+
const framesAfterEos = (this.bundle.model_recommended_frames_after_eos ?? chunk.framesAfterEos) + EXTRA_FRAMES_AFTER_EOS;
|
|
91
|
+
for await (const frame of this.chunk(chunk.tokenIds, voiceState, framesAfterEos, signal)) {
|
|
92
|
+
yield frame;
|
|
93
|
+
if (signal.aborted)
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async close() {
|
|
99
|
+
if (this.closed)
|
|
100
|
+
return;
|
|
101
|
+
this.closed = true;
|
|
102
|
+
await Promise.allSettled(Object.values(this.s).map((s) => s.release()));
|
|
103
|
+
}
|
|
104
|
+
// One chunk, from the voice's own state (upstream copy_state=True). ORT never writes
|
|
105
|
+
// into its inputs, so the cached voice tensors are reused as is.
|
|
106
|
+
async *chunk(ids, voiceState, framesAfterEos, signal) {
|
|
107
|
+
const { ort, bundle } = this;
|
|
108
|
+
const ldim = bundle.latent_dim;
|
|
109
|
+
const tokens = new ort.Tensor('int64', BigInt64Array.from(ids, BigInt), [1, ids.length]);
|
|
110
|
+
const { text_embeddings } = await this.s.textConditioner.run({ token_ids: tokens });
|
|
111
|
+
// Prompt the text into the KV cache; the outputs other than the state are unused.
|
|
112
|
+
let out = await this.s.flowMain.run({
|
|
113
|
+
sequence: new ort.Tensor('float32', new Float32Array(0), [1, 0, ldim]),
|
|
114
|
+
text_embeddings,
|
|
115
|
+
...voiceState,
|
|
116
|
+
});
|
|
117
|
+
let flowState = nextState(out, bundle.flow_lm_state_manifest);
|
|
118
|
+
let mimiState = this.mimiInitial;
|
|
119
|
+
const noText = new ort.Tensor('float32', new Float32Array(0), [1, 0, bundle.conditioning_dim]);
|
|
120
|
+
// NaN means BOS: the graph swaps in its learned BOS latent.
|
|
121
|
+
let sequence = new ort.Tensor('float32', new Float32Array(ldim).fill(NaN), [1, 1, ldim]);
|
|
122
|
+
const maxGen = Math.ceil((ids.length / TOKENS_PER_SECOND + GEN_SECONDS_PADDING) *
|
|
123
|
+
(bundle.sample_rate / bundle.samples_per_frame));
|
|
124
|
+
let eosStep = null;
|
|
125
|
+
const eosThreshold = Math.max(bundle.eos_threshold, CONFIDENT_EOS_LOGIT);
|
|
126
|
+
const pending = [];
|
|
127
|
+
const decode = async () => {
|
|
128
|
+
const latents = new Float32Array(pending.length * ldim);
|
|
129
|
+
pending.forEach((l, i) => latents.set(l, i * ldim));
|
|
130
|
+
const latent = new ort.Tensor('float32', latents, [1, pending.length, ldim]);
|
|
131
|
+
pending.length = 0;
|
|
132
|
+
const decoded = await this.s.mimi.run({ latent, ...mimiState });
|
|
133
|
+
mimiState = nextState(decoded, bundle.mimi_state_manifest);
|
|
134
|
+
return decoded.audio.data;
|
|
135
|
+
};
|
|
136
|
+
for (let step = 0; step < maxGen; step++) {
|
|
137
|
+
if (signal.aborted)
|
|
138
|
+
return;
|
|
139
|
+
out = await this.s.flowMain.run({ sequence, text_embeddings: noText, ...flowState });
|
|
140
|
+
flowState = nextState(out, bundle.flow_lm_state_manifest);
|
|
141
|
+
const eosLogit = out.eos_logit.data;
|
|
142
|
+
const logit = eosLogit[eosLogit.length - 1];
|
|
143
|
+
if (eosStep === null && step >= bundle.min_frames_before_eos && logit > eosThreshold)
|
|
144
|
+
eosStep = step;
|
|
145
|
+
// This step's latent is not emitted.
|
|
146
|
+
if (eosStep !== null && step >= eosStep + framesAfterEos)
|
|
147
|
+
break;
|
|
148
|
+
const latent = await this.sampleLatent(out.conditioning);
|
|
149
|
+
sequence = new ort.Tensor('float32', latent, [1, 1, ldim]);
|
|
150
|
+
pending.push(latent);
|
|
151
|
+
if (pending.length >= this.framesPerDecode)
|
|
152
|
+
yield await decode();
|
|
153
|
+
}
|
|
154
|
+
if (pending.length > 0 && !signal.aborted)
|
|
155
|
+
yield await decode();
|
|
156
|
+
}
|
|
157
|
+
// lsd_decode over the flow net, starting from gaussian noise (std sqrt(temperature)).
|
|
158
|
+
async sampleLatent(conditioning) {
|
|
159
|
+
const { ort, bundle } = this;
|
|
160
|
+
const dim = bundle.conditioning_dim;
|
|
161
|
+
const all = conditioning.data;
|
|
162
|
+
// upstream keeps the last position only.
|
|
163
|
+
const c = new ort.Tensor('float32', all.subarray(all.length - dim), [1, dim]);
|
|
164
|
+
const x = gaussian(bundle.latent_dim, Math.sqrt(bundle.temperature), bundle.noise_clamp);
|
|
165
|
+
const steps = bundle.sampler_decode_steps;
|
|
166
|
+
for (let i = 0; i < steps; i++) {
|
|
167
|
+
const { flow_dir } = await this.s.flowStep.run({
|
|
168
|
+
c,
|
|
169
|
+
s: new ort.Tensor('float32', Float32Array.of(i / steps), [1, 1]),
|
|
170
|
+
t: new ort.Tensor('float32', Float32Array.of((i + 1) / steps), [1, 1]),
|
|
171
|
+
x: new ort.Tensor('float32', x.slice(), [1, bundle.latent_dim]),
|
|
172
|
+
});
|
|
173
|
+
const dir = flow_dir.data;
|
|
174
|
+
for (let k = 0; k < x.length; k++)
|
|
175
|
+
x[k] += dir[k] / steps;
|
|
176
|
+
}
|
|
177
|
+
return x;
|
|
178
|
+
}
|
|
179
|
+
voiceState(voice) {
|
|
180
|
+
if (this.voiceFeeds?.voice === voice)
|
|
181
|
+
return this.voiceFeeds.feeds;
|
|
182
|
+
const tensors = this.voices.get(voice);
|
|
183
|
+
if (!tensors)
|
|
184
|
+
throw new Error(`unknown Pocket voice "${voice}"`);
|
|
185
|
+
const feeds = {};
|
|
186
|
+
for (const e of this.bundle.flow_lm_state_manifest) {
|
|
187
|
+
const t = tensors.get(`${e.module}/${e.key}`);
|
|
188
|
+
feeds[e.input_name] = t
|
|
189
|
+
? new this.ort.Tensor(e.dtype, padInto(t, e.shape), e.shape)
|
|
190
|
+
: this.filled(e);
|
|
191
|
+
}
|
|
192
|
+
this.voiceFeeds = { voice, feeds };
|
|
193
|
+
return feeds;
|
|
194
|
+
}
|
|
195
|
+
filled(e) {
|
|
196
|
+
const n = e.shape.reduce((a, b) => a * b, 1);
|
|
197
|
+
const one = e.fill === 'ones';
|
|
198
|
+
const data = e.dtype === 'float32'
|
|
199
|
+
? new Float32Array(n).fill(one ? 1 : 0)
|
|
200
|
+
: e.dtype === 'int64'
|
|
201
|
+
? new BigInt64Array(n).fill(one ? 1n : 0n)
|
|
202
|
+
: new Uint8Array(n).fill(one ? 1 : 0);
|
|
203
|
+
return new this.ort.Tensor(e.dtype, data, e.shape);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function nextState(out, manifest) {
|
|
207
|
+
const feeds = {};
|
|
208
|
+
for (const e of manifest) {
|
|
209
|
+
const t = out[e.output_name];
|
|
210
|
+
if (!t)
|
|
211
|
+
throw new Error(`graph output ${e.output_name} is missing`);
|
|
212
|
+
feeds[e.input_name] = t;
|
|
213
|
+
}
|
|
214
|
+
return feeds;
|
|
215
|
+
}
|
|
216
|
+
// Box-Muller; a clamp resamples out-of-range draws (torch trunc_normal_ semantics).
|
|
217
|
+
function gaussian(n, std, clamp) {
|
|
218
|
+
const out = new Float32Array(n);
|
|
219
|
+
for (let i = 0; i < n; i++) {
|
|
220
|
+
let v;
|
|
221
|
+
do {
|
|
222
|
+
const u = 1 - Math.random();
|
|
223
|
+
v = std * Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * Math.random());
|
|
224
|
+
} while (clamp !== null && Math.abs(v) > clamp);
|
|
225
|
+
out[i] = v;
|
|
226
|
+
}
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { PronunciationEntry } from 'caretaker-types';
|
|
2
|
+
import { ORT_TARBALLS, POCKET_LANGUAGES, type PocketLanguage } from './catalog.js';
|
|
3
|
+
import { WHISPER_MODELS, type WhisperSize } from '../whisper/catalog.js';
|
|
4
|
+
export type BuiltinVoiceStatus = {
|
|
5
|
+
runtime: {
|
|
6
|
+
installed: boolean;
|
|
7
|
+
version: string;
|
|
8
|
+
loadError?: string;
|
|
9
|
+
};
|
|
10
|
+
languages: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
code: string;
|
|
13
|
+
nativeVoice: string;
|
|
14
|
+
installed: boolean;
|
|
15
|
+
bytes: number;
|
|
16
|
+
}>;
|
|
17
|
+
stt: Array<{
|
|
18
|
+
id: WhisperSize;
|
|
19
|
+
installed: boolean;
|
|
20
|
+
bytes: number;
|
|
21
|
+
}>;
|
|
22
|
+
voices: string[];
|
|
23
|
+
defaults: Record<string, PronunciationEntry[]>;
|
|
24
|
+
};
|
|
25
|
+
export type BuiltinInstallProgress = {
|
|
26
|
+
step: 'runtime' | 'bundle' | 'model';
|
|
27
|
+
file: string;
|
|
28
|
+
received: number;
|
|
29
|
+
total: number;
|
|
30
|
+
} | {
|
|
31
|
+
step: 'done';
|
|
32
|
+
status: BuiltinVoiceStatus;
|
|
33
|
+
} | {
|
|
34
|
+
step: 'error';
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
type Catalog = {
|
|
38
|
+
languages: typeof POCKET_LANGUAGES;
|
|
39
|
+
tarballs: typeof ORT_TARBALLS;
|
|
40
|
+
ortVersion: string;
|
|
41
|
+
revision: string;
|
|
42
|
+
baseUrl: string;
|
|
43
|
+
whisper: typeof WHISPER_MODELS;
|
|
44
|
+
whisperBaseUrl: string;
|
|
45
|
+
};
|
|
46
|
+
export declare function __setCatalogForTest(c: Partial<Catalog>): void;
|
|
47
|
+
export declare function __setFetch(f: typeof fetch): void;
|
|
48
|
+
export declare function __resetFetch(): void;
|
|
49
|
+
export declare function runtimeDir(): string;
|
|
50
|
+
/** Absolute path of onnxruntime-node's entry file, for `createRequire(...)`. */
|
|
51
|
+
export declare function runtimeEntry(): string;
|
|
52
|
+
export declare function bundleDir(lang: PocketLanguage): string;
|
|
53
|
+
/** `<dataDir>/voice/whisper/<size>/<revision>`; the repo's `onnx/` subdirectory is kept. */
|
|
54
|
+
export declare function whisperDir(size: WhisperSize): string;
|
|
55
|
+
export declare function installBuiltinStt(size: WhisperSize): AsyncGenerator<BuiltinInstallProgress>;
|
|
56
|
+
export declare function installBuiltinVoice(lang: PocketLanguage): AsyncGenerator<BuiltinInstallProgress>;
|
|
57
|
+
/** Removes the language's bundle(s); removes the runtime too once nothing else needs it,
|
|
58
|
+
* unless `keepRuntime` (the native binding is loaded in this process: Windows refuses
|
|
59
|
+
* to delete it, and a half-deleted runtime would break reinstalling). */
|
|
60
|
+
export declare function deleteBuiltinVoice(lang: PocketLanguage, opts?: {
|
|
61
|
+
keepRuntime?: boolean;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
export declare function deleteBuiltinStt(size: WhisperSize, opts?: {
|
|
64
|
+
keepRuntime?: boolean;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
export declare function builtinVoiceStatus(): Promise<BuiltinVoiceStatus>;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=install.d.ts.map
|