Initial commit: Voice Assistant Gateway mit Konfig-/Routing-Fundament
- FastAPI-Gateway mit REST-Endpunkten (chat/speak/transcribe/devices/sessions/config) - Geschichtete Konfiguration mit Profilen (local-dev/hybrid/cloud) via TOML + ENV - Registry-Pattern + einheitliche Route-Aufloesung (Default->Profil->ENV->Session->Request) - Device Router (strikt, Singleton) und Output-Lifecycle im Orchestrator - OpenRouter-Adapter (STT multipart/LLM/TTS) + lokale Provider-Stubs - Regelbasierte Pipeline (Cleaner/Spoken-Adapter/TTS-Normalizer) - 22 automatisierte Tests; Doku: README, BEDIENUNGSANLEITUNG, Architektur - Secrets ausschliesslich ueber Umgebung; .env und lokale config gitignored Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
commit
293ed257db
72 changed files with 2612 additions and 0 deletions
60
app/api/speak.py
Normal file
60
app/api/speak.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
from io import BytesIO
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from app.config import settings
|
||||
from app.errors import RoutingError
|
||||
from app.dependencies import (
|
||||
resolve_route,
|
||||
build_orchestrator,
|
||||
resolve_output_endpoint,
|
||||
)
|
||||
from app.schemas import SpeakRequest
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/speak")
|
||||
async def speak(
|
||||
payload: SpeakRequest,
|
||||
session_id: str | None = Query(
|
||||
default=None,
|
||||
description="Optional session id to apply a stored route",
|
||||
),
|
||||
):
|
||||
overrides = {
|
||||
"output_endpoint": payload.output_endpoint,
|
||||
"language": payload.language,
|
||||
"tts_provider": payload.tts_provider,
|
||||
}
|
||||
route = resolve_route(session_id, overrides)
|
||||
voice = payload.voice or settings.openrouter_tts_voice
|
||||
|
||||
try:
|
||||
orchestrator = build_orchestrator(route)
|
||||
output = await resolve_output_endpoint(route)
|
||||
except RoutingError as exc:
|
||||
raise HTTPException(status_code=422, detail=str(exc))
|
||||
|
||||
try:
|
||||
audio = await orchestrator.speak_only(
|
||||
payload.text,
|
||||
voice=voice,
|
||||
language=route.language,
|
||||
output=output,
|
||||
)
|
||||
|
||||
headers = {
|
||||
"Content-Language": route.language,
|
||||
"X-Audio-Format": "pcm",
|
||||
"X-Audio-Sample-Rate": "24000",
|
||||
"X-Audio-Channels": "1",
|
||||
"X-Audio-Sample-Width": "16",
|
||||
"X-Output-Endpoint": route.output_endpoint,
|
||||
"X-TTS-Provider": route.tts_provider,
|
||||
}
|
||||
return StreamingResponse(BytesIO(audio), media_type="audio/pcm", headers=headers)
|
||||
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=502, detail=str(exc))
|
||||
Loading…
Add table
Add a link
Reference in a new issue