blu-assistant / src /blu /tts.py
Aravindhan11's picture
Upload 33 files
9776024 verified
raw
history blame contribute delete
734 Bytes
from typing import Optional
import os
def synthesize(text: str, out_path: str = "output.wav", voice: Optional[str] = None) -> str:
"""Simple TTS using Coqui TTS CLI if available; else fallback to pyttsx3."""
voice = voice or "tts_models/en/ljspeech/tacotron2-DDC"
try:
import subprocess
cmd = ["tts", "--text", text, "--model_name", voice, "--out_path", out_path]
subprocess.run(cmd, check=True)
return out_path
except Exception:
try:
import pyttsx3
engine = pyttsx3.init()
engine.save_to_file(text, out_path)
engine.runAndWait()
return out_path
except Exception as e:
return f"TTS failed: {e}"