Voice selection and SSML

Voice carries half the persona. A snappy support agent and a calm clinic receptionist need different voices, different pacing, and a touch of SSML to handle pauses around numbers and ID strings. The trick is doing this without losing the streaming win.

Voice selection tradeoffs

Latency, naturalness, SSML support, and cost vary across providers. Pick on the axes that matter for the persona.

agent/tts.py
python
def to_ssml(text: str) -> str:
    # Insert short pauses around numeric ids so callers actually catch them.
    # Keep emphasis sparse so it does not feel theatrical.
    text = re.sub(r'\b([A-Z]{2,}\d{2,})\b', r'<break time="120ms"/>\1<break time="120ms"/>', text)
    return f'<speak>{text}</speak>'

Light SSML, applied only where it matters. Heavy SSML slows synthesis and feels robotic. Two breaks around an order id is plenty.

Quiz: Quiz

Loading practice…