π Bug Report: Speak button reads raw markdown aloud (TTS cleanup dropped in #2126)
π Description
The "Speak" button on chat answers reads raw markdown aloud. POST /api/tts hands data["text"] straight to the TTS provider, so the voice reads out ##, **, full link URLs and whole code blocks.
This is a regression. #2112 added a clean_text_for_tts() call to the TTS route for exactly this case. Six days later, #2126 (an unrelated multi-file upload change) removed that call, apparently by accident. clean_text_for_tts() in docsgpt/utils.py has had no callers since.
Putting the call back as-is would bring back two bugs in the cleaner itself:
- Images leave a stray
!. The[text](url)regex runs before theregex, so the image rule never matches:becomes!diagram. - All non-ASCII characters are deleted.
[^\x20-\x7E\n\r\t]is meant to drop emoji, but it also drops letters.γγγ«γ‘γ―becomes an empty string,ΠΡΠΈΠ²Π΅Ρbecomes empty, andCafΓ© rΓ©sumΓ©becomesCaf rsum. The UI ships in de, es, jp, ru, zh and zh-TW, so the Speak button would break for those users.
π Reproduction steps
- Set a TTS provider (for example
TTS_PROVIDER=google_tts) and ask a question whose answer contains a heading, bold text, a link or a code block. - Click the Speak button on the answer.
- The voice reads the markdown syntax and the full URL.
At the function level, on main:
from docsgpt.utils import clean_text_for_tts
clean_text_for_tts("See ") # 'See !diagram'
clean_text_for_tts("γγγ«γ‘γ―") # ''
clean_text_for_tts("CafΓ© rΓ©sumΓ©") # 'Caf rsum'
π Expected behavior
The TTS route strips markdown before synthesis, images are removed completely, and only emoji and symbols are removed, so letters in every script are kept.
π Actual Behavior with Screenshots
The provider receives the raw markdown. A route test that mocks the provider shows the exact input:
text_to_speech('## Setup\n**Run** the [installer](https://example.com/install).\n```bash\n./setup.sh\n```\n')
π» Operating system
Linux
π€ What development environment are you experiencing this bug on?
Local dev server
π Provide any additional context for the Bug.
Proposed fix (about 20 lines plus tests):
docsgpt/api/user/attachments/routes.py: callclean_text_for_tts()on the text beforetext_to_speech().docsgpt/utils.py: run the image regex before the link regex. Replace the ASCII-only filter with one that drops Unicode symbol, format and private-use characters and variation selectors (emoji, ZWJ sequences, skin tones). ASCII handling stays exactly as it is now.- Tests: a route test that checks the provider gets cleaned text, and unit tests for images, emoji sequences, five non-Latin or accented scripts, and unchanged ASCII behaviour.
I have this working locally with red/green tests. tests/test_utils.py, tests/api/user/attachments and tests/tts all pass, and ruff is clean.
AI disclosure: I used an AI coding assistant (Claude Code) to help find this bug, trace the regression and draft the fix and tests. I have reviewed and run all of it myself and understand the change.
π Have you spent some time to check if this bug has been raised before?
- [x] I checked and didn't find similar issue
π Are you willing to submit PR?
Yes, I am willing to submit a PR!
π§ββοΈ Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Hi maintainers, I have a tested fix ready for this (details in the issue). Could you assign this to me so I can open the PR? Thanks!
Assigned to @iam-shanmukha.
- Open a PR or post progress within 14 days; otherwise the issue will be made available to others.
- Read
CONTRIBUTING.mdand include the route and text-cleaning regression tests. - Include a screenshot or short recording demonstrating the Speak change in the PR.
Automated triage. A maintainer will follow up.