From a2e9bac081588048ae0fb01abe7df2ffe9e64bcf Mon Sep 17 00:00:00 2001 From: Z User Date: Thu, 29 Oct 2026 23:39:55 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20TTS=20logs=20+=20voices=20list=20?= =?UTF-8?q?=E2=80=94=20stream=20VALID=5FROLES=20+=20file-based=20voice=20s?= =?UTF-8?q?can=20+=20v0.9.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 3 fixes ### 1. TTS logs not working in dashboard The stream route (/api/services/[role]/stream) had its own VALID_ROLES list that was missing 'tts'. Added 'tts' to the list. ### 2. Dashboard doesn't show voices /api/tts/voices only queried the TTS API (http://tts:8000/v1/audio/voices). If TTS was not running or the API didn't return custom voices, the list was empty. Rewrote /api/tts/voices to use 3 sources: 1. TTS API (if running) 2. voice_to_speaker.yaml (parse voice names from config file) 3. Scan gpu/tts/voices/ directory for .onnx and .wav files - .onnx files: ru_RU-irina-medium.onnx → 'irina' - .wav files: myvoice.wav → 'myvoice' 4. Always include defaults (alloy, echo, fable, onyx, nova, shimmer) ### 3. Voices not loading on page open refreshVoices() was only called when ttsRunning was true. Changed to always fetch on mount — the API now works even when TTS is stopped because it reads from config files and directory. ## Version → 0.9.2 ## After merge ```sh git pull && sh build.sh docker compose up -d --force-recreate dashboard ``` TTS tab should now show irina, denis, dmitri, ruslan in the voice dropdown (even if TTS is stopped). TTS logs should work in Logs tab. --- dashboard/src/app/api/debug/route.ts | 2 +- .../app/api/services/[role]/stream/route.ts | 1 + dashboard/src/app/api/tts/voices/route.ts | 89 +++++++++++++++---- dashboard/src/app/page.tsx | 8 +- dashboard/src/lib/version.ts | 2 +- 5 files changed, 76 insertions(+), 26 deletions(-) diff --git a/dashboard/src/app/api/debug/route.ts b/dashboard/src/app/api/debug/route.ts index e4c5cd7..91b2d80 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.9.1", + version: "0.9.2", timestamp: new Date().toISOString(), }); } diff --git a/dashboard/src/app/api/services/[role]/stream/route.ts b/dashboard/src/app/api/services/[role]/stream/route.ts index 6162512..74c0c14 100644 --- a/dashboard/src/app/api/services/[role]/stream/route.ts +++ b/dashboard/src/app/api/services/[role]/stream/route.ts @@ -14,6 +14,7 @@ const VALID_ROLES: ServiceRole[] = [ "ssh-companion", "gpu-test", "dashboard", + "tts", ]; /** diff --git a/dashboard/src/app/api/tts/voices/route.ts b/dashboard/src/app/api/tts/voices/route.ts index fc3cf6d..8925c98 100644 --- a/dashboard/src/app/api/tts/voices/route.ts +++ b/dashboard/src/app/api/tts/voices/route.ts @@ -1,36 +1,87 @@ import { NextResponse } from "next/server"; +import { promises as fs } from "node:fs"; +import path from "node:path"; +import { PROJECT_DIR } from "@/lib/docker"; 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"); + /** * GET /api/tts/voices * - * Proxies openedai-speech /v1/audio/voices endpoint. - * Returns the list of available TTS voices. + * Returns available TTS voices. Tries two sources: + * 1. openedai-speech /v1/audio/voices API (if TTS is running) + * 2. Falls back to reading voice_to_speaker.yaml + scanning voices/ dir + * (so voices show up even when TTS is stopped) */ export async function GET() { + const voices: string[] = []; + + // Source 1: Try the TTS API try { const res = await fetch("http://tts:8000/v1/audio/voices", { cache: "no-store", - signal: AbortSignal.timeout(5000), + signal: AbortSignal.timeout(3000), }); - if (!res.ok) { - return NextResponse.json( - { ok: false, error: `tts returned ${res.status}` }, - { status: res.status } - ); + if (res.ok) { + const data = await res.json(); + if (data.voices && Array.isArray(data.voices)) { + for (const v of data.voices) { + const id = v.voice_id || v.name; + if (id && !voices.includes(id)) voices.push(id); + } + } } - const data = await res.json(); - return NextResponse.json({ ok: true, ...data }); - } catch (err) { - return NextResponse.json( - { - ok: false, - error: (err as Error).message, - hint: "TTS container must be running (docker compose --profile tts up -d tts)", - }, - { status: 503 } - ); + } catch { + /* TTS not running — fall through to file scan */ } + + // Source 2: Read voice_to_speaker.yaml (always available, even when TTS is off) + try { + const yaml = await fs.readFile(VOICE_CONFIG_PATH, "utf-8"); + // Parse voice names — they're indented under "tts-1:" and "tts-1-hd:" + // Format: " voicename:\n model: ..." + const matches = yaml.matchAll(/^\s{2}(\w[\w\-]*):/gm); + for (const m of matches) { + const name = m[1]; + if (!voices.includes(name)) voices.push(name); + } + } catch { + /* config doesn't exist yet */ + } + + // Source 3: Scan voices/ directory for .onnx files (Piper voices) + try { + const entries = await fs.readdir(TTS_VOICES_DIR); + for (const f of entries) { + if (f.endsWith(".onnx")) { + // e.g. ru_RU-irina-medium.onnx → irina + const match = f.match(/^[a-z]{2}_([A-Z]{2})-([a-z]+)-/i); + if (match) { + const name = match[2]; + if (!voices.includes(name)) voices.push(name); + } + } + if (f.endsWith(".wav")) { + const name = f.replace(/\.wav$/, ""); + if (!voices.includes(name)) voices.push(name); + } + } + } catch { + /* dir doesn't exist */ + } + + // Always include defaults so the dropdown isn't empty + for (const d of ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]) { + if (!voices.includes(d)) voices.push(d); + } + + return NextResponse.json({ + ok: true, + voices: voices.map((v) => ({ voice_id: v })), + }); } diff --git a/dashboard/src/app/page.tsx b/dashboard/src/app/page.tsx index 36844a8..314dcd8 100644 --- a/dashboard/src/app/page.tsx +++ b/dashboard/src/app/page.tsx @@ -4448,7 +4448,6 @@ function TTSTab({ if (!res.ok) return; const data = await res.json(); if (data.ok && data.voices) { - // OpenAI format: { voices: [{ voice_id: "alloy", ... }] } const voiceIds = data.voices.map((v: { voice_id?: string; name?: string }) => v.voice_id || v.name).filter(Boolean); if (voiceIds.length > 0) { setVoices(voiceIds); @@ -4459,11 +4458,10 @@ function TTSTab({ } }, []); + // Refresh voices on mount (even if TTS is not running — we read config + files) React.useEffect(() => { - if (ttsRunning) { - refreshVoices(); - } - }, [ttsRunning, refreshVoices]); + refreshVoices(); + }, [refreshVoices]); async function handleGenerate() { if (!input.trim() || !ttsRunning || generating) return; diff --git a/dashboard/src/lib/version.ts b/dashboard/src/lib/version.ts index 9183878..2ef440a 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.9.1"; +export const DASHBOARD_VERSION = "0.9.2"; /** * Build timestamp — set at build time by Next.js. -- 2.49.1