[PR #1221] [MERGED] feat(tts): stream autoplay audio per sentence #4991

Closed
opened 2026-10-22 04:12:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1221
Author: @cha1latte
Created: 5/26/2026
Status: ✅ Merged
Merged: 5/26/2026
Merged by: @cha1latte

Base: refactor ← Head: port/pr-1142-refactor


📝 Commits (3)

  • cc166ed feat(tts): stream autoplay audio per sentence
  • 9712254 test(tts): cover streaming autoplay queue
  • 84ac2a1 test(tts): cover pockettts speak smoke

📊 Changes

13 files changed (+847 additions, -29 deletions)

View changed files

📝 src-tauri/src/commands/storage/integrations/tts.rs (+73 -0)
📝 src/engine/contracts/types/tts.ts (+1 -0)
📝 src/features/modes/conversation/components/ConversationModeRoute.tsx (+1 -0)
📝 src/features/modes/roleplay/components/RoleplayModeRoute.tsx (+1 -0)
📝 src/features/modes/shared/chat-ui/components/ChatMessage.tsx (+23 -8)
📝 src/features/modes/shared/chat-ui/hooks/use-chat-tts-autoplay.ts (+67 -11)
➕ src/features/modes/shared/chat-ui/hooks/use-streaming-tts.test.tsx (+145 -0)
➕ src/features/modes/shared/chat-ui/hooks/use-streaming-tts.ts (+272 -0)
📝 src/features/modes/shared/chat-ui/index.ts (+1 -0)
📝 src/features/shell/settings/components/settings/TTSConfigCard.tsx (+11 -0)
➕ src/shared/lib/sentence-chunker.test.ts (+39 -0)
➕ src/shared/lib/sentence-chunker.ts (+140 -0)
📝 src/shared/lib/tts-dialogue.ts (+73 -10)

📄 Description

Linked issue

Closes #1142

Why this change

  • TTS autoplay currently waits until the model finishes generating before requesting and playing audio. This adds an opt-in streaming autoplay path so conversation, roleplay, and visual novel replies can begin speaking completed sentences while generation is still in progress.

What changed

  • Added a default-off autoplayStreaming TTS setting and surfaced it in the TTS settings card.
  • Added a sentence chunker that emits completed sentences, strips closed thinking blocks, pauses at unclosed thinking blocks, and avoids replay after stream-buffer rewrites.
  • Added a shared streaming TTS hook that watches active chat stream buffers, requests audio per completed sentence, and plays fetched audio sequentially.
  • Wired streaming TTS into conversation, roleplay, and visual novel autoplay while suppressing final-message autoplay when streaming is enabled to avoid duplicate playback.
  • Updated message speaker controls so they can stop an active streaming narration queue.
  • Kept game-mode TTS behavior out of scope.

Refactor impact

Primary owner:

Shared mode UI / TTS configuration

Impact areas reviewed:

  • Engine TTS config contract
  • Rust TTS default storage config
  • Shell settings TTS card
  • Shared chat TTS autoplay hook
  • Conversation and roleplay route wiring
  • Shared TTS dialogue parsing helpers

Boundary notes:

  • Engine contract change is limited to a default-off config field.
  • Rust change is limited to the default stored TTS config.
  • Streaming playback stays in shared chat UI hooks and uses the existing client-side ttsService.generateAudio path.
  • No provider voices endpoint, remote runtime, schema, dependency, or prompt-pipeline changes.
  • Game mode remains untouched.

Pressure points touched:

  • Shared mode UI: use-chat-tts-autoplay, use-streaming-tts, ChatMessage
  • Conversation and roleplay route call sites
  • TTS settings card
  • No ModeSurface, GameSurface, or src-tauri/src/lib.rs command-registration changes

Validation

  • pnpm check passes locally
  • pnpm typecheck passes locally
  • pnpm build passes locally
  • pnpm check:architecture passes locally
  • pnpm check:docs passes locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace passes locally
  • Rust clippy/tests were run for Rust behavior changes
  • Browser or Tauri app manual verification completed
  • Playwright, screenshot, or recording evidence added for UI changes
  • Remote runtime smoke checked when relevant

Manual verification notes

  • Codex ran pnpm test -- src/shared/lib/sentence-chunker.test.ts; 4 tests passed.
  • Codex ran pnpm typecheck; passed.
  • Codex ran pnpm check; passed, including architecture, frontend, Rust, and docs checks.
  • Codex ran pnpm build; passed. Vite emitted existing chunk/import warnings.
  • Codex ran cargo check --manifest-path src-tauri/Cargo.toml --workspace; passed.
  • Codex ran a Playwright app-shell smoke against this worktree's Vite server at http://127.0.0.1:4174; the app loaded as Marinara Engine with no console warnings/errors captured.
  • True provider-audio verification is still pending. Before marking ready, manually enable TTS + autoplay + "Stream as the model generates", send a long conversation/RP reply, confirm audio starts before completion, confirm no duplicate final playback, stop mid-stream from a speaker icon, test regenerate while streaming, and disable the streaming toggle to confirm final autoplay still works.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

No docs or release metadata changed. This is an opt-in TTS setting on the refactor branch.

UI evidence

No GitHub-renderable UI evidence is attached yet. Codex did run a local Playwright app-shell smoke on this worktree's Vite server with no console warnings/errors, but real provider-audio behavior still needs manual verification before ready-for-review.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1221 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 5/26/2026 **Status:** ✅ Merged **Merged:** 5/26/2026 **Merged by:** [@cha1latte](https://github.com/cha1latte) **Base:** `refactor` ← **Head:** `port/pr-1142-refactor` --- ### 📝 Commits (3) - [`cc166ed`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cc166ed13d60cd7d1ab7e93150ebaf981dcfc65d) feat(tts): stream autoplay audio per sentence - [`9712254`](https://github.com/Pasta-Devs/Marinara-Engine/commit/971225434098553f9d6fb3268abac790d6b492e2) test(tts): cover streaming autoplay queue - [`84ac2a1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/84ac2a173effbf44df80fb390c305b52edceccaa) test(tts): cover pockettts speak smoke ### 📊 Changes **13 files changed** (+847 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/integrations/tts.rs` (+73 -0) 📝 `src/engine/contracts/types/tts.ts` (+1 -0) 📝 `src/features/modes/conversation/components/ConversationModeRoute.tsx` (+1 -0) 📝 `src/features/modes/roleplay/components/RoleplayModeRoute.tsx` (+1 -0) 📝 `src/features/modes/shared/chat-ui/components/ChatMessage.tsx` (+23 -8) 📝 `src/features/modes/shared/chat-ui/hooks/use-chat-tts-autoplay.ts` (+67 -11) ➕ `src/features/modes/shared/chat-ui/hooks/use-streaming-tts.test.tsx` (+145 -0) ➕ `src/features/modes/shared/chat-ui/hooks/use-streaming-tts.ts` (+272 -0) 📝 `src/features/modes/shared/chat-ui/index.ts` (+1 -0) 📝 `src/features/shell/settings/components/settings/TTSConfigCard.tsx` (+11 -0) ➕ `src/shared/lib/sentence-chunker.test.ts` (+39 -0) ➕ `src/shared/lib/sentence-chunker.ts` (+140 -0) 📝 `src/shared/lib/tts-dialogue.ts` (+73 -10) </details> ### 📄 Description ## Linked issue Closes #1142 ## Why this change - TTS autoplay currently waits until the model finishes generating before requesting and playing audio. This adds an opt-in streaming autoplay path so conversation, roleplay, and visual novel replies can begin speaking completed sentences while generation is still in progress. ## What changed - Added a default-off `autoplayStreaming` TTS setting and surfaced it in the TTS settings card. - Added a sentence chunker that emits completed sentences, strips closed thinking blocks, pauses at unclosed thinking blocks, and avoids replay after stream-buffer rewrites. - Added a shared streaming TTS hook that watches active chat stream buffers, requests audio per completed sentence, and plays fetched audio sequentially. - Wired streaming TTS into conversation, roleplay, and visual novel autoplay while suppressing final-message autoplay when streaming is enabled to avoid duplicate playback. - Updated message speaker controls so they can stop an active streaming narration queue. - Kept game-mode TTS behavior out of scope. ## Refactor impact Primary owner: Shared mode UI / TTS configuration Impact areas reviewed: - Engine TTS config contract - Rust TTS default storage config - Shell settings TTS card - Shared chat TTS autoplay hook - Conversation and roleplay route wiring - Shared TTS dialogue parsing helpers Boundary notes: - Engine contract change is limited to a default-off config field. - Rust change is limited to the default stored TTS config. - Streaming playback stays in shared chat UI hooks and uses the existing client-side `ttsService.generateAudio` path. - No provider voices endpoint, remote runtime, schema, dependency, or prompt-pipeline changes. - Game mode remains untouched. Pressure points touched: - Shared mode UI: `use-chat-tts-autoplay`, `use-streaming-tts`, `ChatMessage` - Conversation and roleplay route call sites - TTS settings card - No `ModeSurface`, `GameSurface`, or `src-tauri/src/lib.rs` command-registration changes ## Validation - [ ] `pnpm check` passes locally - [ ] `pnpm typecheck` passes locally - [ ] `pnpm build` passes locally - [ ] `pnpm check:architecture` passes locally - [ ] `pnpm check:docs` passes locally - [ ] `cargo check --manifest-path src-tauri/Cargo.toml --workspace` passes locally - [ ] Rust clippy/tests were run for Rust behavior changes - [ ] Browser or Tauri app manual verification completed - [ ] Playwright, screenshot, or recording evidence added for UI changes - [ ] Remote runtime smoke checked when relevant ### Manual verification notes - Codex ran `pnpm test -- src/shared/lib/sentence-chunker.test.ts`; 4 tests passed. - Codex ran `pnpm typecheck`; passed. - Codex ran `pnpm check`; passed, including architecture, frontend, Rust, and docs checks. - Codex ran `pnpm build`; passed. Vite emitted existing chunk/import warnings. - Codex ran `cargo check --manifest-path src-tauri/Cargo.toml --workspace`; passed. - Codex ran a Playwright app-shell smoke against this worktree's Vite server at `http://127.0.0.1:4174`; the app loaded as `Marinara Engine` with no console warnings/errors captured. - True provider-audio verification is still pending. Before marking ready, manually enable TTS + autoplay + "Stream as the model generates", send a long conversation/RP reply, confirm audio starts before completion, confirm no duplicate final playback, stop mid-stream from a speaker icon, test regenerate while streaming, and disable the streaming toggle to confirm final autoplay still works. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [ ] Confirmed this PR does not restore old staging/package-workspace/release claims No docs or release metadata changed. This is an opt-in TTS setting on the refactor branch. ## UI evidence No GitHub-renderable UI evidence is attached yet. Codex did run a local Playwright app-shell smoke on this worktree's Vite server with no console warnings/errors, but real provider-audio behavior still needs manual verification before ready-for-review. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:18 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4991
No description provided.