@qvac/sdk 0.21.0 → 0.22.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/NOTICE +35 -1
- package/README.md +167 -24
- package/dist/examples/abot-world.js +1 -1
- package/dist/examples/advisory-model-fit.d.ts +0 -58
- package/dist/examples/advisory-model-fit.js +23 -150
- package/dist/examples/asr/moss-transcribe-filesystem.d.ts +2 -0
- package/dist/examples/asr/moss-transcribe-filesystem.js +84 -0
- package/dist/examples/asr/moss-transcribe-fit.d.ts +2 -0
- package/dist/examples/asr/moss-transcribe-fit.js +40 -0
- package/dist/examples/asr/nemotron-diarization-filesystem.d.ts +2 -0
- package/dist/examples/asr/nemotron-diarization-filesystem.js +64 -0
- package/dist/examples/asr/parakeet-ctc-filesystem.js +2 -2
- package/dist/examples/asr/parakeet-indic-conformer-filesystem.js +2 -2
- package/dist/examples/asr/parakeet-microphone-record.js +1 -1
- package/dist/examples/asr/parakeet-microphone-stream.js +1 -1
- package/dist/examples/asr/parakeet-nemotron-filesystem.js +3 -3
- package/dist/examples/asr/parakeet-sortformer-streaming.js +2 -2
- package/dist/examples/asr/parakeet-sortformer.js +1 -1
- package/dist/examples/asr/parakeet-tdt-filesystem-chunked.js +2 -2
- package/dist/examples/asr/parakeet-tdt-filesystem.js +2 -2
- package/dist/examples/asr/parakeet-unified-coreml.js +2 -2
- package/dist/examples/asr/parakeet-unified-filesystem.js +2 -2
- package/dist/examples/asr/whispercpp-filesystem-streaming.js +1 -1
- package/dist/examples/asr/whispercpp-filesystem.js +1 -1
- package/dist/examples/asr/whispercpp-microphone-record.js +1 -1
- package/dist/examples/asr/whispercpp-prompt.js +1 -1
- package/dist/examples/assess-model-fit.js +3 -6
- package/dist/examples/audiogen/edit-music.js +2 -2
- package/dist/examples/audiogen/generate-cover.js +2 -2
- package/dist/examples/audiogen/generate-music-minimax.js +1 -1
- package/dist/examples/audiogen/generate-music.js +1 -1
- package/dist/examples/audiogen/understand-music.js +2 -2
- package/dist/examples/batch-completion.d.ts +1 -1
- package/dist/examples/batch-completion.js +1 -1
- package/dist/examples/bci/bci-filesystem-streaming.js +2 -2
- package/dist/examples/bci/bci-filesystem.js +2 -2
- package/dist/examples/concurrent-completion-collision.js +1 -1
- package/dist/examples/config-reload.js +1 -1
- package/dist/examples/decisions.d.ts +2 -0
- package/dist/examples/decisions.js +38 -0
- package/dist/examples/diffusion-esrgan-upscale.js +1 -1
- package/dist/examples/diffusion-flux2-klein-img2img.js +1 -1
- package/dist/examples/diffusion-img2img.js +1 -1
- package/dist/examples/diffusion-img2vid-ltx.js +1 -1
- package/dist/examples/diffusion-img2vid-minimax-h3.d.ts +2 -0
- package/dist/examples/diffusion-img2vid-minimax-h3.js +72 -0
- package/dist/examples/diffusion-img2vid.js +1 -1
- package/dist/examples/llamacpp-filesystem.js +1 -1
- package/dist/examples/llamacpp-multi-gpu.js +2 -2
- package/dist/examples/llamacpp-structured-output.js +1 -1
- package/dist/examples/mcp-websearch.d.ts +2 -2
- package/dist/examples/mcp-websearch.js +3 -3
- package/dist/examples/model-fit-ui/server.d.ts +1 -1
- package/dist/examples/model-fit-ui/server.js +1 -1
- package/dist/examples/multi-job-completion.d.ts +1 -1
- package/dist/examples/multi-job-completion.js +1 -1
- package/dist/examples/ocr-fasttext.js +1 -1
- package/dist/examples/tools/llamacpp-tools-auto-dialect.js +1 -1
- package/dist/examples/tools/llamacpp-tools-gemma4.js +1 -1
- package/dist/examples/tools/llamacpp-tools-qwen35.js +1 -1
- package/dist/examples/tts/llm-to-tts-streaming.d.ts +2 -2
- package/dist/examples/tts/llm-to-tts-streaming.js +2 -2
- package/dist/examples/tts/moss-sound-effect-controls.d.ts +2 -0
- package/dist/examples/tts/moss-sound-effect-controls.js +88 -0
- package/dist/examples/tts/moss-sound-effect.d.ts +2 -0
- package/dist/examples/tts/moss-sound-effect.js +86 -0
- package/dist/examples/tts/moss-speech-audio.d.ts +2 -0
- package/dist/examples/tts/moss-speech-audio.js +159 -0
- package/dist/examples/tts/moss-speech.d.ts +2 -0
- package/dist/examples/tts/moss-speech.js +70 -0
- package/dist/examples/vla-groot.js +2 -2
- package/dist/examples/vla-pi05.js +2 -2
- package/dist/examples/vla-smolvla.js +2 -2
- package/dist/examples/voice-assistant/voice-assistant.js +1 -1
- package/dist/scripts/contract/build-contract.d.ts +3 -1
- package/dist/scripts/contract/build-contract.js +40 -2
- package/dist/scripts/contract/build-model-type-maps.d.ts +6 -1
- package/dist/scripts/contract/build-model-type-maps.js +3 -2
- package/dist/scripts/contract/constants-registry.d.ts +4 -0
- package/dist/scripts/contract/constants-registry.js +3 -1
- package/dist/scripts/contract/method-shapes.d.ts +1 -0
- package/dist/scripts/contract/method-shapes.js +1 -0
- package/dist/scripts/export-contract.js +20 -7
- package/dist/scripts/run-unit-tests.js +10 -5
- package/dist/src/client/api/assess-model-fit.d.ts +5 -5
- package/dist/src/client/api/assess-model-fit.js +5 -6
- package/dist/src/client/api/audio-edit.d.ts +14 -2
- package/dist/src/client/api/audio-edit.js +14 -2
- package/dist/src/client/api/audio-gen.d.ts +10 -2
- package/dist/src/client/api/audio-gen.js +10 -2
- package/dist/src/client/api/audio-understand.d.ts +1 -1
- package/dist/src/client/api/audio-understand.js +1 -1
- package/dist/src/client/api/batch-completion.js +1 -1
- package/dist/src/client/api/completion-stream.js +1 -1
- package/dist/src/client/api/decide.d.ts +31 -0
- package/dist/src/client/api/decide.js +29 -0
- package/dist/src/client/api/index.d.ts +1 -0
- package/dist/src/client/api/index.js +1 -0
- package/dist/src/client/api/load-model.d.ts +1 -0
- package/dist/src/client/api/text-to-speech.d.ts +1 -0
- package/dist/src/client/api/text-to-speech.js +15 -22
- package/dist/src/client/api/transcribe.js +5 -2
- package/dist/src/client/api/video-request.d.ts +5 -5
- package/dist/src/client/api/video.d.ts +23 -3
- package/dist/src/client/api/video.js +23 -3
- package/dist/src/commands/bundle/bare-pack.d.ts +8 -0
- package/dist/src/commands/bundle/bare-pack.js +28 -5
- package/dist/src/commands/bundle/constants.js +2 -0
- package/dist/src/commands/bundle/index.d.ts +7 -6
- package/dist/src/commands/bundle/index.js +126 -43
- package/dist/src/commands/bundle/manifest.d.ts +2 -0
- package/dist/src/commands/bundle/manifest.js +3 -2
- package/dist/src/commands/host-prebuilds/index.d.ts +15 -7
- package/dist/src/commands/host-prebuilds/index.js +35 -16
- package/dist/src/commands/index.d.ts +1 -1
- package/dist/src/commands/index.js +1 -1
- package/dist/src/commands/verify/addon-source.d.ts +12 -0
- package/dist/src/commands/verify/addon-source.js +36 -3
- package/dist/src/commands/verify/bare-kit-runtimes.js +2 -1
- package/dist/src/commands/verify/node-modules-source.js +10 -1
- package/dist/src/{expo/plugins/patches/qvac-platform-addons.d.ts → commands/verify/platform-addons.d.ts} +6 -10
- package/dist/src/{expo/plugins/patches/qvac-platform-addons.js → commands/verify/platform-addons.js} +2 -45
- package/dist/src/commands/verify/prebuilds.d.ts +7 -10
- package/dist/src/commands/verify/prebuilds.js +43 -34
- package/dist/src/expo/plugins/get-project-root.d.ts +1 -1
- package/dist/src/expo/plugins/link-addons.d.ts +18 -0
- package/dist/src/expo/plugins/link-addons.js +65 -0
- package/dist/src/expo/plugins/withAndroidArchitecture.d.ts +1 -1
- package/dist/src/expo/plugins/withAndroidNdkVersion.d.ts +1 -1
- package/dist/src/expo/plugins/withDeviceInfo.d.ts +1 -1
- package/dist/src/expo/plugins/withMobileBundle.d.ts +11 -21
- package/dist/src/expo/plugins/withMobileBundle.js +22 -112
- package/dist/src/expo/plugins/withOpenCL.d.ts +1 -1
- package/dist/src/expo/plugins/withQvacSDK.d.ts +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +2 -2
- package/dist/src/logging/base-logger.js +1 -1
- package/dist/src/logging/utils.js +1 -1
- package/dist/src/pear/pre.js +2 -0
- package/dist/src/plugin-ids.d.ts +3 -1
- package/dist/src/plugin-ids.js +4 -0
- package/dist/src/schemas/public.d.ts +2 -1
- package/dist/src/schemas/public.js +2 -1
- package/dist/src/schemas/sdk-errors-client.d.ts +3 -0
- package/dist/src/schemas/sdk-errors-client.js +16 -0
- package/dist/src/schemas/sdk-errors-server.d.ts +1 -0
- package/dist/src/schemas/sdk-errors-server.js +5 -0
- package/dist/src/utils/errors-client.d.ts +10 -0
- package/dist/src/utils/errors-client.js +18 -0
- package/dist/src/utils/mcp-adapter.js +12 -8
- package/dist/src/utils/tool-helpers.d.ts +1 -1
- package/dist/src/utils/tool-helpers.js +20 -52
- package/dist/src/worker/create-server.d.ts +1 -0
- package/dist/src/worker/create-server.js +5 -0
- package/dist/src/worker/index.js +4 -0
- package/dist/src/worker/lifecycle.js +9 -1
- package/dist/src/worker/plugins/llamacpp-decision.d.ts +2 -0
- package/dist/src/worker/plugins/llamacpp-decision.js +1 -0
- package/dist/src/worker/plugins/moss-transcribe.d.ts +2 -0
- package/dist/src/worker/plugins/moss-transcribe.js +1 -0
- package/package.json +39 -35
- package/src/electron-forge/index.cjs +12 -71
- package/dist/scripts/link-workspace-inference.d.ts +0 -2
- package/dist/scripts/link-workspace-inference.js +0 -31
- package/src/expo/plugins/patches/android-link.mjs +0 -67
- package/src/expo/plugins/patches/ios-link.mjs +0 -67
- package/src/expo/plugins/patches/qvac-platform-addons.ts +0 -124
|
@@ -4,7 +4,7 @@ import path from 'path';
|
|
|
4
4
|
// ESRGAN upscale example.
|
|
5
5
|
//
|
|
6
6
|
// Usage:
|
|
7
|
-
//
|
|
7
|
+
// npx tsx examples/diffusion-esrgan-upscale.ts [esrganSrc] [prompt] [outputDir]
|
|
8
8
|
const esrganArg = process.argv[2];
|
|
9
9
|
const promptArg = process.argv[3];
|
|
10
10
|
const outputDirArg = process.argv[4];
|
|
@@ -10,7 +10,7 @@ const llmModelSrc = process.argv[6] || QWEN3_4B_Q4_K_M;
|
|
|
10
10
|
const vaeModelSrc = process.argv[7] || FLUX_2_KLEIN_4B_VAE;
|
|
11
11
|
if (!inputPath) {
|
|
12
12
|
console.error('✖ input image path is required');
|
|
13
|
-
console.error('Usage:
|
|
13
|
+
console.error('Usage: node dist/examples/diffusion-flux2-klein-img2img.js <inputImage> [prompt] [outputDir] [diffusionModelSrc] [llmModelSrc] [vaeModelSrc]');
|
|
14
14
|
process.exit(1);
|
|
15
15
|
}
|
|
16
16
|
try {
|
|
@@ -8,7 +8,7 @@ const outputDir = process.argv[4] || '.';
|
|
|
8
8
|
const modelSrc = process.argv[5] || SD_V2_1_1B_Q8_0;
|
|
9
9
|
if (!inputPath) {
|
|
10
10
|
console.error('✖ input image path is required');
|
|
11
|
-
console.error('Usage:
|
|
11
|
+
console.error('Usage: node dist/examples/diffusion-img2img.js <inputImage> [prompt] [outputDir] [modelSrc]');
|
|
12
12
|
process.exit(1);
|
|
13
13
|
}
|
|
14
14
|
try {
|
|
@@ -27,7 +27,7 @@ const embeddingsConnectorsModelSrc = process.argv[9] ||
|
|
|
27
27
|
`${HF}/unsloth/LTX-2.3-GGUF/resolve/main/text_encoders/ltx-2.3-22b-distilled_embeddings_connectors.safetensors`;
|
|
28
28
|
if (!initImagePath) {
|
|
29
29
|
console.error('✖ init image path is required');
|
|
30
|
-
console.error('Usage:
|
|
30
|
+
console.error('Usage: node dist/examples/diffusion-img2vid-ltx.js ' +
|
|
31
31
|
'<initImagePath> [prompt] [outputDir] ' +
|
|
32
32
|
'[diffusionModelSrc] [llmModelSrc] [vaeModelSrc] [audioVaeModelSrc] [embeddingsConnectorsModelSrc]');
|
|
33
33
|
process.exit(1);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { loadModel, unloadModel, video } from '@qvac/sdk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
const modelsDir = process.argv[2];
|
|
5
|
+
const initImagePath = process.argv[3];
|
|
6
|
+
if (!modelsDir || !initImagePath) {
|
|
7
|
+
console.error('✖ models directory and init image path are required');
|
|
8
|
+
console.error('Usage: bun run bare:example dist/examples/diffusion-img2vid-minimax-h3.js ' +
|
|
9
|
+
'<modelsDirectory> <initImagePath> [output.avi]');
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
const outputPath = process.argv[4] || 'minimax-h3-img2vid.avi';
|
|
13
|
+
const modelSrc = path.resolve(modelsDir, process.env['H3_MODEL'] || 'minimax_h3_fl2va_pruned-Q4_K.gguf');
|
|
14
|
+
const llmModelSrc = path.resolve(modelsDir, process.env['H3_LLM'] || 'qwen3vl_32b_minimax_h3-Q4_K_M.gguf');
|
|
15
|
+
const vaeModelSrc = path.resolve(modelsDir, 'vae/minimax_h3_video_vae_fp16.safetensors');
|
|
16
|
+
let modelId;
|
|
17
|
+
try {
|
|
18
|
+
for (const file of [modelSrc, llmModelSrc, vaeModelSrc, initImagePath])
|
|
19
|
+
fs.accessSync(file);
|
|
20
|
+
console.log('▸ Loading MiniMax-H3 model (diffusion + Qwen3-VL + video VAE)...');
|
|
21
|
+
modelId = await loadModel({
|
|
22
|
+
modelType: 'sdcpp-generation',
|
|
23
|
+
modelSrc,
|
|
24
|
+
modelConfig: {
|
|
25
|
+
mode: 'video',
|
|
26
|
+
llmModelSrc,
|
|
27
|
+
vaeModelSrc,
|
|
28
|
+
device: 'gpu',
|
|
29
|
+
diffusion_fa: true,
|
|
30
|
+
offload_to_cpu: process.env['H3_OFFLOAD_TO_CPU'] !== '0',
|
|
31
|
+
stream_layers: process.env['H3_STREAM_LAYERS'] === '1',
|
|
32
|
+
...(process.env['H3_BACKEND'] && { backend: process.env['H3_BACKEND'] }),
|
|
33
|
+
...(process.env['H3_PARAMS_BACKEND'] && { params_backend: process.env['H3_PARAMS_BACKEND'] }),
|
|
34
|
+
...(process.env['H3_MAX_VRAM'] && { max_vram: process.env['H3_MAX_VRAM'] })
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
console.log(`▸ Model loaded: ${modelId}`);
|
|
38
|
+
const init_image = new Uint8Array(fs.readFileSync(initImagePath));
|
|
39
|
+
const prompt = process.env['PROMPT'] ||
|
|
40
|
+
'The boat glides forward through the mist while the camera slowly pulls back, cinematic natural motion.';
|
|
41
|
+
console.log(`▸ Generating video for: "${prompt}"`);
|
|
42
|
+
const { progressStream, outputs, stats } = video({
|
|
43
|
+
modelId,
|
|
44
|
+
mode: 'img2vid',
|
|
45
|
+
prompt,
|
|
46
|
+
init_image,
|
|
47
|
+
width: 864,
|
|
48
|
+
height: 480,
|
|
49
|
+
// H3 uses 17*k+5 frames and requires 24 FPS.
|
|
50
|
+
video_frames: Number(process.env['FRAMES'] || 124),
|
|
51
|
+
fps: 24,
|
|
52
|
+
steps: 8,
|
|
53
|
+
cfg_scale: 1,
|
|
54
|
+
seed: 11
|
|
55
|
+
});
|
|
56
|
+
for await (const { step, totalSteps } of progressStream) {
|
|
57
|
+
console.log(`▸ step ${step}/${totalSteps}`);
|
|
58
|
+
}
|
|
59
|
+
const buffers = await outputs;
|
|
60
|
+
if (!buffers[0])
|
|
61
|
+
throw new Error('Generation finished without an AVI result');
|
|
62
|
+
fs.writeFileSync(outputPath, buffers[0]);
|
|
63
|
+
console.log(`▸ Saved ${outputPath}`, await stats);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error('✖', error);
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
if (modelId)
|
|
71
|
+
await unloadModel({ modelId, clearStorage: false });
|
|
72
|
+
}
|
|
@@ -14,7 +14,7 @@ const vaeModelSrc = process.argv[7] || WAN_2_1_COMFYUI_REPACKAGED_VAE;
|
|
|
14
14
|
const clipVisionModelSrc = process.argv[8] || CLIP_VISION_H;
|
|
15
15
|
if (!initImagePath) {
|
|
16
16
|
console.error('✖ init image path is required');
|
|
17
|
-
console.error('Usage:
|
|
17
|
+
console.error('Usage: node dist/examples/diffusion-img2vid.js ' +
|
|
18
18
|
'<initImagePath> [prompt] [outputDir] ' +
|
|
19
19
|
'[i2vModelSrc] [t5XxlModelSrc] [vaeModelSrc] [clipVisionModelSrc]');
|
|
20
20
|
process.exit(1);
|
|
@@ -3,7 +3,7 @@ import { completion, loadModel, unloadModel } from '@qvac/sdk';
|
|
|
3
3
|
const ggufPath = process.argv[2];
|
|
4
4
|
if (!ggufPath) {
|
|
5
5
|
console.error('✖ Please provide the path to a GGUF file as the first argument');
|
|
6
|
-
console.error('✖ Usage:
|
|
6
|
+
console.error('✖ Usage: npx tsx examples/llamacpp-filesystem.ts <path-to-gguf-file>');
|
|
7
7
|
process.exit(1);
|
|
8
8
|
}
|
|
9
9
|
console.log(`▸ Loading GGUF model from: ${ggufPath}`);
|
|
@@ -10,8 +10,8 @@ import { completion, loadModel, unloadModel, VERBOSITY, LLAMA_3_2_1B_INST_Q4_0 }
|
|
|
10
10
|
// "1,1" distributes evenly across two GPUs; "3,1" assigns 75% to GPU 0.
|
|
11
11
|
//
|
|
12
12
|
// Usage:
|
|
13
|
-
//
|
|
14
|
-
//
|
|
13
|
+
// node dist/examples/llamacpp-multi-gpu.js
|
|
14
|
+
// node dist/examples/llamacpp-multi-gpu.js '<model-url>'
|
|
15
15
|
const modelSrc = process.argv[2] ?? LLAMA_3_2_1B_INST_Q4_0;
|
|
16
16
|
try {
|
|
17
17
|
const modelId = await loadModel({
|
|
@@ -4,7 +4,7 @@ import { loadModel, completion, unloadModel, QWEN3_600M_INST_Q4 } from '@qvac/sd
|
|
|
4
4
|
// difference between free-form text, free-form JSON, and a strict JSON Schema.
|
|
5
5
|
//
|
|
6
6
|
// Usage:
|
|
7
|
-
//
|
|
7
|
+
// npx tsx examples/llamacpp-structured-output.ts
|
|
8
8
|
const PERSON_SCHEMA = {
|
|
9
9
|
type: 'object',
|
|
10
10
|
properties: {
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* The server provides tools to search the web and get answers.
|
|
6
6
|
*
|
|
7
7
|
* Prerequisites:
|
|
8
|
-
* - Install MCP SDK:
|
|
8
|
+
* - Install MCP SDK: npm install @modelcontextprotocol/sdk
|
|
9
9
|
*
|
|
10
|
-
* Run with:
|
|
10
|
+
* Run with: npx tsx examples/mcp-websearch.ts
|
|
11
11
|
*/
|
|
12
12
|
export {};
|
|
13
13
|
//# sourceMappingURL=mcp-websearch.d.ts.map
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* The server provides tools to search the web and get answers.
|
|
6
6
|
*
|
|
7
7
|
* Prerequisites:
|
|
8
|
-
* - Install MCP SDK:
|
|
8
|
+
* - Install MCP SDK: npm install @modelcontextprotocol/sdk
|
|
9
9
|
*
|
|
10
|
-
* Run with:
|
|
10
|
+
* Run with: npx tsx examples/mcp-websearch.ts
|
|
11
11
|
*/
|
|
12
12
|
import { completion, loadModel, unloadModel, QWEN3_1_7B_INST_Q4 } from '../src/index.js';
|
|
13
13
|
// MCP SDK is a user-installed optional dependency
|
|
14
|
-
// Install with:
|
|
14
|
+
// Install with: npm install @modelcontextprotocol/sdk
|
|
15
15
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
16
16
|
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
17
17
|
function parseSearchResults(mcpResult) {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* machine is doing — fine for a demo, not a measurement.
|
|
18
18
|
*
|
|
19
19
|
* Run (Node or Bun, not Bare — this uses node:http):
|
|
20
|
-
*
|
|
20
|
+
* npx tsx examples/model-fit-ui/server.ts
|
|
21
21
|
* node dist/examples/model-fit-ui/server.js
|
|
22
22
|
*/
|
|
23
23
|
export {};
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* machine is doing — fine for a demo, not a measurement.
|
|
18
18
|
*
|
|
19
19
|
* Run (Node or Bun, not Bare — this uses node:http):
|
|
20
|
-
*
|
|
20
|
+
* npx tsx examples/model-fit-ui/server.ts
|
|
21
21
|
* node dist/examples/model-fit-ui/server.js
|
|
22
22
|
*/
|
|
23
23
|
import { createServer } from 'node:http';
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* `parallel` in flight, admitting one more waits FIFO until a slot frees.
|
|
22
22
|
*
|
|
23
23
|
* Run from packages/sdk:
|
|
24
|
-
*
|
|
24
|
+
* npx tsx examples/multi-job-completion.ts
|
|
25
25
|
*/
|
|
26
26
|
export {};
|
|
27
27
|
//# sourceMappingURL=multi-job-completion.d.ts.map
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* `parallel` in flight, admitting one more waits FIFO until a slot frees.
|
|
22
22
|
*
|
|
23
23
|
* Run from packages/sdk:
|
|
24
|
-
*
|
|
24
|
+
* npx tsx examples/multi-job-completion.ts
|
|
25
25
|
*/
|
|
26
26
|
import { completion, cancel, loadModel, unloadModel, InferenceCancelledError, LLAMA_3_2_1B_INST_Q4_0 } from '@qvac/sdk';
|
|
27
27
|
const PROMPTS = [
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* OCR example using the QVAC SDK.
|
|
3
3
|
*
|
|
4
4
|
* Usage:
|
|
5
|
-
*
|
|
5
|
+
* npx tsx examples/ocr-fasttext.ts [path-to-image]
|
|
6
6
|
*
|
|
7
7
|
* This example requires a test image (default: examples/image/basic_test.bmp).
|
|
8
8
|
* Sample images are available in the QVAC source repository, but not included in the published npm package.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LFM without requiring a toolDialect override.
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
|
-
*
|
|
9
|
+
* node dist/examples/tools/llamacpp-tools-auto-dialect.js <model-src>
|
|
10
10
|
*/
|
|
11
11
|
import { completion, loadModel, unloadModel } from '@qvac/sdk';
|
|
12
12
|
import { tools, mockExecute } from './shared.js';
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* completion() if auto-detection does not pick it up for a given file name.
|
|
14
14
|
*
|
|
15
15
|
* Usage:
|
|
16
|
-
*
|
|
16
|
+
* node dist/examples/tools/llamacpp-tools-gemma4.js <model-url>
|
|
17
17
|
*/
|
|
18
18
|
import { completion, loadModel, unloadModel, GEMMA4_2B_MULTIMODAL_Q4_K_M } from '@qvac/sdk';
|
|
19
19
|
import { tools, mockExecute } from './shared.js';
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* toolDialect: "qwen35" explicitly if auto-detection does not pick it up.
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
12
|
-
*
|
|
12
|
+
* node dist/examples/tools/llamacpp-tools-qwen35.js <model-url>
|
|
13
13
|
*/
|
|
14
14
|
import { completion, loadModel, unloadModel, QWEN3_5_0_8B_MULTIMODAL_Q8_0 } from '@qvac/sdk';
|
|
15
15
|
import { tools, mockExecute } from './shared.js';
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* Each synthesized phrase is played as soon as PCM arrives (`playPcmInt16Chunk`). A combined WAV
|
|
7
7
|
* is written at the end for inspection.
|
|
8
8
|
*
|
|
9
|
-
* Prerequisites:
|
|
9
|
+
* Prerequisites: Node.js, QVAC worker, registry access, macOS `afplay` / Linux `aplay` (or Windows
|
|
10
10
|
* PowerShell player) for chunk playback.
|
|
11
11
|
*
|
|
12
12
|
* Usage:
|
|
13
|
-
*
|
|
13
|
+
* npx tsx examples/tts/llm-to-tts-streaming.ts
|
|
14
14
|
*/
|
|
15
15
|
export {};
|
|
16
16
|
//# sourceMappingURL=llm-to-tts-streaming.d.ts.map
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* Each synthesized phrase is played as soon as PCM arrives (`playPcmInt16Chunk`). A combined WAV
|
|
7
7
|
* is written at the end for inspection.
|
|
8
8
|
*
|
|
9
|
-
* Prerequisites:
|
|
9
|
+
* Prerequisites: Node.js, QVAC worker, registry access, macOS `afplay` / Linux `aplay` (or Windows
|
|
10
10
|
* PowerShell player) for chunk playback.
|
|
11
11
|
*
|
|
12
12
|
* Usage:
|
|
13
|
-
*
|
|
13
|
+
* npx tsx examples/tts/llm-to-tts-streaming.ts
|
|
14
14
|
*/
|
|
15
15
|
import { completion, loadModel, textToSpeechStream, unloadModel, LLAMA_3_2_1B_INST_Q4_0, TTS_MULTILINGUAL_SUPERTONIC3_Q8_0 } from '@qvac/sdk';
|
|
16
16
|
import { createWav, playPcmInt16Chunk } from './utils.js';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { loadModel, textToSpeech, unloadModel, close, AUDIOGEN_MOSS_SFX_V2_Q8_0 } from '@qvac/sdk';
|
|
3
|
+
// Desktop MOSS-SoundEffect-v2, 48 kHz mono output. A GPU is recommended.
|
|
4
|
+
// Run from packages/sdk: node --import tsx examples/tts/moss-sound-effect-controls.ts
|
|
5
|
+
// Optional: QVAC_MOSS_SFX_MODEL=/absolute/path/moss-sfx-v2-q8_0.gguf
|
|
6
|
+
// Use the catalog source URL: its full descriptor selects the audiogen plugin.
|
|
7
|
+
// Each clip denoises a 30-second latent, regardless of its requested output duration.
|
|
8
|
+
function saveWav(samples, sampleRate, filename) {
|
|
9
|
+
if (samples.length === 0 || samples.some((sample) => !Number.isFinite(sample))) {
|
|
10
|
+
throw new Error('The model returned no usable audio.');
|
|
11
|
+
}
|
|
12
|
+
const wav = Buffer.alloc(44 + samples.length * 2);
|
|
13
|
+
wav.write('RIFF', 0);
|
|
14
|
+
wav.writeUInt32LE(wav.length - 8, 4);
|
|
15
|
+
wav.write('WAVEfmt ', 8);
|
|
16
|
+
wav.writeUInt32LE(16, 16);
|
|
17
|
+
wav.writeUInt16LE(1, 20);
|
|
18
|
+
wav.writeUInt16LE(1, 22);
|
|
19
|
+
wav.writeUInt32LE(sampleRate, 24);
|
|
20
|
+
wav.writeUInt32LE(sampleRate * 2, 28);
|
|
21
|
+
wav.writeUInt16LE(2, 32);
|
|
22
|
+
wav.writeUInt16LE(16, 34);
|
|
23
|
+
wav.write('data', 36);
|
|
24
|
+
wav.writeUInt32LE(samples.length * 2, 40);
|
|
25
|
+
for (let i = 0; i < samples.length; i++) {
|
|
26
|
+
wav.writeInt16LE(Math.max(-32768, Math.min(32767, Math.round(samples[i]))), 44 + i * 2);
|
|
27
|
+
}
|
|
28
|
+
writeFileSync(filename, wav);
|
|
29
|
+
console.error(`▸ Saved ${filename}: ${sampleRate} Hz, ${(samples.length / sampleRate).toFixed(2)} seconds`);
|
|
30
|
+
}
|
|
31
|
+
let lastPercentage = -1;
|
|
32
|
+
function progress(p) {
|
|
33
|
+
const percentage = Math.floor(p.percentage);
|
|
34
|
+
if (percentage === lastPercentage)
|
|
35
|
+
return;
|
|
36
|
+
lastPercentage = percentage;
|
|
37
|
+
const line = `▸ Downloading ${p.percentage.toFixed(0)}% (${(p.downloaded / 1e6).toFixed(1)}/${(p.total / 1e6).toFixed(1)} MB)`;
|
|
38
|
+
process.stderr.write(process.stderr.isTTY ? `\r${line}` : `${line}\n`);
|
|
39
|
+
if (p.percentage >= 100)
|
|
40
|
+
process.stderr.write('\n');
|
|
41
|
+
}
|
|
42
|
+
async function main() {
|
|
43
|
+
const modelId = await loadModel({
|
|
44
|
+
modelSrc: process.env['QVAC_MOSS_SFX_MODEL'] ?? AUDIOGEN_MOSS_SFX_V2_Q8_0.src,
|
|
45
|
+
modelType: 'tts-ggml',
|
|
46
|
+
modelConfig: { ttsEngine: 'moss-sfx', useGPU: true, seed: 42 },
|
|
47
|
+
onProgress: progress
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
console.error('▸ Generating a sound effect...');
|
|
51
|
+
const result = textToSpeech({
|
|
52
|
+
modelId,
|
|
53
|
+
text: 'A dog barking twice in a quiet room.',
|
|
54
|
+
stream: false,
|
|
55
|
+
seconds: 3,
|
|
56
|
+
negativePrompt: 'Speech, music, background voices.',
|
|
57
|
+
steps: 20,
|
|
58
|
+
guidance: 4,
|
|
59
|
+
shift: 5
|
|
60
|
+
});
|
|
61
|
+
const samples = await result.buffer;
|
|
62
|
+
if (!(await result.done))
|
|
63
|
+
throw new Error('Sound-effect generation did not complete.');
|
|
64
|
+
const sampleRate = await result.sampleRate;
|
|
65
|
+
if (sampleRate !== 48000)
|
|
66
|
+
throw new Error(`Unexpected sound-effect sample rate: ${sampleRate}`);
|
|
67
|
+
saveWav(samples, sampleRate, 'moss-sound-effect-controls-output.wav');
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
await unloadModel({ modelId });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
await main();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error('✖', error);
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
try {
|
|
82
|
+
await close();
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('✖ Cleanup failed:', error);
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { loadModel, textToSpeech, unloadModel, close, AUDIOGEN_MOSS_SFX_V2_Q8_0 } from '@qvac/sdk';
|
|
3
|
+
// Desktop MOSS-SoundEffect-v2, 48 kHz mono output. A GPU is recommended.
|
|
4
|
+
// Run from packages/sdk: node --import tsx examples/tts/moss-sound-effect.ts
|
|
5
|
+
// Optional: QVAC_MOSS_SFX_MODEL=/absolute/path/moss-sfx-v2-q8_0.gguf
|
|
6
|
+
// Use the catalog source URL: its full descriptor selects the audiogen plugin.
|
|
7
|
+
// Each clip denoises a 30-second latent, regardless of its requested output duration.
|
|
8
|
+
// Use 20 steps for a practical demo; omitting steps uses the slower baked default (100).
|
|
9
|
+
function saveWav(samples, sampleRate, filename) {
|
|
10
|
+
if (samples.length === 0 || samples.some((sample) => !Number.isFinite(sample))) {
|
|
11
|
+
throw new Error('The model returned no usable audio.');
|
|
12
|
+
}
|
|
13
|
+
const wav = Buffer.alloc(44 + samples.length * 2);
|
|
14
|
+
wav.write('RIFF', 0);
|
|
15
|
+
wav.writeUInt32LE(wav.length - 8, 4);
|
|
16
|
+
wav.write('WAVEfmt ', 8);
|
|
17
|
+
wav.writeUInt32LE(16, 16);
|
|
18
|
+
wav.writeUInt16LE(1, 20);
|
|
19
|
+
wav.writeUInt16LE(1, 22);
|
|
20
|
+
wav.writeUInt32LE(sampleRate, 24);
|
|
21
|
+
wav.writeUInt32LE(sampleRate * 2, 28);
|
|
22
|
+
wav.writeUInt16LE(2, 32);
|
|
23
|
+
wav.writeUInt16LE(16, 34);
|
|
24
|
+
wav.write('data', 36);
|
|
25
|
+
wav.writeUInt32LE(samples.length * 2, 40);
|
|
26
|
+
for (let i = 0; i < samples.length; i++) {
|
|
27
|
+
wav.writeInt16LE(Math.max(-32768, Math.min(32767, Math.round(samples[i]))), 44 + i * 2);
|
|
28
|
+
}
|
|
29
|
+
writeFileSync(filename, wav);
|
|
30
|
+
console.error(`▸ Saved ${filename}: ${sampleRate} Hz, ${(samples.length / sampleRate).toFixed(2)} seconds`);
|
|
31
|
+
}
|
|
32
|
+
let lastPercentage = -1;
|
|
33
|
+
function progress(p) {
|
|
34
|
+
const percentage = Math.floor(p.percentage);
|
|
35
|
+
if (percentage === lastPercentage)
|
|
36
|
+
return;
|
|
37
|
+
lastPercentage = percentage;
|
|
38
|
+
const line = `▸ Downloading ${p.percentage.toFixed(0)}% (${(p.downloaded / 1e6).toFixed(1)}/${(p.total / 1e6).toFixed(1)} MB)`;
|
|
39
|
+
process.stderr.write(process.stderr.isTTY ? `\r${line}` : `${line}\n`);
|
|
40
|
+
if (p.percentage >= 100)
|
|
41
|
+
process.stderr.write('\n');
|
|
42
|
+
}
|
|
43
|
+
async function main() {
|
|
44
|
+
const modelId = await loadModel({
|
|
45
|
+
modelSrc: process.env['QVAC_MOSS_SFX_MODEL'] ?? AUDIOGEN_MOSS_SFX_V2_Q8_0.src,
|
|
46
|
+
modelType: 'tts-ggml',
|
|
47
|
+
modelConfig: { ttsEngine: 'moss-sfx', useGPU: true, seed: 42 },
|
|
48
|
+
onProgress: progress
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
console.error('▸ Generating a sound effect...');
|
|
52
|
+
const result = textToSpeech({
|
|
53
|
+
modelId,
|
|
54
|
+
text: 'Heavy rain falling on a tin roof.',
|
|
55
|
+
stream: false,
|
|
56
|
+
seconds: 2,
|
|
57
|
+
steps: 20
|
|
58
|
+
});
|
|
59
|
+
const samples = await result.buffer;
|
|
60
|
+
if (!(await result.done))
|
|
61
|
+
throw new Error('Sound-effect generation did not complete.');
|
|
62
|
+
const sampleRate = await result.sampleRate;
|
|
63
|
+
if (sampleRate !== 48000)
|
|
64
|
+
throw new Error(`Unexpected sound-effect sample rate: ${sampleRate}`);
|
|
65
|
+
saveWav(samples, sampleRate, 'moss-sound-effect-output.wav');
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
await unloadModel({ modelId });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
await main();
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.error('✖', error);
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
try {
|
|
80
|
+
await close();
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error('✖ Cleanup failed:', error);
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { loadModel, textToSpeech, unloadModel, close, TTS_MOSS_SPEECH_Q8_0, TTS_CODEC_MOSS_SPEECH_F16 } from '@qvac/sdk';
|
|
3
|
+
// Desktop MOSS-Speech: 9B language model + codec, 24 kHz spoken reply and text.
|
|
4
|
+
// Run from packages/sdk: node --import tsx examples/tts/moss-speech-audio.ts question.wav
|
|
5
|
+
// Use a GPU with enough memory. Registry sources download automatically.
|
|
6
|
+
// Optional local paths: QVAC_MOSS_SPEECH_MODEL and QVAC_MOSS_SPEECH_CODEC.
|
|
7
|
+
// Both engines run a batch job; stream: false collects the complete reply.
|
|
8
|
+
function saveWav(samples, sampleRate, filename) {
|
|
9
|
+
if (samples.length === 0 || samples.some((sample) => !Number.isFinite(sample))) {
|
|
10
|
+
throw new Error('The model returned no usable audio.');
|
|
11
|
+
}
|
|
12
|
+
const wav = Buffer.alloc(44 + samples.length * 2);
|
|
13
|
+
wav.write('RIFF', 0);
|
|
14
|
+
wav.writeUInt32LE(wav.length - 8, 4);
|
|
15
|
+
wav.write('WAVEfmt ', 8);
|
|
16
|
+
wav.writeUInt32LE(16, 16);
|
|
17
|
+
wav.writeUInt16LE(1, 20);
|
|
18
|
+
wav.writeUInt16LE(1, 22);
|
|
19
|
+
wav.writeUInt32LE(sampleRate, 24);
|
|
20
|
+
wav.writeUInt32LE(sampleRate * 2, 28);
|
|
21
|
+
wav.writeUInt16LE(2, 32);
|
|
22
|
+
wav.writeUInt16LE(16, 34);
|
|
23
|
+
wav.write('data', 36);
|
|
24
|
+
wav.writeUInt32LE(samples.length * 2, 40);
|
|
25
|
+
for (let i = 0; i < samples.length; i++) {
|
|
26
|
+
wav.writeInt16LE(Math.max(-32768, Math.min(32767, Math.round(samples[i]))), 44 + i * 2);
|
|
27
|
+
}
|
|
28
|
+
writeFileSync(filename, wav);
|
|
29
|
+
console.error(`▸ Saved ${filename}: ${sampleRate} Hz, ${(samples.length / sampleRate).toFixed(2)} seconds`);
|
|
30
|
+
}
|
|
31
|
+
let lastPercentage = -1;
|
|
32
|
+
function progress(p) {
|
|
33
|
+
const percentage = Math.floor(p.percentage);
|
|
34
|
+
if (percentage === lastPercentage)
|
|
35
|
+
return;
|
|
36
|
+
lastPercentage = percentage;
|
|
37
|
+
const line = `▸ Downloading ${p.percentage.toFixed(0)}% (${(p.downloaded / 1e6).toFixed(1)}/${(p.total / 1e6).toFixed(1)} MB)`;
|
|
38
|
+
process.stderr.write(process.stderr.isTTY ? `\r${line}` : `${line}\n`);
|
|
39
|
+
if (p.percentage >= 100)
|
|
40
|
+
process.stderr.write('\n');
|
|
41
|
+
}
|
|
42
|
+
// Read standard mono/stereo PCM16 or float32 WAV without an audio-library dependency.
|
|
43
|
+
function readQuestion(filename) {
|
|
44
|
+
const wav = readFileSync(filename);
|
|
45
|
+
if (wav.length < 12 ||
|
|
46
|
+
wav.toString('ascii', 0, 4) !== 'RIFF' ||
|
|
47
|
+
wav.toString('ascii', 8, 12) !== 'WAVE') {
|
|
48
|
+
throw new Error('Question must be a RIFF WAV file.');
|
|
49
|
+
}
|
|
50
|
+
let format = 0;
|
|
51
|
+
let channels = 0;
|
|
52
|
+
let sampleRate = 0;
|
|
53
|
+
let bits = 0;
|
|
54
|
+
let data;
|
|
55
|
+
for (let offset = 12; offset + 8 <= wav.length;) {
|
|
56
|
+
const size = wav.readUInt32LE(offset + 4);
|
|
57
|
+
const start = offset + 8;
|
|
58
|
+
if (start + size > wav.length)
|
|
59
|
+
throw new Error('Truncated WAV chunk.');
|
|
60
|
+
const id = wav.toString('ascii', offset, offset + 4);
|
|
61
|
+
if (id === 'fmt ') {
|
|
62
|
+
if (size < 16)
|
|
63
|
+
throw new Error('Invalid WAV format chunk.');
|
|
64
|
+
format = wav.readUInt16LE(start);
|
|
65
|
+
channels = wav.readUInt16LE(start + 2);
|
|
66
|
+
sampleRate = wav.readUInt32LE(start + 4);
|
|
67
|
+
bits = wav.readUInt16LE(start + 14);
|
|
68
|
+
}
|
|
69
|
+
else if (id === 'data')
|
|
70
|
+
data = wav.subarray(start, start + size);
|
|
71
|
+
offset = start + size + (size % 2);
|
|
72
|
+
}
|
|
73
|
+
if (!data ||
|
|
74
|
+
![1, 2].includes(channels) ||
|
|
75
|
+
!((format === 1 && bits === 16) || (format === 3 && bits === 32))) {
|
|
76
|
+
throw new Error('Use a mono/stereo PCM16 or float32 WAV question.');
|
|
77
|
+
}
|
|
78
|
+
if (sampleRate < 8000 || sampleRate > 192000) {
|
|
79
|
+
throw new Error('WAV sample rate must be 8000–192000 Hz.');
|
|
80
|
+
}
|
|
81
|
+
const bytesPerSample = bits / 8;
|
|
82
|
+
const frameBytes = bytesPerSample * channels;
|
|
83
|
+
if (data.length % frameBytes !== 0)
|
|
84
|
+
throw new Error('Incomplete WAV audio frame.');
|
|
85
|
+
const audio = [];
|
|
86
|
+
for (let offset = 0; offset < data.length; offset += frameBytes) {
|
|
87
|
+
let sample = 0;
|
|
88
|
+
for (let channel = 0; channel < channels; channel++) {
|
|
89
|
+
const at = offset + channel * bytesPerSample;
|
|
90
|
+
sample += format === 1 ? data.readInt16LE(at) / 32768 : data.readFloatLE(at);
|
|
91
|
+
}
|
|
92
|
+
audio.push(sample / channels);
|
|
93
|
+
}
|
|
94
|
+
if (audio.length === 0 || audio.length > sampleRate * 60) {
|
|
95
|
+
throw new Error('Use a non-empty question of at most 60 seconds.');
|
|
96
|
+
}
|
|
97
|
+
return { audio, sampleRate };
|
|
98
|
+
}
|
|
99
|
+
async function main() {
|
|
100
|
+
const filename = process.argv[2];
|
|
101
|
+
if (!filename) {
|
|
102
|
+
throw new Error('Usage: node --import tsx examples/tts/moss-speech-audio.ts question.wav');
|
|
103
|
+
}
|
|
104
|
+
const question = readQuestion(filename);
|
|
105
|
+
const modelId = await loadModel({
|
|
106
|
+
modelSrc: process.env['QVAC_MOSS_SPEECH_MODEL'] ?? TTS_MOSS_SPEECH_Q8_0,
|
|
107
|
+
modelType: 'tts-ggml',
|
|
108
|
+
modelConfig: {
|
|
109
|
+
ttsEngine: 'moss-speech',
|
|
110
|
+
mossSpeechCodecModelSrc: process.env['QVAC_MOSS_SPEECH_CODEC'] ?? TTS_CODEC_MOSS_SPEECH_F16,
|
|
111
|
+
useGPU: true,
|
|
112
|
+
seed: 42
|
|
113
|
+
},
|
|
114
|
+
onProgress: progress
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
console.error('▸ Generating a spoken reply...');
|
|
118
|
+
const result = textToSpeech({
|
|
119
|
+
modelId,
|
|
120
|
+
...question,
|
|
121
|
+
stream: false,
|
|
122
|
+
greedy: true,
|
|
123
|
+
maxNewTokens: 128,
|
|
124
|
+
maxReplySeconds: 5,
|
|
125
|
+
messages: [{ role: 'user', text: 'Please answer the next spoken turn briefly.' }]
|
|
126
|
+
});
|
|
127
|
+
const samples = await result.buffer;
|
|
128
|
+
const reply = await result.text;
|
|
129
|
+
if (!(await result.done))
|
|
130
|
+
throw new Error('Speech generation did not complete.');
|
|
131
|
+
if (reply?.trim())
|
|
132
|
+
console.log(reply);
|
|
133
|
+
else
|
|
134
|
+
console.error('▸ The model returned an audio-only reply.');
|
|
135
|
+
const sampleRate = await result.sampleRate;
|
|
136
|
+
if (sampleRate !== 24000)
|
|
137
|
+
throw new Error(`Unexpected reply sample rate: ${sampleRate}`);
|
|
138
|
+
saveWav(samples, sampleRate, 'moss-speech-audio-output.wav');
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
await unloadModel({ modelId });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
await main();
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
console.error('✖', error);
|
|
149
|
+
process.exitCode = 1;
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
try {
|
|
153
|
+
await close();
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error('✖ Cleanup failed:', error);
|
|
157
|
+
process.exitCode = 1;
|
|
158
|
+
}
|
|
159
|
+
}
|