Repository navigation
Strip markdown from the speech handed to Assist/TTS - #43
Open
qian2023qian wants to merge 1 commit into
Open
qian2023qian wants to merge 1 commit into
qian2023qian wants to merge 1 commit into
Conversation
Assist passes `intent_response.speech` straight to text-to-speech, so any
markdown left in a reply is read out literally ("asterisk asterisk bold text
asterisk asterisk"). OpenClaw currently sets the speech to the raw response
text.
Add `strip_markdown_for_speech()` to the dependency-free helpers and use it
for the speech only: headings, list markers, quotes, code fences and inline
code, emphasis, strikethrough and link syntax are removed, while words,
numbers, punctuation and emoji are preserved. The chat card and the
`openclaw_message_received` event keep receiving the raw response.
Regression tests cover CJK bold text, a full reported response, headings and
lists, links/inline code, arithmetic such as `3*4=12`, plain text and an
unbalanced emphasis run.
Refs techartdev#6 (the broader voice-mode request). This is the integration-side
safeguard that stays correct even when a voice-optimised agent is in use.
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.
Problem
When OpenClaw answers through the Assist pipeline,
intent_response.speechishanded straight to text-to-speech. The speech is currently set to the raw
response text, so markdown is read out literally:
Reported symptoms include
**being spoken aloud, headings/list markers beingread as symbols, and URLs spelled out character by character.
Change
strip_markdown_for_speech()to the dependency-freehelpers.py:headings, bullets and numbered lists, block quotes, code fences and inline
code,
**/__/*/_emphasis,~~strikethrough~~and[text](url)linksyntax are removed. Words, numbers, punctuation and emoji are preserved, and
arithmetic such as
3*4=12is deliberately left alone.conversation.py. The chat card andthe
openclaw_message_receivedevent keep the raw response, so markdown stillrenders in the UI.
Tests
python -m unittest discover -s tests -v→ 17 tests, 8 of them new:CJK bold text, a full reported response, headings/lists/quotes, links and
inline code, arithmetic (
3*4=12), plain text, empty input, and anunbalanced
**run.22 ×
**before → 0 after, with emoji and numeric values intact.Relation to #6
This is the integration-side safeguard for the markdown part of #6 — it stays
correct even once a voice-optimised agent is in use, and fixes the symptom
immediately for existing setups. It does not implement the voice-origin
detection / TTS-friendly text (numbers, dates, bare URLs) that #6 also asks
for, so I did not mark this as closing it.
Note for the streaming work in #39: once responses are streamed through Assist,
the deltas are piped to TTS directly and the final speech text is no longer what
gets spoken, so the same stripping has to be applied per delta. Happy to prepare
that follow-up if it is useful.