97424cb98f
Full voice pipeline (Whisper STT -> DeepSeek LLM -> OpenAI TTS), animated SVG avatar (Live2D-ready), girly-pop UI, lofi music, timer/notes/pets/wardrobe widgets, 10 background scenes with particle effects, Honcho cross-session memory.
32 lines
825 B
Python
32 lines
825 B
Python
"""Text-to-speech via OpenAI TTS API"""
|
|
|
|
import logging
|
|
from openai import AsyncOpenAI
|
|
from config import settings
|
|
|
|
logger = logging.getLogger("kira.tts")
|
|
|
|
|
|
def _get_client() -> AsyncOpenAI:
|
|
return AsyncOpenAI(api_key=settings.openai_api_key)
|
|
|
|
|
|
async def synthesize_speech(text: str, voice: str = "nova") -> bytes:
|
|
"""Synthesize text to speech audio bytes.
|
|
|
|
Voices available: alloy, echo, fable, nova, shimmer
|
|
Nova is the warmest female voice — fits Kira's personality.
|
|
"""
|
|
try:
|
|
client = _get_client()
|
|
resp = await client.audio.speech.create(
|
|
model="tts-1",
|
|
voice=voice,
|
|
input=text,
|
|
response_format="opus",
|
|
)
|
|
return resp.content
|
|
except Exception as e:
|
|
logger.error(f"TTS error: {e}")
|
|
return b""
|