feat(tts): echtes lokales TTS via piper (kein Stub mehr)

PiperTTSProvider ruft das piper-Binary (--output-raw) async auf, liest die native
Sample-Rate aus der .onnx.json und resampelt per ffmpeg auf 24000 Hz (Gateway-Norm).
Nicht passende Stimmen (z. B. Cloud-Stimme 'Zephyr' aus der Route) fallen auf die
konfigurierte Default-Stimme zurueck. Damit ist eine voll-lokale Konstellation
(faster-whisper + Ollama + piper) moeglich -> keine API-Kosten, max. Datenschutz.

- config: PIPER_BIN/PIPER_VOICES_DIR/PIPER_VOICE/TTS_SAMPLE_RATE (+ .env.example)
- dependencies: piper-Factory mit Settings verdrahtet
- tests: tests/test_piper_tts.py (offline, Fake-Binary; Resample-Test skippt ohne ffmpeg);
  e2e/auth-Tests nutzen jetzt einen Stub-TTS statt 'piper' als Pseudo-Stub
- docs: README, BEDIENUNGSANLEITUNG (voll-lokal-Beispiel), Architektur-Roadmap

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-06-17 22:11:20 +02:00
commit cca423dac3
10 changed files with 269 additions and 15 deletions

View file

@ -9,15 +9,25 @@ from tests.conftest import loopback_output
client = TestClient(app)
def test_speak_loopback_collects_chunks():
# piper-Stub liefert b"" -> kein Netzcall; Loopback sammelt den Chunk.
def _stub_tts(monkeypatch, name="stub-tts", audio=b""):
"""Registriert einen deterministischen TTS-Stub (kein Netz, kein lokales Binary)."""
class StubTTS:
async def synthesize(self, text, voice=None, audio_format="pcm"):
return audio
monkeypatch.setitem(deps.TTS_REGISTRY, name, lambda s: StubTTS())
return name
def test_speak_loopback_collects_chunks(monkeypatch):
# Stub-TTS liefert b"" -> kein Netzcall; Loopback sammelt den Chunk.
tts = _stub_tts(monkeypatch)
resp = client.post(
"/api/speak",
json={"text": "Hallo Welt", "tts_provider": "piper", "output_endpoint": "loopback"},
json={"text": "Hallo Welt", "tts_provider": tts, "output_endpoint": "loopback"},
)
assert resp.status_code == 200
assert resp.headers["X-Output-Endpoint"] == "loopback"
assert resp.headers["X-TTS-Provider"] == "piper"
assert resp.headers["X-TTS-Provider"] == tts
assert len(loopback_output().chunks) == 1
@ -35,15 +45,16 @@ def test_unknown_provider_returns_422():
assert resp.status_code == 422
def test_session_route_applies():
def test_session_route_applies(monkeypatch):
tts = _stub_tts(monkeypatch)
client.post(
"/api/sessions/s1/route",
json={"tts_provider": "piper", "output_endpoint": "loopback"},
json={"tts_provider": tts, "output_endpoint": "loopback"},
)
resp = client.post("/api/speak?session_id=s1", json={"text": "hallo"})
assert resp.status_code == 200
assert resp.headers["X-Output-Endpoint"] == "loopback"
assert resp.headers["X-TTS-Provider"] == "piper"
assert resp.headers["X-TTS-Provider"] == tts
def test_chat_per_request_override_and_loopback(monkeypatch):