fix: handle SSML phoneme attribute order in ssml_to_deepgram#741
Open
NishchayMahor wants to merge 1 commit into
Open
fix: handle SSML phoneme attribute order in ssml_to_deepgram#741NishchayMahor wants to merge 1 commit into
NishchayMahor wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ssml_to_deepgram()only recognized<phoneme>tags when the attributes were inalphabet-before-phorder. Since SSML attribute order is not significant, a perfectly valid tag written the other way was silently dropped:The regex hardcoded
alphabet=... ph=...; when reversed, the tag didn't matchphoneme_patternand 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 pullphout of it, so order no longer matters (src/deepgram/helpers/text_builder.py). If there's nophattribute, it degrades gracefully to the plain word. Behavior for the existingalphabet-first form is unchanged.Testing
Added
test_phoneme_attribute_order_independenttoTestSsmlToDeepgram.pytest tests/custom/test_text_builder.py→ 45 passed. Pure string transformation — no API key/network.