Skip to content

fix: handle SSML phoneme attribute order in ssml_to_deepgram#741

Open
NishchayMahor wants to merge 1 commit into
deepgram:mainfrom
NishchayMahor:fix/ssml-phoneme-attribute-order
Open

fix: handle SSML phoneme attribute order in ssml_to_deepgram#741
NishchayMahor wants to merge 1 commit into
deepgram:mainfrom
NishchayMahor:fix/ssml-phoneme-attribute-order

Conversation

@NishchayMahor

Copy link
Copy Markdown

What

ssml_to_deepgram() only recognized <phoneme> tags when the attributes were in alphabet-before-ph order. Since SSML attribute order is not significant, a perfectly valid tag written the other way was silently dropped:

ssml_to_deepgram('<phoneme alphabet="ipa" ph="ˌæzə">azathioprine</phoneme>')
# -> {"word": "azathioprine", "pronounce": "ˌæzə"}   ✅

ssml_to_deepgram('<phoneme ph="ˌæzə" alphabet="ipa">azathioprine</phoneme>')
# -> "azathioprine"   ❌  pronunciation silently lost

The regex hardcoded alphabet=... ph=...; when reversed, the tag didn't match phoneme_pattern and fell through to the generic <[^>]+> strip, leaving only the bare word — no error, so the caller never knows the pronunciation was dropped.

Fix

Match the <phoneme> attributes as a group and pull ph out of it, so order no longer matters (src/deepgram/helpers/text_builder.py). If there's no ph attribute, it degrades gracefully to the plain word. Behavior for the existing alphabet-first form is unchanged.

Testing

Added test_phoneme_attribute_order_independent to TestSsmlToDeepgram. pytest tests/custom/test_text_builder.py45 passed. Pure string transformation — no API key/network.

ssml_to_deepgram only matched <phoneme> tags with alphabet before ph, so
<phoneme ph="..." alphabet="ipa">word</phoneme> silently lost its
pronunciation and fell through to the generic tag strip, leaving the bare
word. SSML attribute order is not significant, so match the attributes as a
group and pull ph out of it. Add a regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant