feat(audio): choose a male or female local voice per language
The installer now fetches one male and one female Piper voice per language (Swedish NST/Lisa, English Ryan/Lessac), with genders confirmed by measuring each voice's pitch rather than guessed from the name. Settings -> Audio gets a voice selector per language with its own Test button that always plays the Piper voice. Male is preselected for both. The integration test now runs its server with an empty home directory, so voices installed on the developer's own machine can't leak into it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,7 @@ function setup() {
|
||||
const root = mkdtempSync(join(tmpdir(), "live-rc-tts-"));
|
||||
const voices = join(root, "voices");
|
||||
mkdirSync(voices);
|
||||
for (const name of ["sv_SE-nst-medium", "sv_SE-lisa-low", "en_US-lessac-medium", "de_DE-thorsten-medium"]) {
|
||||
for (const name of ["sv_SE-nst-medium", "sv_SE-lisa-medium", "sv_SE-alma-low", "en_US-lessac-medium", "en_US-ryan-medium", "de_DE-thorsten-medium"]) {
|
||||
writeFileSync(join(voices, `${name}.onnx`), "");
|
||||
writeFileSync(join(voices, `${name}.onnx.json`), "{}");
|
||||
}
|
||||
@@ -43,13 +43,23 @@ function setup() {
|
||||
return { root, voices, binary, cleanup: () => rmSync(root, { recursive: true, force: true }) };
|
||||
}
|
||||
|
||||
test("voices need a matching .onnx.json and are picked per language, preferring medium quality", () => {
|
||||
test("voices need a matching .onnx.json, carry catalog gender labels, and the chosen voice wins", () => {
|
||||
const env = setup();
|
||||
try {
|
||||
const voices = listVoices([env.voices, join(env.root, "missing-dir")]);
|
||||
assert.deepEqual(voices.map((voice) => voice.name), ["de_DE-thorsten-medium", "en_US-lessac-medium", "sv_SE-lisa-low", "sv_SE-nst-medium"]);
|
||||
assert.equal(pickVoice(voices, "sv").name, "sv_SE-nst-medium");
|
||||
assert.equal(pickVoice(voices, "en-US").name, "en_US-lessac-medium");
|
||||
assert.deepEqual(voices.map((voice) => voice.name), ["de_DE-thorsten-medium", "en_US-lessac-medium", "en_US-ryan-medium", "sv_SE-alma-low", "sv_SE-lisa-medium", "sv_SE-nst-medium"]);
|
||||
const byName = Object.fromEntries(voices.map((voice) => [voice.name, voice]));
|
||||
assert.equal(byName["sv_SE-nst-medium"].gender, "male");
|
||||
assert.equal(byName["sv_SE-lisa-medium"].gender, "female");
|
||||
assert.equal(byName["en_US-ryan-medium"].gender, "male");
|
||||
assert.equal(byName["en_US-lessac-medium"].gender, "female");
|
||||
assert.equal(byName["sv_SE-alma-low"].gender, "", "a voice outside the catalog has no guessed gender");
|
||||
|
||||
assert.equal(pickVoice(voices, "sv").name, "sv_SE-nst-medium", "Swedish defaults to the male NST voice");
|
||||
assert.equal(pickVoice(voices, "en-US").name, "en_US-ryan-medium", "English defaults to the male Ryan voice");
|
||||
assert.equal(pickVoice(voices, "sv", "sv_SE-lisa-medium").name, "sv_SE-lisa-medium", "the voice chosen in Settings is used");
|
||||
assert.equal(pickVoice(voices, "sv", "en_US-lessac-medium").name, "sv_SE-nst-medium", "a chosen voice in another language is ignored");
|
||||
assert.equal(pickVoice(voices, "sv", "sv_SE-removed-medium").name, "sv_SE-nst-medium", "an uninstalled choice falls back to the default");
|
||||
assert.equal(pickVoice(voices, "fi"), null);
|
||||
} finally { env.cleanup(); }
|
||||
});
|
||||
@@ -79,12 +89,15 @@ test("each line is generated once, cached, deduplicated, and generated one at a
|
||||
await Promise.all([tts.speech({ text: "One", language: "en" }), tts.speech({ text: "Two", language: "en" }), tts.speech({ text: "Tre", language: "sv", rate: 0.5 })]);
|
||||
assert.equal(calls.length, 4);
|
||||
assert.ok(calls.every((call) => call.maxParallel === 1), "generations never overlap");
|
||||
assert.ok(calls[1].args.includes(join(env.voices, "en_US-lessac-medium.onnx")), "the English voice is used for English text");
|
||||
assert.ok(calls[1].args.includes(join(env.voices, "en_US-ryan-medium.onnx")), "the English voice is used for English text");
|
||||
await tts.speech({ text: "Heat ett startar.", language: "sv", rate: 1, voice: "sv_SE-lisa-medium" });
|
||||
assert.equal(calls.length, 5, "the same text in another voice is a separate cached line");
|
||||
assert.ok(calls[4].args.includes(join(env.voices, "sv_SE-lisa-medium.onnx")));
|
||||
assert.equal(calls[3].args[calls[3].args.indexOf("--length_scale") + 1], "1.6", "slow speech rate maps to a longer (clamped) length scale");
|
||||
|
||||
const status = tts.status();
|
||||
assert.equal(status.available, true);
|
||||
assert.equal(status.cachedLines, 4);
|
||||
assert.equal(status.cachedLines, 5);
|
||||
assert.equal(readdirSync(join(env.root, "data", "tts")).filter((file) => file.endsWith(".tmp")).length, 0, "no temp files are left behind");
|
||||
} finally { env.cleanup(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user