agents icon indicating copy to clipboard operation
agents copied to clipboard

SSML Tags are getting dropped in TTS node for ElevenLabs on 1.2.7 and above

Open shivamkataria2000 opened this issue 1 year ago • 4 comments

SSML Tags are getting dropped in TTS node for ElevenLabs on 1.2.7 and above

Problem

SSML <break> tags are being stripped from ElevenLabs TTS output after upgrading from v1.2.6 to v1.2.7+. Tags appear in LLM generation (visible in Langfuse traces) but disappear from final transcripts.

Environment

  • Broken: LiveKit v1.2.7, v1.2.8
  • Working: LiveKit v1.2.6
  • TTS: ElevenLabs with enable_ssml_parsing=True

Reproduction

Expected: Hey... <break time="0.4s" /> how's your Wednesday going? Actual: Hey... . how's your Wednesday going?

Configuration

{
    'model': 'eleven_flash_v2_5',
    'auto_mode': True,
    'enable_ssml_parsing': True
}

Impact

Regression breaks natural speech timing/pacing control in conversational AI.

Image Image

shivamkataria2000 avatar Sep 02 '25 21:09 shivamkataria2000

can you share your full agent configuration, do you have the use_tts_aligned_transcript enabled? if so the tag was actually sent to the TTS but filtered out from the output transcription by elevenlabs.

longcw avatar Sep 03 '25 02:09 longcw

Yes, use_tts_aligned_transcript is set to True. I found the issue. This got introduced with this commit https://github.com/livekit/agents/commit/81c9cc8f46a93c8dc47e5c93c49d51acfefffc65 where we started using normalizedAlignment instead of alignment from 11labs response.

Create a PR to resolve it https://github.com/livekit/agents/pull/3336

shivamkataria2000 avatar Sep 03 '25 09:09 shivamkataria2000

@shivamkataria2000 thanks for the issue and PR. I was triaging a regression and came across this post which pointed us in the right direction.

We also use elevenlabs with pronunciation controls via a lightly modified version of https://docs.livekit.io/agents/build/audio/#pronunciation to accommodate their use of cmu-arpabet phoneme tags. We set use_tts_aligned_transcript = False. In our case, our TTS stops yielding output with an exception whenever it encounters a chunk with SSML tags. I'm unsure why the normalized alignments are problematic but using your "original" alignment resolves it for us.

Exception below for reference:

{
    "message": "recv loop error\nTraceback (most recent call last):\n  File \"/voice/.venv/lib/python3.12/site-packages/livekit/plugins/elevenlabs/tts.py\", line 641, in _recv_loop\n    timed_words, stream._text_buffer = _to_timed_words(\n                                       ^^^^^^^^^^^^^^^^\n  File \"/voice/.venv/lib/python3.12/site-packages/livekit/plugins/elevenlabs/tts.py\", line 796, in _to_timed_words\n    end_t = timestamps[end] / 1000\n            ~~~~~~~~~~^^^^^\nIndexError: list index out of range",
    "level": "WARNING",
    "name": "livekit.plugins.elevenlabs",
    "room": "livekit-web-20250902T1953-RCZVbF-DEVTEST",
    "pid": 155074,
    "job_id": "AJ_t7UEEVkjaMKP",
    "timestamp": "2025-09-02T19:54:07.959040+00:00"
}{
    "message": "failed to synthesize speech, retrying in 0.1s\nTraceback (most recent call last):\n  File \"/voice/.venv/lib/python3.12/site-packages/livekit/plugins/elevenlabs/tts.py\", line 420, in _run\n    await waiter\n  File \"/voice/.venv/lib/python3.12/site-packages/livekit/plugins/elevenlabs/tts.py\", line 641, in _recv_loop\n    timed_words, stream._text_buffer = _to_timed_words(\n                                       ^^^^^^^^^^^^^^^^\n  File \"/voice/.venv/lib/python3.12/site-packages/livekit/plugins/elevenlabs/tts.py\", line 796, in _to_timed_words\n    end_t = timestamps[end] / 1000\n            ~~~~~~~~~~^^^^^\nIndexError: list index out of range\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n  File \"/voice/.venv/lib/python3.12/site-packages/livekit/agents/tts/tts.py\", line 357, in _main_task\n    await self._run(output_emitter)\n  File \"/voice/.venv/lib/python3.12/site-packages/livekit/plugins/elevenlabs/tts.py\", line 426, in _run\n    raise APIStatusError(\"Could not synthesize\") from e\nlivekit.agents._exceptions.APIStatusError: Could not synthesize (status_code=-1, request_id=None, body=None, retryable=True)",
    "level": "WARNING",
    "name": "livekit.agents",
    "room": "livekit-web-20250902T1953-RCZVbF-DEVTEST",
    "tts": "livekit.plugins.elevenlabs.tts.TTS",
    "attempt": 1,
    "streamed": true,
    "pid": 155074,
    "job_id": "AJ_t7UEEVkjaMKP",
    "timestamp": "2025-09-02T19:54:07.964967+00:00"
}

yuyuma avatar Sep 03 '25 19:09 yuyuma

@shivamkataria2000 thanks for the pr, I created a new one with a fix for the comment of @yuyuma #3341

longcw avatar Sep 04 '25 02:09 longcw