elysium / backend /tts /debate_sequencer.py
pmrinal2005's picture
Upload folder using huggingface_hub
a521353 verified
Raw
History Blame
993 Bytes
"""Sequences multiple agent utterances into one debate audio drama."""
import uuid
from pathlib import Path
from pydub import AudioSegment
from ..config import AUDIO_CACHE
from .voxcpm_engine import synthesize
def build_debate(agent_outputs: list) -> str | None:
"""Returns a server-relative path under /audio/... for the frontend."""
if not agent_outputs:
return None
track = AudioSegment.silent(duration=300)
for ao in agent_outputs:
text = ao.get("tts_speech_text", "")
voice = ao.get("tts_voice_design", {}) or {}
wav_path = synthesize(text, voice)
try:
seg = AudioSegment.from_wav(wav_path)
track += seg + AudioSegment.silent(duration=400)
except Exception:
continue
out_path = AUDIO_CACHE / f"debate_{uuid.uuid4().hex}.wav"
track.export(out_path, format="wav")
# Return /audio/<filename> for the static mount
return f"/audio/{out_path.name}"