mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #1139] [CLOSED] feat(tts): stream audio per sentence as the model generates #4941
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#4941
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1139
Author: @etherious1804
Created: 5/24/2026
Status: ❌ Closed
Base:
staging← Head:feat/tts-streaming-autoplay📝 Commits (1)
b1b0d32feat(tts): stream audio per sentence as the model generates📊 Changes
5 files changed (+476 additions, -0 deletions)
View changed files
📝
packages/client/src/components/chat/ChatArea.tsx(+26 -0)📝
packages/client/src/components/panels/settings/TTSConfigCard.tsx(+11 -0)➕
packages/client/src/hooks/use-streaming-tts.ts(+289 -0)➕
packages/client/src/lib/sentence-chunker.ts(+141 -0)📝
packages/shared/src/types/tts.ts(+9 -0)📄 Description
Linked issue
Closes #1138
Why this change
When auto-play is on, Marinara waits for
isStreamingto flip to false before dispatching the entire reply to TTS. That flag only flips after the full LLM response AND post-processing agents have completed. For local TTS providers (mlx-audio with Chatterbox / Higgs / etc.), where synthesis isn't as fast as cloud APIs, this means users wait the full 5-30s reply time before hearing any audio. The information to start earlier is already in the chat store —streamBuffersupdates token-by-token. We can chunk on sentence boundaries and dispatch each completed sentence to/api/tts/speakimmediately.What changed
packages/shared/src/types/tts.ts— newautoplayStreaming: booleanfield onttsConfigSchema, defaultfalse. Existing users are unaffected by virtue of the default and Zod's schema-fills-missing-fields behavior.packages/client/src/lib/sentence-chunker.ts(new) — pure-logic chunker that, given a growing buffer, returns each newly-completed sentence on every call. Handles inline thinking-block patterns (<think>,<thinking>,<thought>,<|think|>,<|channel>thought) so models that emit reasoning inline aren't spoken. Defensive againstcontent_replaceSSE events (server can shorten the buffer mid- or end-of-stream).packages/client/src/hooks/use-streaming-tts.ts(new) — React hook that subscribes to the chat store and runs a streaming session for the active chat. Each completed sentence kicks a TTS fetch immediately; the resulting blobs play sequentially through chained HTMLAudioElement instances. Key design points:ttsServicesingleton. The hook tracks its own audios and never callsttsService.stop(), so per-message "speak this message" buttons elsewhere keep working unaltered.AbortSignalat session start — teardown fires immediately instead of waiting for theisStreaming → falsetransition (which can lag several hundred ms behind the abort).{once: true}listener with explicitremoveEventListeneron the natural-end path. No accumulation across long replies.audio.playbackRate = cfg.speedis applied client-side, so the slider works uniformly regardless of whether the local TTS server respects thespeedAPI parameter.packages/client/src/components/panels/settings/TTSConfigCard.tsx— exposes the new toggle under the existing Auto-play group.packages/client/src/components/chat/ChatArea.tsx— invokes the hook gated oncfg.enabled && cfg.autoplayStreaming && mode-specific autoplay flag. When streaming TTS is active, the existing end-of-stream autoplay early-returns to avoid double-speaking the reply.No server-side changes. Existing autoplay path is untouched.
Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
Tested against a local mlx-audio server running Chatterbox Turbo with a cloned-voice registry entry (
http://127.0.0.1:8081/v1):pnpm checkran cleanly end-to-end (TS + ESLint + production build). The only WARN lines are pre-existingUnsupported enginenotices for node 26 vs>=24 <26— unrelated.AbortSignallistener path verified by settingisStreamingflips to false 200-400ms after Stop on this machine, and audio still stops immediately, confirming the abort listener fires earlier than the isStreaming-based path.ttsService.speakSequenceand now coexists with the streaming session. (Two audios overlapping is an existing-tool limitation, not a regression; flagged as a follow-up if Marinara wants to enforce single-active-playback across both code paths.)enable_thinking=true(model emits<thought>...</thought>inline). The chunker waited for the closing tag and never dispatched the thinking content to TTS. Once the close arrived, the actual reply was spoken correctly.if (cfg.autoplayStreaming) return;guard. With the toggle off, behavior is identical to before this PR (verified by toggling and observing).Reviewer should: enable the toggle in TTS settings, ensure mode-specific autoplay is on (e.g.
autoplayRP), then send a roleplay message and listen for the first audio within ~2s. Try Stop mid-reply. Try the speed slider. Try a per-message play button.Docs and release impact
No documentation updated. The new toggle has self-explanatory label + sits next to the existing autoplay toggles. If maintainers want a doc note for the FAQ ("Why does TTS feel slow with local providers? Try the streaming toggle"), I can add it in a follow-up.
UI evidence (if applicable)
No new UI surface beyond a single ToggleRow consistent with the surrounding rows (autoplayRP / autoplayConvo / autoplayGame). No screenshots; the visual diff is one new row labeled "Stream as the model generates" under Auto-play.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.