From 2a160a68b80b84bf8fd872351c0425da2b8187eb Mon Sep 17 00:00:00 2001 From: Apeksha_2022 <70309060+Apeksha9389@users.noreply.github.com> Date: Thu, 22 Oct 2026 13:28:55 +0530 Subject: [PATCH] fix(helpers): preserve SSML breaks with additional attributes --- src/deepgram/helpers/text_builder.py | 12 +++++++++--- tests/custom/test_text_builder.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/deepgram/helpers/text_builder.py b/src/deepgram/helpers/text_builder.py index 8886aeba..b23fecc3 100644 --- a/src/deepgram/helpers/text_builder.py +++ b/src/deepgram/helpers/text_builder.py @@ -297,11 +297,17 @@ def replace_phoneme(match): ssml_text = re.sub(phoneme_pattern, replace_phoneme, ssml_text) # Handle tags - break_pattern = r'' + break_pattern = r"]*?)\s*/>" def replace_break(match): - value = float(match.group(1)) - unit = match.group(2) + time_match = re.search( + r"(?:^|\s)time\s*=\s*([\"'])(\d+(?:\.\d+)?)(ms|s)\1(?=\s|$)", + match.group(1), + ) + if time_match is None: + return match.group(0) + value = float(time_match.group(2)) + unit = time_match.group(3) duration_ms = value * 1000 if unit == "s" else value if not duration_ms.is_integer(): diff --git a/tests/custom/test_text_builder.py b/tests/custom/test_text_builder.py index 5f1f3083..9d69c600 100644 --- a/tests/custom/test_text_builder.py +++ b/tests/custom/test_text_builder.py @@ -554,3 +554,19 @@ def test_standalone_function_workflow(self): assert '"pronounce": "ˌæzəˈθaɪəpriːn"' in text assert '"word": "dupilumab"' in text assert '"pronounce": "duːˈpɪljuːmæb"' in text + + +@pytest.mark.parametrize( + "markup", + [ + '', + "", + '', + '', + ], +) +def test_ssml_break_time_accepts_attribute_spacing_and_order(markup): + ssml = f"Hello{markup}world" + + assert ssml_to_deepgram(ssml) == r"Hello\{pause:500ms\}world" + assert TextBuilder().from_ssml(ssml).build() == r"Hello\{pause:500ms\}world"