59856bd4fc
Services: Pipecat agent (LiveKit + Claude + Whisper STT + Piper TTS), SpeechBrain analysis service, Piper TTS service, web client (nginx). Includes LiveKit server config and docker-compose orchestration. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
35 lines
986 B
Python
Executable File
35 lines
986 B
Python
Executable File
"""
|
|
Piper TTS client for Pipecat pipeline.
|
|
Calls the self-hosted Piper HTTP service.
|
|
"""
|
|
import io
|
|
import logging
|
|
import wave
|
|
import httpx
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class PiperTTSClient:
|
|
"""HTTP client for the Piper TTS service."""
|
|
|
|
def __init__(self, base_url: str = "http://piper-tts:8003"):
|
|
self.base_url = base_url.rstrip("/")
|
|
self._client = httpx.AsyncClient(timeout=10.0)
|
|
|
|
async def synthesize(self, text: str) -> bytes:
|
|
"""Convert text to WAV audio bytes via Piper service."""
|
|
try:
|
|
response = await self._client.post(
|
|
f"{self.base_url}/synthesize",
|
|
json={"text": text, "length_scale": 0.95, "sentence_silence": 0.15},
|
|
)
|
|
response.raise_for_status()
|
|
return response.content
|
|
except Exception as e:
|
|
logger.error(f"Piper TTS failed: {e}")
|
|
return b""
|
|
|
|
async def close(self):
|
|
await self._client.aclose()
|