@qvac/sdk 0.11.0 → 0.12.1

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 (211) hide show
  1. package/NOTICE +1423 -43
  2. package/README.md +2 -0
  3. package/dist/client/api/classify.d.ts +23 -0
  4. package/dist/client/api/classify.js +43 -0
  5. package/dist/client/api/get-model-info.d.ts +1 -1
  6. package/dist/client/api/index.d.ts +4 -0
  7. package/dist/client/api/index.js +4 -0
  8. package/dist/client/api/load-model.js +24 -1
  9. package/dist/client/api/transcribe.d.ts +3 -0
  10. package/dist/client/api/transcribe.js +13 -2
  11. package/dist/client/api/video.d.ts +64 -0
  12. package/dist/client/api/video.js +147 -0
  13. package/dist/client/api/vla-helpers.d.ts +45 -0
  14. package/dist/client/api/vla-helpers.js +130 -0
  15. package/dist/client/api/vla.d.ts +65 -0
  16. package/dist/client/api/vla.js +109 -0
  17. package/dist/client/config-loader/resolve-config.node.d.ts +16 -0
  18. package/dist/client/config-loader/resolve-config.node.js +77 -23
  19. package/dist/client/plugins-factory.d.ts +8 -0
  20. package/dist/client/plugins-factory.js +10 -0
  21. package/dist/client/rpc/bare-client.d.ts +1 -0
  22. package/dist/client/rpc/bare-client.js +66 -66
  23. package/dist/client/rpc/ensure-worker-ready.d.ts +9 -0
  24. package/dist/client/rpc/ensure-worker-ready.js +17 -0
  25. package/dist/client/rpc/expo-rpc-client.d.ts +1 -0
  26. package/dist/client/rpc/expo-rpc-client.js +4 -0
  27. package/dist/client/rpc/node-rpc-client.d.ts +1 -0
  28. package/dist/client/rpc/node-rpc-client.js +97 -5
  29. package/dist/client/rpc/rpc-client.js +115 -8
  30. package/dist/client/rpc/rpc-error.js +14 -1
  31. package/dist/commands/bundle/bare-pack.d.ts +13 -0
  32. package/dist/commands/bundle/bare-pack.js +54 -0
  33. package/dist/commands/bundle/constants.d.ts +7 -0
  34. package/dist/commands/bundle/constants.js +23 -0
  35. package/dist/commands/bundle/entry-gen.d.ts +2 -0
  36. package/dist/commands/bundle/entry-gen.js +48 -0
  37. package/dist/commands/bundle/index.d.ts +20 -0
  38. package/dist/commands/bundle/index.js +141 -0
  39. package/dist/commands/bundle/manifest.d.ts +21 -0
  40. package/dist/commands/bundle/manifest.js +193 -0
  41. package/dist/commands/bundle/plugins.d.ts +9 -0
  42. package/dist/commands/bundle/plugins.js +51 -0
  43. package/dist/commands/index.d.ts +5 -0
  44. package/dist/commands/index.js +2 -0
  45. package/dist/commands/verify/abi.d.ts +52 -0
  46. package/dist/commands/verify/abi.js +125 -0
  47. package/dist/commands/verify/addon-source.d.ts +43 -0
  48. package/dist/commands/verify/addon-source.js +75 -0
  49. package/dist/commands/verify/bundle-source.d.ts +12 -0
  50. package/dist/commands/verify/bundle-source.js +53 -0
  51. package/dist/commands/verify/index.d.ts +59 -0
  52. package/dist/commands/verify/index.js +371 -0
  53. package/dist/commands/verify/node-modules-source.d.ts +11 -0
  54. package/dist/commands/verify/node-modules-source.js +76 -0
  55. package/dist/commands/verify/prebuilds.d.ts +15 -0
  56. package/dist/commands/verify/prebuilds.js +39 -0
  57. package/dist/examples/classification/classify-image.d.ts +2 -0
  58. package/dist/examples/classification/classify-image.js +23 -0
  59. package/dist/examples/diffusion-txt2vid.d.ts +2 -0
  60. package/dist/examples/diffusion-txt2vid.js +81 -0
  61. package/dist/examples/plugins.js +3 -7
  62. package/dist/examples/tools/llamacpp-tools-gemma4.js +2 -5
  63. package/dist/examples/tools/llamacpp-tools-qwen35.js +2 -3
  64. package/dist/examples/transcription/parakeet-ctc-filesystem.js +18 -12
  65. package/dist/examples/transcription/parakeet-microphone-record.js +7 -12
  66. package/dist/examples/transcription/parakeet-microphone-stream.d.ts +2 -0
  67. package/dist/examples/transcription/parakeet-microphone-stream.js +79 -0
  68. package/dist/examples/transcription/parakeet-sortformer-streaming.d.ts +2 -0
  69. package/dist/examples/transcription/parakeet-sortformer-streaming.js +121 -0
  70. package/dist/examples/transcription/parakeet-sortformer.js +58 -55
  71. package/dist/examples/transcription/parakeet-tdt-filesystem.js +18 -15
  72. package/dist/examples/transcription/whispercpp-microphone-conversation.js +6 -1
  73. package/dist/examples/tts/chatterbox.js +7 -16
  74. package/dist/examples/tts/llm-to-tts-streaming.js +3 -10
  75. package/dist/examples/tts/supertonic-multilingual.js +4 -12
  76. package/dist/examples/tts/supertonic.js +5 -12
  77. package/dist/examples/vla-smolvla.d.ts +2 -0
  78. package/dist/examples/vla-smolvla.js +75 -0
  79. package/dist/examples/voice-assistant/voice-assistant.js +3 -10
  80. package/dist/expo/plugins/find-in-ancestor-node-modules.d.ts +14 -0
  81. package/dist/expo/plugins/find-in-ancestor-node-modules.js +24 -0
  82. package/dist/expo/plugins/get-project-root.d.ts +22 -0
  83. package/dist/expo/plugins/get-project-root.js +23 -0
  84. package/dist/expo/plugins/index.d.ts +4 -0
  85. package/dist/expo/plugins/index.js +4 -0
  86. package/dist/expo/plugins/resolve-sdk-package-dir.d.ts +9 -2
  87. package/dist/expo/plugins/resolve-sdk-package-dir.js +38 -11
  88. package/dist/expo/plugins/withDeviceInfo.js +2 -1
  89. package/dist/expo/plugins/withMobileBundle.d.ts +2 -17
  90. package/dist/expo/plugins/withMobileBundle.js +31 -85
  91. package/dist/index.d.ts +5 -3
  92. package/dist/index.js +9 -3
  93. package/dist/models/registry/models.d.ts +3711 -368
  94. package/dist/models/registry/models.js +7066 -3562
  95. package/dist/models/update-models/naming.js +22 -8
  96. package/dist/pear/pre.js +6 -2
  97. package/dist/schemas/cancel.d.ts +5 -0
  98. package/dist/schemas/cancel.js +1 -0
  99. package/dist/schemas/classification.d.ts +53 -0
  100. package/dist/schemas/classification.js +33 -0
  101. package/dist/schemas/common.d.ts +1001 -1739
  102. package/dist/schemas/common.js +6 -1
  103. package/dist/schemas/completion-event.d.ts +3 -0
  104. package/dist/schemas/completion-event.js +1 -0
  105. package/dist/schemas/completion-stream.d.ts +1 -0
  106. package/dist/schemas/download-asset.d.ts +13 -3
  107. package/dist/schemas/engine-addon-map.d.ts +3 -0
  108. package/dist/schemas/engine-addon-map.js +18 -5
  109. package/dist/schemas/get-model-info.d.ts +4 -0
  110. package/dist/schemas/get-model-info.js +2 -0
  111. package/dist/schemas/index.d.ts +3 -0
  112. package/dist/schemas/index.js +3 -0
  113. package/dist/schemas/llamacpp-config.d.ts +12 -2
  114. package/dist/schemas/load-model.d.ts +6152 -10764
  115. package/dist/schemas/load-model.js +75 -7
  116. package/dist/schemas/model-src-utils.d.ts +22 -2
  117. package/dist/schemas/model-types.d.ts +46 -6
  118. package/dist/schemas/model-types.js +28 -5
  119. package/dist/schemas/ocr.d.ts +5 -0
  120. package/dist/schemas/plugin.d.ts +20 -5
  121. package/dist/schemas/plugin.js +21 -4
  122. package/dist/schemas/registry.d.ts +44 -0
  123. package/dist/schemas/registry.js +5 -0
  124. package/dist/schemas/reload-config.d.ts +22 -2
  125. package/dist/schemas/sdcpp-config.d.ts +316 -1
  126. package/dist/schemas/sdcpp-config.js +232 -33
  127. package/dist/schemas/sdk-config.d.ts +654 -1324
  128. package/dist/schemas/sdk-config.js +16 -1
  129. package/dist/schemas/sdk-errors-client.d.ts +7 -0
  130. package/dist/schemas/sdk-errors-client.js +36 -1
  131. package/dist/schemas/sdk-errors-server.d.ts +3 -1
  132. package/dist/schemas/sdk-errors-server.js +20 -5
  133. package/dist/schemas/text-to-speech.d.ts +79 -696
  134. package/dist/schemas/text-to-speech.js +46 -19
  135. package/dist/schemas/transcription-config.d.ts +37 -226
  136. package/dist/schemas/transcription-config.js +76 -15
  137. package/dist/schemas/transcription.d.ts +63 -11
  138. package/dist/schemas/transcription.js +56 -2
  139. package/dist/schemas/translation-config.d.ts +60 -10
  140. package/dist/schemas/vla.d.ts +87 -0
  141. package/dist/schemas/vla.js +108 -0
  142. package/dist/scripts/run-unit-tests.js +8 -2
  143. package/dist/server/bare/ops/transcribe.d.ts +2 -1
  144. package/dist/server/bare/ops/transcribe.js +59 -34
  145. package/dist/server/bare/plugins/ggml-classification/ops/classify.d.ts +6 -0
  146. package/dist/server/bare/plugins/ggml-classification/ops/classify.js +30 -0
  147. package/dist/server/bare/plugins/ggml-classification/plugin.d.ts +32 -0
  148. package/dist/server/bare/plugins/ggml-classification/plugin.js +55 -0
  149. package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.d.ts +3 -0
  150. package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.js +12 -0
  151. package/dist/server/bare/plugins/ggml-vla/ops/vla-run.d.ts +3 -0
  152. package/dist/server/bare/plugins/ggml-vla/ops/vla-run.js +75 -0
  153. package/dist/server/bare/plugins/ggml-vla/plugin.d.ts +54 -0
  154. package/dist/server/bare/plugins/ggml-vla/plugin.js +57 -0
  155. package/dist/server/bare/plugins/index.d.ts +3 -1
  156. package/dist/server/bare/plugins/index.js +3 -1
  157. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +3 -0
  158. package/dist/server/bare/plugins/llamacpp-completion/ops/context-overflow.d.ts +29 -0
  159. package/dist/server/bare/plugins/llamacpp-completion/ops/context-overflow.js +65 -0
  160. package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +6 -0
  161. package/dist/server/bare/plugins/llamacpp-completion/plugin.js +26 -0
  162. package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +25 -0
  163. package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +5 -0
  164. package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +67 -246
  165. package/dist/server/bare/plugins/parakeet-transcription/plugin.js +66 -97
  166. package/dist/server/bare/plugins/sdcpp-generation/ops/video.d.ts +3 -0
  167. package/dist/server/bare/plugins/sdcpp-generation/ops/video.js +199 -0
  168. package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +200 -2
  169. package/dist/server/bare/plugins/sdcpp-generation/plugin.js +61 -8
  170. package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech-stream.js +2 -15
  171. package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech.js +2 -1
  172. package/dist/server/bare/plugins/tts-ggml/plugin.d.ts +75 -0
  173. package/dist/server/bare/plugins/tts-ggml/plugin.js +189 -0
  174. package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +29 -4
  175. package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +12 -1
  176. package/dist/server/bare/registry/model-config-utils.js +7 -0
  177. package/dist/server/bare/runtime/request-context.d.ts +1 -1
  178. package/dist/server/bare/runtime-lifecycle.js +9 -9
  179. package/dist/server/bare/types/addon-responses.d.ts +1 -0
  180. package/dist/server/env.js +4 -1
  181. package/dist/server/plugins/index.d.ts +1 -1
  182. package/dist/server/plugins/index.js +1 -1
  183. package/dist/server/plugins/registry.d.ts +1 -0
  184. package/dist/server/plugins/registry.js +5 -0
  185. package/dist/server/rpc/handler-registry.js +4 -0
  186. package/dist/server/rpc/handler-selection.d.ts +9 -0
  187. package/dist/server/rpc/handler-selection.js +14 -0
  188. package/dist/server/rpc/handler-utils.js +5 -13
  189. package/dist/server/rpc/handlers/classify.d.ts +3 -0
  190. package/dist/server/rpc/handlers/classify.js +4 -0
  191. package/dist/server/rpc/handlers/index.d.ts +2 -0
  192. package/dist/server/rpc/handlers/index.js +2 -0
  193. package/dist/server/rpc/handlers/load-model/handler.js +4 -1
  194. package/dist/server/rpc/handlers/load-model/resolve.js +9 -0
  195. package/dist/server/rpc/handlers/video-stream.d.ts +3 -0
  196. package/dist/server/rpc/handlers/video-stream.js +4 -0
  197. package/dist/server/rpc/profiling/operation-metrics.js +23 -0
  198. package/dist/server/utils/config-transform.js +1 -1
  199. package/dist/server/utils/tools/parsers/qwen35.js +7 -3
  200. package/dist/server/worker.js +14 -11
  201. package/dist/utils/errors-client.d.ts +23 -0
  202. package/dist/utils/errors-client.js +40 -0
  203. package/dist/utils/errors-server.d.ts +30 -2
  204. package/dist/utils/errors-server.js +51 -3
  205. package/package.json +66 -80
  206. package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +0 -490
  207. package/dist/server/bare/plugins/onnx-tts/plugin.js +0 -272
  208. package/dist/server/bare/plugins/onnx-tts/wav-helper.d.ts +0 -14
  209. package/dist/server/bare/plugins/onnx-tts/wav-helper.js +0 -107
  210. /package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech-stream.d.ts +0 -0
  211. /package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech.d.ts +0 -0
@@ -1,272 +0,0 @@
1
- import path from "bare-path";
2
- import ttsAddonLogging from "@qvac/tts-onnx/addonLogging.js";
3
- import ONNXTTS from "@qvac/tts-onnx";
4
- import { definePlugin, defineHandler, defineDuplexHandler, ttsRequestSchema, ttsResponseSchema, textToSpeechStreamRequestSchema, textToSpeechStreamResponseSchema, ModelType, ttsConfigSchema, ADDON_TTS, } from "../../../../schemas/index.js";
5
- import { createStreamLogger, registerAddonLogger } from "../../../../logging/index.js";
6
- import { TtsArtifactsRequiredError, TtsReferenceAudioRequiredError, } from "../../../../utils/errors-server.js";
7
- import { textToSpeech } from "./ops/text-to-speech.js";
8
- import { textToSpeechStream } from "./ops/text-to-speech-stream.js";
9
- import { attachModelExecutionMs } from "../../../../profiling/model-execution.js";
10
- import { loadReferenceAudioAt24k } from "./wav-helper.js";
11
- async function resolveChatterboxConfig(config, ctx) {
12
- const { ttsTokenizerSrc, ttsSpeechEncoderSrc, ttsEmbedTokensSrc, ttsConditionalDecoderSrc, ttsLanguageModelSrc, referenceAudioSrc, language, } = config;
13
- if (!ttsTokenizerSrc ||
14
- !ttsSpeechEncoderSrc ||
15
- !ttsEmbedTokensSrc ||
16
- !ttsConditionalDecoderSrc ||
17
- !ttsLanguageModelSrc) {
18
- throw new TtsArtifactsRequiredError();
19
- }
20
- if (!referenceAudioSrc) {
21
- throw new TtsReferenceAudioRequiredError();
22
- }
23
- const resolve = ctx.resolveModelPath;
24
- const [tokenizerPath, speechEncoderPath, embedTokensPath, conditionalDecoderPath, languageModelPath, referenceAudioPath,] = await Promise.all([
25
- resolve(ttsTokenizerSrc),
26
- resolve(ttsSpeechEncoderSrc),
27
- resolve(ttsEmbedTokensSrc),
28
- resolve(ttsConditionalDecoderSrc),
29
- resolve(ttsLanguageModelSrc),
30
- resolve(referenceAudioSrc),
31
- ]);
32
- return {
33
- config: {
34
- ttsEngine: "chatterbox",
35
- language,
36
- },
37
- artifacts: {
38
- tokenizerPath,
39
- speechEncoderPath,
40
- embedTokensPath,
41
- conditionalDecoderPath,
42
- languageModelPath,
43
- referenceAudioPath,
44
- },
45
- };
46
- }
47
- async function resolveSupertonicConfig(config, ctx) {
48
- const { ttsTextEncoderSrc, ttsDurationPredictorSrc, ttsVectorEstimatorSrc, ttsVocoderSrc, ttsUnicodeIndexerSrc, ttsTtsConfigSrc, ttsVoiceStyleSrc, ttsSpeed, ttsNumInferenceSteps, ttsSupertonicMultilingual, language, } = config;
49
- if (!ttsTextEncoderSrc ||
50
- !ttsDurationPredictorSrc ||
51
- !ttsVectorEstimatorSrc ||
52
- !ttsVocoderSrc ||
53
- !ttsUnicodeIndexerSrc ||
54
- !ttsTtsConfigSrc ||
55
- !ttsVoiceStyleSrc) {
56
- throw new TtsArtifactsRequiredError();
57
- }
58
- const resolve = ctx.resolveModelPath;
59
- const [textEncoderPath, durationPredictorPath, vectorEstimatorPath, vocoderPath, unicodeIndexerPath, ttsConfigPath, voiceStylePath,] = await Promise.all([
60
- resolve(ttsTextEncoderSrc),
61
- resolve(ttsDurationPredictorSrc),
62
- resolve(ttsVectorEstimatorSrc),
63
- resolve(ttsVocoderSrc),
64
- resolve(ttsUnicodeIndexerSrc),
65
- resolve(ttsTtsConfigSrc),
66
- resolve(ttsVoiceStyleSrc),
67
- ]);
68
- return {
69
- config: {
70
- ttsEngine: "supertonic",
71
- language,
72
- ttsSpeed,
73
- ttsNumInferenceSteps,
74
- ttsSupertonicMultilingual,
75
- },
76
- artifacts: {
77
- textEncoderPath,
78
- durationPredictorPath,
79
- vectorEstimatorPath,
80
- vocoderPath,
81
- unicodeIndexerPath,
82
- ttsConfigPath,
83
- voiceStylePath,
84
- },
85
- };
86
- }
87
- function createChatterboxModel(modelId, config, artifacts) {
88
- const tokenizerPath = artifacts["tokenizerPath"];
89
- const speechEncoderPath = artifacts["speechEncoderPath"];
90
- const embedTokensPath = artifacts["embedTokensPath"];
91
- const conditionalDecoderPath = artifacts["conditionalDecoderPath"];
92
- const languageModelPath = artifacts["languageModelPath"];
93
- const referenceAudioPath = artifacts["referenceAudioPath"];
94
- if (!tokenizerPath ||
95
- !speechEncoderPath ||
96
- !embedTokensPath ||
97
- !conditionalDecoderPath ||
98
- !languageModelPath) {
99
- throw new TtsArtifactsRequiredError();
100
- }
101
- if (!referenceAudioPath) {
102
- throw new TtsReferenceAudioRequiredError();
103
- }
104
- const logger = createStreamLogger(modelId, ModelType.onnxTts);
105
- registerAddonLogger(modelId, ModelType.onnxTts, logger);
106
- const referenceAudio = loadReferenceAudioAt24k(referenceAudioPath);
107
- const model = new ONNXTTS({
108
- files: {
109
- tokenizerPath,
110
- speechEncoderPath,
111
- embedTokensPath,
112
- conditionalDecoderPath,
113
- languageModelPath,
114
- },
115
- engine: "chatterbox",
116
- config: { language: config.language ?? "en", useGPU: false },
117
- referenceAudio,
118
- logger,
119
- opts: { stats: true },
120
- exclusiveRun: true,
121
- });
122
- return { model };
123
- }
124
- function createSupertonicModel(modelId, config, artifacts) {
125
- const textEncoderPath = artifacts["textEncoderPath"];
126
- const durationPredictorPath = artifacts["durationPredictorPath"];
127
- const vectorEstimatorPath = artifacts["vectorEstimatorPath"];
128
- const vocoderPath = artifacts["vocoderPath"];
129
- const unicodeIndexerPath = artifacts["unicodeIndexerPath"];
130
- const ttsConfigPath = artifacts["ttsConfigPath"];
131
- const voiceStylePath = artifacts["voiceStylePath"];
132
- if (!textEncoderPath ||
133
- !durationPredictorPath ||
134
- !vectorEstimatorPath ||
135
- !vocoderPath ||
136
- !unicodeIndexerPath ||
137
- !ttsConfigPath ||
138
- !voiceStylePath) {
139
- throw new TtsArtifactsRequiredError();
140
- }
141
- const logger = createStreamLogger(modelId, ModelType.onnxTts);
142
- registerAddonLogger(modelId, ModelType.onnxTts, logger);
143
- const voiceName = path.basename(voiceStylePath).replace(/\.json$/i, "") || "F1";
144
- const model = new ONNXTTS({
145
- files: {
146
- textEncoderPath,
147
- durationPredictorPath,
148
- vectorEstimatorPath,
149
- vocoderPath,
150
- unicodeIndexerPath,
151
- ttsConfigPath,
152
- voiceStyleJsonPath: voiceStylePath,
153
- },
154
- engine: "supertonic",
155
- voiceName,
156
- speed: config.ttsSpeed ?? 1,
157
- numInferenceSteps: config.ttsNumInferenceSteps ?? 5,
158
- supertonicMultilingual: config.ttsSupertonicMultilingual !== false,
159
- config: { language: config.language ?? "en" },
160
- logger,
161
- opts: { stats: true },
162
- exclusiveRun: true,
163
- });
164
- return { model };
165
- }
166
- export const ttsPlugin = definePlugin({
167
- modelType: ModelType.onnxTts,
168
- displayName: "TTS (ONNX)",
169
- addonPackage: ADDON_TTS,
170
- loadConfigSchema: ttsConfigSchema,
171
- skipPrimaryModelPathValidation: true,
172
- async resolveConfig(cfg, ctx) {
173
- const { ttsEngine } = cfg;
174
- if (ttsEngine === "supertonic") {
175
- return resolveSupertonicConfig(cfg, ctx);
176
- }
177
- return resolveChatterboxConfig(cfg, ctx);
178
- },
179
- createModel(params) {
180
- const config = (params.modelConfig ?? {});
181
- const artifacts = params.artifacts ?? {};
182
- if (config.ttsEngine === "supertonic") {
183
- return createSupertonicModel(params.modelId, config, artifacts);
184
- }
185
- return createChatterboxModel(params.modelId, config, artifacts);
186
- },
187
- handlers: {
188
- textToSpeech: defineHandler({
189
- requestSchema: ttsRequestSchema,
190
- responseSchema: ttsResponseSchema,
191
- streaming: true,
192
- // ONNX TTS does not expose a cancel surface — SDK falls back
193
- // to soft-cancel.
194
- cancel: { scope: "none" },
195
- handler: async function* (request) {
196
- const stream = textToSpeech(request);
197
- try {
198
- let result = await stream.next();
199
- while (!result.done) {
200
- yield {
201
- type: "textToSpeech",
202
- buffer: result.value.buffer,
203
- done: false,
204
- ...(result.value.chunkIndex !== undefined
205
- ? { chunkIndex: result.value.chunkIndex }
206
- : {}),
207
- ...(typeof result.value.sentenceChunk === "string" &&
208
- result.value.sentenceChunk.length > 0
209
- ? { sentenceChunk: result.value.sentenceChunk }
210
- : {}),
211
- };
212
- result = await stream.next();
213
- }
214
- const { modelExecutionMs, stats } = result.value;
215
- yield attachModelExecutionMs({
216
- type: "textToSpeech",
217
- buffer: [],
218
- done: true,
219
- ...(stats && { stats }),
220
- }, modelExecutionMs);
221
- }
222
- finally {
223
- await stream.return?.(undefined);
224
- }
225
- },
226
- }),
227
- textToSpeechStream: defineDuplexHandler({
228
- requestSchema: textToSpeechStreamRequestSchema,
229
- responseSchema: textToSpeechStreamResponseSchema,
230
- streaming: true,
231
- duplex: true,
232
- // ONNX TTS does not expose a cancel surface — SDK falls back
233
- // to soft-cancel.
234
- cancel: { scope: "none" },
235
- handler: async function* (request, inputStream) {
236
- const stream = textToSpeechStream(request, inputStream);
237
- try {
238
- let result = await stream.next();
239
- while (!result.done) {
240
- yield {
241
- type: "textToSpeechStream",
242
- buffer: result.value.buffer,
243
- done: false,
244
- ...(result.value.chunkIndex !== undefined
245
- ? { chunkIndex: result.value.chunkIndex }
246
- : {}),
247
- ...(typeof result.value.sentenceChunk === "string" &&
248
- result.value.sentenceChunk.length > 0
249
- ? { sentenceChunk: result.value.sentenceChunk }
250
- : {}),
251
- };
252
- result = await stream.next();
253
- }
254
- const { modelExecutionMs, stats } = result.value;
255
- yield attachModelExecutionMs({
256
- type: "textToSpeechStream",
257
- buffer: [],
258
- done: true,
259
- ...(stats && { stats }),
260
- }, modelExecutionMs);
261
- }
262
- finally {
263
- await stream.return?.(undefined);
264
- }
265
- },
266
- }),
267
- },
268
- logging: {
269
- module: ttsAddonLogging,
270
- namespace: ModelType.onnxTts,
271
- },
272
- });
@@ -1,14 +0,0 @@
1
- export type ReadWavResult = {
2
- samples: Float32Array;
3
- sampleRate: number;
4
- };
5
- /**
6
- * Read a WAV file and return Float32Array of mono samples in [-1, 1].
7
- * Supports 16-bit PCM and 32-bit float; stereo is converted to mono (left channel).
8
- */
9
- export declare function readWavAsFloat32(wavPath: string): ReadWavResult;
10
- /**
11
- * Load reference audio from a WAV path and return Float32Array at 24kHz for Chatterbox.
12
- */
13
- export declare function loadReferenceAudioAt24k(wavPath: string): Float32Array;
14
- //# sourceMappingURL=wav-helper.d.ts.map
@@ -1,107 +0,0 @@
1
- import fs from "bare-fs";
2
- const CHATTERBOX_SAMPLE_RATE = 24000;
3
- /**
4
- * Read a WAV file and return Float32Array of mono samples in [-1, 1].
5
- * Supports 16-bit PCM and 32-bit float; stereo is converted to mono (left channel).
6
- */
7
- export function readWavAsFloat32(wavPath) {
8
- const buf = fs.readFileSync(wavPath);
9
- if (buf.length < 44)
10
- throw new Error("WAV file too small");
11
- const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
12
- const riff = String.fromCharCode(buf[0], buf[1], buf[2], buf[3]);
13
- const wave = String.fromCharCode(buf[8], buf[9], buf[10], buf[11]);
14
- if (riff !== "RIFF")
15
- throw new Error("Not a RIFF file");
16
- if (wave !== "WAVE")
17
- throw new Error("Not WAVE format");
18
- let fmtChunk = null;
19
- let dataChunk = null;
20
- let offset = 12;
21
- while (offset + 8 <= buf.length) {
22
- const chunkId = String.fromCharCode(buf[offset], buf[offset + 1], buf[offset + 2], buf[offset + 3]);
23
- const chunkSize = view.getUint32(offset + 4, true);
24
- if (chunkId === "fmt ")
25
- fmtChunk = { offset: offset + 8, size: chunkSize };
26
- else if (chunkId === "data")
27
- dataChunk = { offset: offset + 8, size: chunkSize };
28
- offset += 8 + chunkSize;
29
- if (chunkSize % 2 === 1 && offset < buf.length)
30
- offset += 1;
31
- }
32
- if (!fmtChunk)
33
- throw new Error("WAV missing fmt chunk");
34
- if (!dataChunk)
35
- throw new Error("WAV missing data chunk");
36
- const fmtOff = fmtChunk.offset;
37
- if (fmtOff + 16 > buf.length)
38
- throw new Error("fmt chunk truncated");
39
- const audioFormat = view.getUint16(fmtOff, true);
40
- const numChannels = view.getUint16(fmtOff + 2, true);
41
- const sampleRate = view.getUint32(fmtOff + 4, true);
42
- const bitsPerSample = view.getUint16(fmtOff + 14, true);
43
- if (audioFormat !== 1 && audioFormat !== 3) {
44
- throw new Error("Unsupported WAV audio format: " +
45
- audioFormat +
46
- " (only PCM=1 and IEEE_FLOAT=3 supported)");
47
- }
48
- const dataOff = dataChunk.offset;
49
- const dataLen = Math.min(dataChunk.size, buf.length - dataOff);
50
- let samples;
51
- if (audioFormat === 1 && bitsPerSample === 16) {
52
- const bytesPerSample = 2;
53
- const numSamples = Math.floor(dataLen / bytesPerSample);
54
- const numFrames = numChannels === 1 ? numSamples : Math.floor(numSamples / numChannels);
55
- samples = new Float32Array(numFrames);
56
- for (let i = 0; i < numFrames; i++) {
57
- const idx = dataOff + (numChannels === 1 ? i * 2 : i * numChannels * 2);
58
- if (idx + 2 > buf.length)
59
- break;
60
- const s = view.getInt16(idx, true);
61
- samples[i] = s / 32768;
62
- }
63
- }
64
- else if (audioFormat === 3 && bitsPerSample === 32) {
65
- const bytesPerSample = 4;
66
- const numSamples = Math.floor(dataLen / bytesPerSample);
67
- const numFrames = numChannels === 1 ? numSamples : Math.floor(numSamples / numChannels);
68
- samples = new Float32Array(numFrames);
69
- for (let i = 0; i < numFrames; i++) {
70
- const idx = dataOff + (numChannels === 1 ? i * 4 : i * numChannels * 4);
71
- if (idx + 4 > buf.length)
72
- break;
73
- samples[i] = view.getFloat32(idx, true);
74
- }
75
- }
76
- else {
77
- throw new Error("Unsupported WAV format: audioFormat=" +
78
- audioFormat +
79
- ", bitsPerSample=" +
80
- bitsPerSample);
81
- }
82
- return { samples, sampleRate };
83
- }
84
- function resampleLinear(samples, fromRate, toRate) {
85
- if (fromRate === toRate)
86
- return samples;
87
- const ratio = fromRate / toRate;
88
- const outputLen = Math.round(samples.length / ratio);
89
- const output = new Float32Array(outputLen);
90
- for (let i = 0; i < outputLen; i++) {
91
- const srcIdx = i * ratio;
92
- const lo = Math.floor(srcIdx);
93
- const hi = Math.min(lo + 1, samples.length - 1);
94
- const frac = srcIdx - lo;
95
- output[i] = samples[lo] * (1 - frac) + samples[hi] * frac;
96
- }
97
- return output;
98
- }
99
- /**
100
- * Load reference audio from a WAV path and return Float32Array at 24kHz for Chatterbox.
101
- */
102
- export function loadReferenceAudioAt24k(wavPath) {
103
- const { samples, sampleRate } = readWavAsFloat32(wavPath);
104
- if (sampleRate === CHATTERBOX_SAMPLE_RATE)
105
- return samples;
106
- return resampleLinear(samples, sampleRate, CHATTERBOX_SAMPLE_RATE);
107
- }