Fuzzy voice matching

This commit is contained in:
2026-05-14 20:33:31 +02:00
parent 456ec8c83f
commit afeb05447d
5 changed files with 63 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ import { readdirSync } from "node:fs";
import { join } from "node:path";
import { respond } from "../audio/AudioService.js";
import type { TTSPreferencesRow } from "../db/schema.js";
import { formatCandidates } from "../tts/BaseEngine.js";
import type { Module } from "./types.js";
export const canttalk: Module = ({ client, audio, commands, tts, db, t, config, rootDir }) => {
@@ -38,23 +39,27 @@ export const canttalk: Module = ({ client, audio, commands, tts, db, t, config,
});
commands.register("myvoice", async (args, message) => {
if (args.length > 3) {
return respond(audio, sysmsg, message, t("TOO_MANY_ARGUMENTS"));
}
const engineName = args[1];
const voiceArg = args[2];
if (!engineName || !voiceArg) {
if (!engineName || args.length < 3) {
return respond(audio, sysmsg, message, t("TOO_MANY_ARGUMENTS"));
}
const engine = tts.get(engineName);
if (!engine) {
return respond(audio, sysmsg, message, t("INVALID_ENGINE", engineName));
}
const userVoice = voiceArg.toLowerCase();
const voiceInput = args.slice(2).join(" ");
const res = engine.resolveVoice(voiceInput);
let chosenVoice: string;
if (engine.validateVoice(userVoice)) {
chosenVoice = userVoice;
if (res.kind === "exact" || res.kind === "fuzzy") {
chosenVoice = res.voice;
respond(audio, sysmsg, message, t("USER_VOICE_CHANGED", chosenVoice, engine.longName));
} else if (res.kind === "ambiguous") {
return respond(
audio,
sysmsg,
message,
t("AMBIGUOUS_VOICE", voiceInput, formatCandidates(res.candidates)),
);
} else {
chosenVoice = engine.getDefaultVoice();
respond(audio, sysmsg, message, t("INVALID_VOICE", chosenVoice, engine.longName));