Fix TTS cleanText bugs causing incomplete speech playback #902
+58
−64
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.
Summary
Fixes multiple critical bugs in the TTS system that caused incomplete speech playback and mangled text output.
Fixes #901
Problems Fixed
1. cleanText() Regex Bug (Primary Issue)
The regex pattern was fundamentally broken, matching from any opening tag to any closing tag and destroying content in between.
Before:
After: Replaced with DOMParser for proper HTML parsing
2. Streaming Race Condition
The for-loop would exit after speaking available chunks. If the
finished=trueupdate arrived while speech was running (polling interval: 25ms), it would be ignored and remaining chunks never spoken.Fix: Replaced for-loop with continuous while-loop that checks for new chunks until stream finishes.
3. Audio Cancellation Bug
Both
speakWithBrowser()andspeakWithKokoro()calledstopAudio()even whenwaitForPrevious=true, canceling speech immediately after waiting for it.Fix: Only call
stopAudio()when NOT waiting for previous speech.4. Replay Button Issue
The speak button extracted plain text instead of HTML, preventing
cleanText()from finding<pre>and<code>tags.Fix: Pass HTML to
cleanText()so code blocks are properly replaced with placeholder.Testing
Files Changed
webui/components/chat/speech/speech-store.jscleanText()with DOMParserspeakStream()stopAudio()logic inspeakWithBrowser()andspeakWithKokoro()webui/components/messages/action-buttons/simple-action-buttons.js