merlyn/frontend
Gopal Bagaswar 7d884c7863
fix(tts): strip Markdown syntax before sending text to TTS engines (#5560)
* fix(tts): strip Markdown syntax before sending text to TTS engines

Chat responses are rendered as Markdown but the TTS components piped the
raw response into Piper / the browser's `SpeechSynthesis` API. The
synthesizer reads every special character literally — `**bold**` becomes
"asterisk asterisk bold asterisk asterisk", `# Heading` becomes "pound
heading", code fences are read backtick-by-backtick, and bullet lists
become "hyphen item". The result is unintelligible whenever the assistant
includes any formatting, which is most of the time.

This commit adds a small `messageToSpeech` helper that converts a
Markdown chat message into plain text suitable for TTS:

- fenced code blocks and images are dropped (nothing useful to read)
- inline code and link labels keep their text content
- emphasis markers, headings, blockquote markers, list markers, and
  horizontal rules are stripped while preserving the underlying words
- HTML tags are removed but their text content kept
- table pipes become commas so rows read naturally

The helper is regex-based — no new dependency — and is wired into both
the native (`SpeechSynthesis`) and Piper TTS components in
`WorkspaceChat/ChatContainer/ChatHistory/HistoricalMessage/Actions/TTSButton`.

Closes #5557.
---
Co-authored-by: Timothy Carambat <rambat1010@gmail.com>
2026-05-01 12:44:19 -07:00
..
public normalize logo wordmark 2026-02-11 08:53:44 -08:00
scripts Enable editing and setting of meta-tag information (#1892) 2024-07-19 15:58:43 -07:00
src fix(tts): strip Markdown syntax before sending text to TTS engines (#5560) 2026-05-01 12:44:19 -07:00
.env.example chore: rename Github to GitHub (#3199) 2025-02-13 10:45:43 -08:00
.gitignore Icon Button Tooltips (#1451) 2024-05-18 23:29:23 -05:00
.nvmrc dev build with new epub2 build target and remove patch work (#4694) 2025-11-26 17:36:34 -08:00
eslint.config.js feat: Enable essential ESLint rules and refactor frontend lint config (#4923) 2026-01-29 17:01:39 -08:00
index.html 4595 refactor PWA (#4664) 2025-11-19 16:08:09 -08:00
jsconfig.json [FEAT] Agent skills UI redesign (#1565) 2024-06-12 10:52:32 -07:00
package.json feat: Scheduled Jobs (#5322) 2026-04-29 12:05:46 -07:00
postcss.config.js inital commit 2023-06-03 19:28:07 -07:00
tailwind.config.js 4595 refactor PWA (#4664) 2025-11-19 16:08:09 -08:00
vite.config.js Add piperTTS in-browser text-to-speech (#2052) 2024-08-07 11:09:51 -07:00
yarn.lock feat: Scheduled Jobs (#5322) 2026-04-29 12:05:46 -07:00