@jskit-ai/assistant-voice-sherpa 0.1.41 → 0.1.43

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "schema": "vibe64.voice-model-sources.v1",
2
+ "schema": "jskit.assistant-voice.model-sources.v1",
3
3
  "packRevision": 2,
4
4
  "models": [
5
5
  {
@@ -1,5 +1,5 @@
1
1
  {
2
- "schema": "vibe64.voice-model-sources.v1",
2
+ "schema": "jskit.assistant-voice.model-sources.v1",
3
3
  "packRevision": 1,
4
4
  "models": [
5
5
  {
@@ -1,5 +1,5 @@
1
1
  {
2
- "schema": "vibe64.voice-model-sources.v1",
2
+ "schema": "jskit.assistant-voice.model-sources.v1",
3
3
  "packRevision": 3,
4
4
  "models": [
5
5
  {
@@ -1,5 +1,5 @@
1
1
  {
2
- "schema": "vibe64.voice-model-sources.v1",
2
+ "schema": "jskit.assistant-voice.model-sources.v1",
3
3
  "packRevision": 2,
4
4
  "models": [
5
5
  {
@@ -1,5 +1,5 @@
1
1
  {
2
- "schema": "vibe64.voice-model-sources.v1",
2
+ "schema": "jskit.assistant-voice.model-sources.v1",
3
3
  "packRevision": 3,
4
4
  "models": [
5
5
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/assistant-voice-sherpa",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "type": "module",
5
5
  "description": "Optional native Sherpa speech engine and explicit model preparation for assistant voice.",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "tooling"
20
20
  ],
21
21
  "dependencies": {
22
- "@jskit-ai/assistant-voice": "0.1.41",
22
+ "@jskit-ai/assistant-voice": "0.1.42",
23
23
  "sherpa-onnx-node": "1.13.6"
24
24
  },
25
25
  "jskit": {
package/src/cli.js CHANGED
@@ -9,6 +9,33 @@ import { createVoiceAccessToken } from "@jskit-ai/assistant-voice/server";
9
9
  import { createVoiceDaemon } from "@jskit-ai/assistant-voice/server";
10
10
  import { verifyVoiceModelContract } from "./voiceModelContract.js";
11
11
 
12
+ // Combined packs list their manifests in merge order: base, kitten, kokoro.
13
+ const PACKS = Object.freeze({
14
+ cori: ["voice-models.json"],
15
+ piper: ["voice-models-piper.json"],
16
+ kitten: ["voice-models-kitten.json"],
17
+ "piper-kitten": ["voice-models-piper.json", "voice-models-kitten.json"],
18
+ kokoro: ["voice-models-kokoro.json"],
19
+ "kokoro-q8f16": ["voice-models-kokoro-q8f16.json"],
20
+ "piper-kitten-kokoro-q8f16": ["voice-models-piper.json", "voice-models-kitten.json", "voice-models-kokoro-q8f16.json"]
21
+ });
22
+ const PACK_NAMES = Object.keys(PACKS);
23
+
24
+ function mergeVoiceModelSources([base, kitten, kokoro]) {
25
+ base.models.push(...kitten.models.filter(model => model.kind === "tts"));
26
+ base.configuration.voices.unshift(...kitten.configuration.voices);
27
+ Object.assign(base.configuration.synthesizers, kitten.configuration.synthesizers);
28
+ if (kokoro) {
29
+ base.models.push(...kokoro.models.filter(model => model.kind === "tts"));
30
+ base.configuration.voices.push(...kokoro.configuration.voices.map(voice => ({ ...voice, modelId: "kokoro" })));
31
+ base.configuration.synthesizers.kokoro = kokoro.configuration.synthesizer;
32
+ base.onnxMetadata = kokoro.onnxMetadata;
33
+ base.textFiles = kokoro.textFiles;
34
+ }
35
+ base.configuration.outputSampleRate = 22050;
36
+ return base;
37
+ }
38
+
12
39
  function argumentMap(values = []) {
13
40
  const [command = "help", ...tail] = values;
14
41
  const options = {};
@@ -50,7 +77,7 @@ function usage() {
50
77
  "",
51
78
  "Commands:",
52
79
  " serve --models-root PATH --key-file PATH [--host ADDRESS] [--port NUMBER] [--config FILE]",
53
- " prepare --models-root PATH [--pack cori|piper|kitten|piper-kitten|kokoro|kokoro-q8f16|piper-kitten-kokoro-q8f16] [--sources-file FILE] [--download-cache PATH] [--hotwords-file PATH]",
80
+ ` prepare --models-root PATH [--pack ${PACK_NAMES.join("|")}] [--sources-file FILE] [--download-cache PATH] [--hotwords-file PATH]`,
54
81
  " verify --models-root PATH",
55
82
  " token --key-file PATH --tenant NAME"
56
83
  ].join("\n");
@@ -77,31 +104,20 @@ async function runVoiceCli(argv = process.argv.slice(2), { createDaemon = create
77
104
  "retain-downloads": "RETAIN_DOWNLOADS", "hotwords-file": "HOTWORDS_FILE"
78
105
  })) if (options[option]) env[`JSKIT_VOICE_${variable}`] = options[option];
79
106
  const pack = options.pack || process.env.JSKIT_VOICE_PACK || "cori";
80
- const manifests = { cori: "voice-models.json", piper: "voice-models-piper.json", kitten: "voice-models-kitten.json", kokoro: "voice-models-kokoro.json", "kokoro-q8f16": "voice-models-kokoro-q8f16.json" };
81
- if (pack !== "piper-kitten" && pack !== "piper-kitten-kokoro-q8f16" && !Object.hasOwn(manifests, pack)) throw new Error("Choose --pack cori, piper, kitten, piper-kitten, kokoro, kokoro-q8f16 or piper-kitten-kokoro-q8f16, or supply --sources-file for your own model pack.");
107
+ if (!Object.hasOwn(PACKS, pack)) throw new Error(`Choose --pack ${PACK_NAMES.slice(0, -1).join(", ")} or ${PACK_NAMES.at(-1)}, or supply --sources-file for your own model pack.`);
108
+ const manifests = PACKS[pack];
82
109
  let temporary;
83
110
  try {
84
111
  env.JSKIT_VOICE_SOURCES_FILE = options["sources-file"] || process.env.JSKIT_VOICE_SOURCES_FILE;
85
- if (!env.JSKIT_VOICE_SOURCES_FILE && (pack === "piper-kitten" || pack === "piper-kitten-kokoro-q8f16")) {
86
- const piper = JSON.parse(await readFile(new URL("../models/voice-models-piper.json", import.meta.url), "utf8"));
87
- const kitten = JSON.parse(await readFile(new URL("../models/voice-models-kitten.json", import.meta.url), "utf8"));
88
- piper.models.push(...kitten.models.filter(model => model.kind === "tts"));
89
- piper.configuration.voices.unshift(...kitten.configuration.voices);
90
- Object.assign(piper.configuration.synthesizers, kitten.configuration.synthesizers);
91
- if (pack === "piper-kitten-kokoro-q8f16") {
92
- const kokoro = JSON.parse(await readFile(new URL("../models/voice-models-kokoro-q8f16.json", import.meta.url), "utf8"));
93
- piper.models.push(...kokoro.models.filter(model => model.kind === "tts"));
94
- piper.configuration.voices.push(...kokoro.configuration.voices.map(voice => ({ ...voice, modelId: "kokoro" })));
95
- piper.configuration.synthesizers.kokoro = kokoro.configuration.synthesizer;
96
- piper.onnxMetadata = kokoro.onnxMetadata;
97
- piper.textFiles = kokoro.textFiles;
98
- }
99
- piper.configuration.outputSampleRate = 22050;
112
+ if (!env.JSKIT_VOICE_SOURCES_FILE && manifests.length > 1) {
113
+ const sources = mergeVoiceModelSources(await Promise.all(manifests.map(async manifest => (
114
+ JSON.parse(await readFile(new URL(`../models/${manifest}`, import.meta.url), "utf8"))
115
+ ))));
100
116
  temporary = await mkdtemp(path.join(os.tmpdir(), "jskit-voice-sources-"));
101
117
  env.JSKIT_VOICE_SOURCES_FILE = path.join(temporary, "sources.json");
102
- await writeFile(env.JSKIT_VOICE_SOURCES_FILE, JSON.stringify(piper, null, 2) + "\n");
118
+ await writeFile(env.JSKIT_VOICE_SOURCES_FILE, JSON.stringify(sources, null, 2) + "\n");
103
119
  }
104
- env.JSKIT_VOICE_SOURCES_FILE ||= fileURLToPath(new URL(`../models/${manifests[pack]}`, import.meta.url));
120
+ env.JSKIT_VOICE_SOURCES_FILE ||= fileURLToPath(new URL(`../models/${manifests[0]}`, import.meta.url));
105
121
  await new Promise((resolve, reject) => {
106
122
  const child = spawn("bash", [script], { env, stdio: "inherit" });
107
123
  child.once("error", reject);
@@ -3,6 +3,7 @@ import { createRequire } from "node:module";
3
3
  import { createSynthesisProcess, SYNTHESIS_REQUEST_TIMEOUT_MS } from "./synthesisProcess.js";
4
4
 
5
5
  import {
6
+ VOICE_ID_PATTERN,
6
7
  VOICE_INPUT_SAMPLE_RATE,
7
8
  normalizeRecognizedText,
8
9
  pcm16LeToFloat32
@@ -105,7 +106,7 @@ async function createSherpaSpeechEngine({
105
106
  ? [{ id: "default", label: "Default voice", speakerId: 0 }]
106
107
  : [{ id: "cori", label: "Cori · female · British English · Piper", language: "en-GB", speakerId: 0 }]);
107
108
  if (!Array.isArray(voices) || !voices.length || voices.length > 128 || new Set(voices.map(voice => voice?.id)).size !== voices.length ||
108
- voices.some(voice => !voice || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/u.test(voice.id) || typeof voice.label !== "string" || !voice.label.trim() || voice.label.length > 100 ||
109
+ voices.some(voice => !voice || !VOICE_ID_PATTERN.test(voice.id) || typeof voice.label !== "string" || !voice.label.trim() || voice.label.length > 100 ||
109
110
  !Number.isSafeInteger(voice.speakerId) || voice.speakerId < 0)) {
110
111
  throw new TypeError("Configure unique voice IDs, names and valid model speaker IDs.");
111
112
  }
@@ -3,7 +3,7 @@ import { createReadStream } from "node:fs";
3
3
  import { readFile, stat } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
 
6
- const VOICE_MODEL_CONTRACT_SCHEMA = "vibe64.voice-models.v1";
6
+ const VOICE_MODEL_CONTRACT_SCHEMA = "jskit.assistant-voice.models.v1";
7
7
  const SHA256_PATTERN = /^[a-f0-9]{64}$/u;
8
8
 
9
9
  function modelContractError(code, message) {
@@ -73,7 +73,9 @@ if [ -f "$models_root/voice-models.json" ] &&
73
73
  cmp -s "$hotwords_source" "$models_root/stt/hotwords.txt" &&
74
74
  cmp -s "$bpe_vocab_source" "$models_root/stt/bpe.vocab" &&
75
75
  "$node_bin" "$model_contract_verifier" "$models_root"; then
76
- chmod 0755 "$models_root"
76
+ # The speech service runs as its own user, so the pack is readable by all
77
+ # whatever umask prepared it.
78
+ chmod -R u=rwX,go=rX "$models_root"
77
79
  if [ "$retain_downloads" = "0" ]; then
78
80
  while IFS= read -r model_id; do
79
81
  rm -f -- "$download_cache/$(read_model_field "$model_id" archive)"
@@ -141,7 +143,7 @@ cp -- "$source_manifest" "$stage_root/sources.json"
141
143
 
142
144
  "$node_bin" "$model_contract_builder" "$stage_root"
143
145
  "$node_bin" "$model_contract_verifier" "$stage_root"
144
- chmod 0755 "$stage_root"
146
+ chmod -R u=rwX,go=rX "$stage_root"
145
147
 
146
148
  rm -rf -- "$previous_root"
147
149
  if [[ -e "$models_root" ]]; then