feat(audio): add downloadable extra Piper voices with accents
Adds Alma (sv), Alan, Northern English, Cori, Alba (British/Scottish) and Joe, John, Norman (American) as optional voices downloaded one at a time from Settings, with gender (measured pitch) and accent shown in the voice lists. The standard install is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import { tmpdir } from "node:os";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { createTts, listVoices, pickVoice, resolvePiperBinary } = require("../server/tts.js");
|
||||
const { installVoices, installAll, VOICES } = require("../server/tts_install.js");
|
||||
|
||||
// Stand-in for execFile: records each call and writes the requested output file, so the
|
||||
// module's queueing/caching can be tested without a real Piper install.
|
||||
@@ -64,6 +65,43 @@ test("voices need a matching .onnx.json, carry catalog gender labels, and the ch
|
||||
} finally { env.cleanup(); }
|
||||
});
|
||||
|
||||
test("status offers the catalog voices that aren't installed yet, with gender and accent", () => {
|
||||
const env = setup();
|
||||
try {
|
||||
const status = createTts({ dataDir: env.root, projectDir: env.root, voiceDirs: [env.voices] }).status();
|
||||
const offered = Object.fromEntries(status.downloadable.map((voice) => [voice.name, voice]));
|
||||
assert.equal(offered["sv_SE-nst-medium"], undefined, "installed voices are not offered again");
|
||||
assert.deepEqual(offered["sv_SE-alma-medium"], { name: "sv_SE-alma-medium", language: "sv", gender: "female", accent: "", label: "Alma" });
|
||||
assert.equal(offered["en_GB-alan-medium"].accent, "gb");
|
||||
assert.equal(offered["en_GB-alan-medium"].gender, "male");
|
||||
assert.equal(status.voices.find((voice) => voice.name === "en_US-ryan-medium").accent, "us");
|
||||
} finally { env.cleanup(); }
|
||||
});
|
||||
|
||||
test("a standard install skips the extra voices; picking one downloads only that voice", async () => {
|
||||
const env = setup();
|
||||
const originalFetch = globalThis.fetch;
|
||||
const urls = [];
|
||||
globalThis.fetch = async (url) => { urls.push(String(url)); return new Response("model"); };
|
||||
try {
|
||||
const target = join(env.root, "fresh-voices");
|
||||
await installVoices({ voicesDir: target, log: () => {} });
|
||||
const standard = VOICES.filter((voice) => !voice.extra).map((voice) => voice.name);
|
||||
assert.deepEqual(standard, ["sv_SE-nst-medium", "sv_SE-lisa-medium", "en_US-ryan-medium", "en_US-lessac-medium"]);
|
||||
assert.equal(urls.length, standard.length * 2, "model + config per standard voice");
|
||||
assert.ok(!urls.some((url) => url.includes("en_GB")), "no extra voice in a standard install");
|
||||
|
||||
urls.length = 0;
|
||||
await installVoices({ voicesDir: target, log: () => {}, names: ["en_GB-alan-medium"] });
|
||||
assert.deepEqual(urls.map((url) => url.split("/main/")[1]), ["en/en_GB/alan/medium/en_GB-alan-medium.onnx.json", "en/en_GB/alan/medium/en_GB-alan-medium.onnx"]);
|
||||
assert.ok(readdirSync(target).includes("en_GB-alan-medium.onnx"));
|
||||
await assert.rejects(installAll({ projectDir: env.root, hasBinary: true, voice: "made_up-voice" }), /Unknown voice/);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
env.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test("the Piper copy installed into the project is preferred over one on PATH", () => {
|
||||
const env = setup();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user