Repository navigation
fix(helpers): decode XML entities in ssml_to_deepgram - #812
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
RaphaelFakhri
requested review from
GregHolmes,
deepgram-kiley and
dg-coreylweathers
as code owners
October 22, 2026 12:46
This branch has not been deployed
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()andTextBuilder.from_ssml()strip SSML tags but never decode XML entities. SSML is XML, so text such asAT&Torit'sis commonly written asAT&Torit's. Those entities reach the TTS request unchanged, so the voice reads the markup:Fix
src/deepgram/helpers/text_builder.pydecodes the five predefined XML entities (&,<,>,",') and numeric character references (',ˈ):<phoneme>word andphvalue, before building the pronunciation control, sojson.dumpsescapes the decoded characters correctly.<break/>stays literal text instead of being parsed or removed. Inline controls are skipped so they are not decoded twice. A<phoneme>without an IPA alphabet keeps its word as text, which is decoded once in this step.The decoder handles XML entities only. HTML-only names such as
©and bare&are left unchanged.Testing
Added four tests to
TestSsmlToDeepgramintests/custom/test_text_builder.py: entities in text, entities in a<phoneme>word andphvalue, escaped markup that must stay text, and a non-IPA<phoneme>whose word is decoded only once.pytest tests/custom/test_text_builder.pygives 4 failed, 56 passed.ruff checkpasses andmypy src/deepgram/helpersreports no issues.Fixes #811