DocsGPT icon indicating copy to clipboard operation
DocsGPT copied to clipboard

πŸ› Bug Report: Speak button reads raw markdown aloud (TTS cleanup dropped in #2126)

Open iam-shanmukha opened this issue 2 months ago β€’ 2 comments

πŸ“œ 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:

  1. Images leave a stray !. The [text](url) regex runs before the ![alt](url) regex, so the image rule never matches: ![diagram](a.png) becomes !diagram.
  2. 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, and CafΓ© rΓ©sumΓ© becomes Caf rsum. The UI ships in de, es, jp, ru, zh and zh-TW, so the Speak button would break for those users.

πŸ‘Ÿ Reproduction steps

  1. 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.
  2. Click the Speak button on the answer.
  3. 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 ![diagram](a.png)")  # '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![diagram](arch.png)')

πŸ’» 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: call clean_text_for_tts() on the text before text_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

iam-shanmukha avatar Oct 04 '26 00:10 iam-shanmukha

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!

iam-shanmukha avatar Oct 04 '26 00:10 iam-shanmukha

Assigned to @iam-shanmukha.

  • Open a PR or post progress within 14 days; otherwise the issue will be made available to others.
  • Read CONTRIBUTING.md and 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.

arc53-machine avatar Oct 04 '26 00:10 arc53-machine