Compare commits
5 Commits
fix/tts-vo
...
bf1c19db2f
| Author | SHA1 | Date | |
|---|---|---|---|
| bf1c19db2f | |||
|
|
a2e9bac081 | ||
| b47da4cca2 | |||
|
|
830763c3fa | ||
| 04ee042a05 |
@@ -120,7 +120,7 @@ export async function GET() {
|
||||
ok: envError === null,
|
||||
error: envError,
|
||||
},
|
||||
version: "0.9.0",
|
||||
version: "0.9.2",
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ const VALID_ROLES: ServiceRole[] = [
|
||||
"ssh-companion",
|
||||
"gpu-test",
|
||||
"dashboard",
|
||||
"tts",
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 })),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.0";
|
||||
export const DASHBOARD_VERSION = "0.9.2";
|
||||
|
||||
/**
|
||||
* Build timestamp — set at build time by Next.js.
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
# Download Russian Piper TTS voices for openedai-speech
|
||||
# Voices: irina (female), denis (male), dmitri (male), ruslan (male)
|
||||
#
|
||||
# Usage: sh download-ru-voices.sh
|
||||
# Usage: sh gpu/tts/download-ru-voices.sh
|
||||
set -e
|
||||
|
||||
VOICES_DIR="${1:-./gpu/tts/voices}"
|
||||
|
||||
mkdir -p "$VOICES_DIR"
|
||||
|
||||
# Piper voice URLs (HuggingFace)
|
||||
BASE_URL="https://huggingface.co/rhasspy/piper-voices/resolve/main/ru_RU"
|
||||
# Piper voice URLs (HuggingFace — note the path: ru/ru_RU/<voice>/medium/)
|
||||
BASE_URL="https://huggingface.co/rhasspy/piper-voices/resolve/main/ru/ru_RU"
|
||||
|
||||
VOICES="irina denis dmitri ruslan"
|
||||
|
||||
@@ -18,7 +18,7 @@ for voice in $VOICES; do
|
||||
MODEL_FILE="$VOICES_DIR/ru_RU-${voice}-medium.onnx"
|
||||
CONFIG_FILE="$VOICES_DIR/ru_RU-${voice}-medium.onnx.json"
|
||||
|
||||
if [ -f "$MODEL_FILE" ]; then
|
||||
if [ -f "$MODEL_FILE" ] && [ $(stat -c%s "$MODEL_FILE" 2>/dev/null || stat -f%z "$MODEL_FILE" 2>/dev/null) -gt 1000 ]; then
|
||||
echo "✓ $voice already downloaded"
|
||||
continue
|
||||
fi
|
||||
@@ -28,7 +28,15 @@ for voice in $VOICES; do
|
||||
"$BASE_URL/${voice}/medium/ru_RU-${voice}-medium.onnx"
|
||||
curl -L -o "$CONFIG_FILE" \
|
||||
"$BASE_URL/${voice}/medium/ru_RU-${voice}-medium.onnx.json"
|
||||
echo "✓ $voice downloaded"
|
||||
|
||||
# Check file size — if too small, download failed
|
||||
SIZE=$(stat -c%s "$MODEL_FILE" 2>/dev/null || stat -f%z "$MODEL_FILE" 2>/dev/null)
|
||||
if [ "$SIZE" -lt 1000 ]; then
|
||||
echo "✗ $voice download failed (file too small: ${SIZE} bytes)"
|
||||
rm -f "$MODEL_FILE" "$CONFIG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ $voice downloaded (${SIZE} bytes)"
|
||||
done
|
||||
|
||||
echo ""
|
||||
|
||||
@@ -2,31 +2,18 @@
|
||||
set -e
|
||||
|
||||
# Custom entrypoint for openedai-speech
|
||||
# On first run, copies the default config files into the mounted /app/config/
|
||||
# directory so they're persistent and editable.
|
||||
# Then launches the original entrypoint.
|
||||
# On first run, creates voice_to_speaker.yaml in /app/config/ with:
|
||||
# - Piper English voices (alloy, echo, fable, onyx, nova, shimmer)
|
||||
# - Piper Russian voices (irina, denis) ← for natural Russian
|
||||
# - XTTS voices (alloy, echo, fable, onyx, nova, shimmer)
|
||||
# Then launches the original startup script.
|
||||
|
||||
CONFIG_DIR="/app/config"
|
||||
|
||||
# If config dir is empty (first run), copy defaults from the image
|
||||
# If config dir is empty (first run), create default config
|
||||
if [ ! -f "$CONFIG_DIR/voice_to_speaker.yaml" ]; then
|
||||
echo "[entrypoint] First run: copying default config files..."
|
||||
# Find the default config in the image
|
||||
for f in voice_to_speaker.yaml pre_process_map.yaml subttts.yaml; do
|
||||
# Try common locations
|
||||
for src in /app/$f /app/config/$f /defaults/$f /$f; do
|
||||
if [ -f "$src" ]; then
|
||||
cp "$src" "$CONFIG_DIR/$f"
|
||||
echo "[entrypoint] Copied $f from $src"
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# If voice_to_speaker.yaml still doesn't exist, create a minimal one
|
||||
if [ ! -f "$CONFIG_DIR/voice_to_speaker.yaml" ]; then
|
||||
echo "[entrypoint] Creating default voice_to_speaker.yaml..."
|
||||
cat > "$CONFIG_DIR/voice_to_speaker.yaml" << 'YAML'
|
||||
echo "[entrypoint] First run: creating voice_to_speaker.yaml..."
|
||||
cat > "$CONFIG_DIR/voice_to_speaker.yaml" << 'YAML'
|
||||
tts-1:
|
||||
alloy:
|
||||
model: voices/en_US-amy-medium.onnx
|
||||
@@ -44,6 +31,10 @@ tts-1:
|
||||
model: voices/ru_RU-irina-medium.onnx
|
||||
denis:
|
||||
model: voices/ru_RU-denis-medium.onnx
|
||||
dmitri:
|
||||
model: voices/ru_RU-dmitri-medium.onnx
|
||||
ruslan:
|
||||
model: voices/ru_RU-ruslan-medium.onnx
|
||||
|
||||
tts-1-hd:
|
||||
alloy:
|
||||
@@ -65,8 +56,7 @@ tts-1-hd:
|
||||
model: xtts
|
||||
speaker: voices/shimmer.wav
|
||||
YAML
|
||||
echo "[entrypoint] Created default voice_to_speaker.yaml with Russian Piper voices (irina, denis)"
|
||||
fi
|
||||
echo "[entrypoint] Created voice_to_speaker.yaml with Russian Piper voices (irina, denis, dmitri, ruslan)"
|
||||
fi
|
||||
|
||||
# If pre_process_map.yaml doesn't exist, create an empty one
|
||||
@@ -76,5 +66,5 @@ fi
|
||||
|
||||
echo "[entrypoint] Config ready. Starting openedai-speech..."
|
||||
|
||||
# Run the original entrypoint/cmd
|
||||
exec python /app/app.py
|
||||
# Run the original startup script (openedai-speech uses: bash startup.sh)
|
||||
exec bash /app/startup.sh
|
||||
|
||||
Reference in New Issue
Block a user