From c9ed8e02456e0ae135f62353c930541c0722126e Mon Sep 17 00:00:00 2001 From: Z User Date: Thu, 29 Oct 2026 23:09:05 +0000 Subject: [PATCH] fix: TTS voice upload updates voice_to_speaker.yaml + language selector + v0.8.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - compose.yaml: mount gpu/tts/config → /app/config for voice_to_speaker.yaml - /api/tts/upload-voice: creates/updates voice_to_speaker.yaml with new voice entry - TTSTab: language selector (default Russian), passed to API - /api/tts/generate: arrayBuffer instead of streaming for reliability --- compose.yaml | 2 + dashboard/src/app/api/debug/route.ts | 2 +- .../src/app/api/tts/upload-voice/route.ts | 120 +++++++++++++++++- dashboard/src/app/page.tsx | 39 +++++- dashboard/src/lib/version.ts | 2 +- 5 files changed, 150 insertions(+), 15 deletions(-) diff --git a/compose.yaml b/compose.yaml index 61bba28..45f6fdd 100644 --- a/compose.yaml +++ b/compose.yaml @@ -172,9 +172,11 @@ services: volumes: - ${HOST_PROJECT_PATH:-./}/gpu/tts/voices:/app/voices - ${HOST_PROJECT_PATH:-./}/gpu/tts/cache:/app/cache + - ${HOST_PROJECT_PATH:-./}/gpu/tts/config:/app/config environment: PORT: 8000 HALF_PRECISION: "false" + TTS_ALLOWED_PLAYERS: "*" networks: - gpu-node restart: "no" diff --git a/dashboard/src/app/api/debug/route.ts b/dashboard/src/app/api/debug/route.ts index 5392b6d..4b76e98 100644 --- a/dashboard/src/app/api/debug/route.ts +++ b/dashboard/src/app/api/debug/route.ts @@ -120,7 +120,7 @@ export async function GET() { ok: envError === null, error: envError, }, - version: "0.8.2", + version: "0.8.3", timestamp: new Date().toISOString(), }); } diff --git a/dashboard/src/app/api/tts/upload-voice/route.ts b/dashboard/src/app/api/tts/upload-voice/route.ts index 85c05e1..cffccd4 100644 --- a/dashboard/src/app/api/tts/upload-voice/route.ts +++ b/dashboard/src/app/api/tts/upload-voice/route.ts @@ -1,5 +1,5 @@ import { NextRequest, NextResponse } from "next/server"; -import { promises as fs } from "node:fs"; +import { promises as fs, existsSync } from "node:fs"; import path from "node:path"; import { PROJECT_DIR } from "@/lib/docker"; @@ -7,13 +7,15 @@ export const dynamic = "force-dynamic"; export const runtime = "nodejs"; const TTS_VOICES_DIR = path.join(PROJECT_DIR, "gpu", "tts", "voices"); +const TTS_CONFIG_DIR = path.join(PROJECT_DIR, "gpu", "tts", "config"); +const VOICE_CONFIG_PATH = path.join(TTS_CONFIG_DIR, "voice_to_speaker.yaml"); /** * POST /api/tts/upload-voice * * Uploads a custom voice sample (WAV file) for XTTSv2 voice cloning. - * The file is saved to gpu/tts/voices/ which is mounted into the TTS - * container at /app/voices/. + * The file is saved to gpu/tts/voices/ AND the voice_to_speaker.yaml config + * is updated so openedai-speech picks it up after restart. * * For XTTS voice samples: * - Mono (single channel) 22050 Hz WAV file @@ -34,6 +36,7 @@ export async function POST(req: NextRequest) { const form = await req.formData(); const file = form.get("file"); const name = form.get("name") as string | null; + const language = (form.get("language") as string) || null; if (!file || !(file instanceof File)) { return NextResponse.json( @@ -54,18 +57,24 @@ export async function POST(req: NextRequest) { const filename = `${voiceName}.wav`; const dest = path.join(TTS_VOICES_DIR, filename); - // Create directory if it doesn't exist + // Create directories if they don't exist await fs.mkdir(TTS_VOICES_DIR, { recursive: true }); + await fs.mkdir(TTS_CONFIG_DIR, { recursive: true }); const buffer = Buffer.from(await file.arrayBuffer()); await fs.writeFile(dest, buffer); + // Now update voice_to_speaker.yaml to include the new voice + // openedai-speech reads this config at startup — without it, the voice + // won't appear in the voices list even though the WAV file exists. + await updateVoiceConfig(voiceName, filename, language); + return NextResponse.json({ ok: true, voice: voiceName, path: filename, size: buffer.length, - hint: "Voice uploaded. Restart TTS container for it to pick up the new voice, or it may be available immediately depending on the backend.", + hint: "Voice uploaded and config updated. Restart TTS container to apply.", }); } catch (err) { return NextResponse.json( @@ -83,9 +92,108 @@ export async function POST(req: NextRequest) { export async function GET() { try { const entries = await fs.readdir(TTS_VOICES_DIR); - const voices = entries.filter((f) => f.endsWith(".wav") || f.endsWith(".mp3") || f.endsWith(".flac")); + const voices = entries.filter( + (f) => f.endsWith(".wav") || f.endsWith(".mp3") || f.endsWith(".flac") + ); return NextResponse.json({ ok: true, voices }); } catch { return NextResponse.json({ ok: true, voices: [] }); } } + +/** + * Update voice_to_speaker.yaml to add a new voice entry. + * If the file doesn't exist, create it with the default built-in voices + * plus the new custom voice. + */ +async function updateVoiceConfig( + voiceName: string, + filename: string, + language: string | null +): Promise { + let existing = ""; + try { + existing = await fs.readFile(VOICE_CONFIG_PATH, "utf-8"); + } catch { + // File doesn't exist — create from scratch with default voices + existing = createDefaultVoiceConfig(); + } + + // Check if voice already exists in config + if (existing.includes(` ${voiceName}:`)) { + // Voice already in config — update the speaker file path + existing = existing.replace( + new RegExp( + ` ${voiceName}:\\n(?: [^\\n]+\\n)*`, + "m" + ), + formatVoiceEntry(voiceName, filename, language) + ); + } else { + // Add new voice under tts-1-hd section + // Find the tts-1-hd: section and append + if (existing.includes("tts-1-hd:")) { + existing = existing.replace( + /(tts-1-hd:\n)/, + `$1${formatVoiceEntry(voiceName, filename, language)}` + ); + } else { + // No tts-1-hd section — add it + existing += `\ntts-1-hd:\n${formatVoiceEntry(voiceName, filename, language)}`; + } + } + + await fs.writeFile(VOICE_CONFIG_PATH, existing, "utf-8"); +} + +function formatVoiceEntry( + name: string, + filename: string, + language: string | null +): string { + let entry = ` ${name}:\n model: xtts\n speaker: voices/${filename}\n`; + if (language) { + entry += ` language: ${language}\n`; + } + return entry; +} + +function createDefaultVoiceConfig(): string { + return `# voice_to_speaker.yaml — openedai-speech voice configuration +# Custom voices are added here. Restart TTS container after changes. + +tts-1: + alloy: + model: voices/en_US-amy-medium.onnx + echo: + model: voices/en_US-libritts-high.onnx + fable: + model: voices/en_US-ryan-high.onnx + onyx: + model: voices/en_US-daniel-low.onnx + nova: + model: voices/en_US-lessac-medium.onnx + shimmer: + model: voices/en_US-nora-medium.onnx + +tts-1-hd: + alloy: + model: xtts + speaker: voices/alloy.wav + echo: + model: xtts + speaker: voices/echo.wav + fable: + model: xtts + speaker: voices/fable.wav + onyx: + model: xtts + speaker: voices/onyx.wav + nova: + model: xtts + speaker: voices/nova.wav + shimmer: + model: xtts + speaker: voices/shimmer.wav +`; +} diff --git a/dashboard/src/app/page.tsx b/dashboard/src/app/page.tsx index eadf05d..058bc47 100644 --- a/dashboard/src/app/page.tsx +++ b/dashboard/src/app/page.tsx @@ -4439,6 +4439,7 @@ function TTSTab({ const [audioUrl, setAudioUrl] = React.useState(null); const [error, setError] = React.useState(""); const [uploadProgress, setUploadProgress] = React.useState(null); + const [voiceLanguage, setVoiceLanguage] = React.useState("ru"); const fileInputRef = React.useRef(null); const refreshVoices = React.useCallback(async () => { @@ -4496,7 +4497,7 @@ function TTSTab({ } } - async function handleUploadVoice(file: File) { + async function handleUploadVoice(file: File, language: string = "ru") { if (!file.name.match(/\.(wav|mp3|flac)$/i)) { setError("Voice sample must be WAV/MP3/FLAC"); return; @@ -4508,13 +4509,14 @@ function TTSTab({ formData.append("file", file); const name = file.name.replace(/\.[^.]+$/, "").replace(/[^\w\-]/g, "_"); formData.append("name", name); + formData.append("language", language); const res = await fetch("/api/tts/upload-voice", { method: "POST", body: formData, }); const data = await res.json(); if (data.ok) { - setError(`Voice "${data.voice}" uploaded. Restart TTS to apply.`); + setError(`Voice "${data.voice}" uploaded (${language}). Restart TTS to apply.`); refreshVoices(); } else { setError(data.error || "Upload failed"); @@ -4707,8 +4709,8 @@ function TTSTab({ {/* Voice upload (for XTTS custom voices) */}
-
- + +
{uploadProgress && (

@@ -4738,8 +4763,8 @@ function TTSTab({ For natural Russian:{" "} built-in voices (alloy, nova, shimmer) are English-trained and will speak Russian with an accent. Upload a clean WAV sample of a Russian - speaker (10-20s, mono 22050 Hz, no noise) → restart TTS → select - the new voice. XTTSv2 supports Russian natively. + speaker (10-20s, mono 22050 Hz, no noise), select the language, and + restart TTS. The new voice will appear in the dropdown above.
Good sources: audiobook samples (lib.ru), news clips, or record diff --git a/dashboard/src/lib/version.ts b/dashboard/src/lib/version.ts index 0aa77a2..0794963 100644 --- a/dashboard/src/lib/version.ts +++ b/dashboard/src/lib/version.ts @@ -4,7 +4,7 @@ * Displayed in the footer and available via /api/debug so the user can * verify the update actually took effect. */ -export const DASHBOARD_VERSION = "0.8.2"; +export const DASHBOARD_VERSION = "0.8.3"; /** * Build timestamp — set at build time by Next.js. -- 2.49.1