From 88f8aa49d0694fd368ba5a6b7edb66863bcd8d35 Mon Sep 17 00:00:00 2001 From: adityajai119 Date: Sun, 29 Nov 2026 00:01:33 +0530 Subject: [PATCH] fix(helpers): preserve text outside in ssml_to_deepgram --- src/deepgram/helpers/text_builder.py | 2 +- tests/custom/test_text_builder.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/deepgram/helpers/text_builder.py b/src/deepgram/helpers/text_builder.py index 8886aeba..2f93c4ff 100644 --- a/src/deepgram/helpers/text_builder.py +++ b/src/deepgram/helpers/text_builder.py @@ -273,7 +273,7 @@ def ssml_to_deepgram(ssml_text: str) -> str: speak_pattern = r"]*>(.*?)" speak_match = re.search(speak_pattern, ssml_text, re.DOTALL) if speak_match: - ssml_text = speak_match.group(1) + ssml_text = re.sub(speak_pattern, r"\1", ssml_text, flags=re.DOTALL) # Process the SSML text # Parse XML fragments manually to handle mixed content diff --git a/tests/custom/test_text_builder.py b/tests/custom/test_text_builder.py index 5f1f3083..5e07d251 100644 --- a/tests/custom/test_text_builder.py +++ b/tests/custom/test_text_builder.py @@ -318,6 +318,13 @@ def test_speak_wrapper(self): result = ssml_to_deepgram(ssml) assert result == "Hello world" + + def test_speak_wrapper_preserves_surrounding_text(self): + """Text outside a wrapper must not be discarded.""" + ssml = "Before Inside after" + result = ssml_to_deepgram(ssml) + + assert result == "Before Inside after" def test_complex_ssml_rejects_mixed_controls(self): """Flux batch cannot combine SSML phoneme and break controls."""