[PR #1143] [CLOSED] feat(tts): auto-split quoted dialogue from prose narration #4944

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1143
Author: @etherious1804
Created: 5/24/2026
Status: ❌ Closed

Base: staging ← Head: feat/tts-narrator-auto-split


📝 Commits (3)

  • 0954666 fix(tts): apply playback rate client-side for local OAI-compatible servers
  • efdf859 feat(tts): stream audio per sentence as the model generates
  • 393ee8c feat(tts): auto-split quoted dialogue from prose narration

📊 Changes

8 files changed (+814 additions, -28 deletions)

View changed files

📝 packages/client/src/components/chat/ChatArea.tsx (+35 -2)
📝 packages/client/src/components/chat/ChatMessage.tsx (+52 -23)
📝 packages/client/src/components/panels/settings/TTSConfigCard.tsx (+13 -0)
➕ packages/client/src/hooks/use-streaming-tts.ts (+368 -0)
➕ packages/client/src/lib/sentence-chunker.ts (+246 -0)
📝 packages/client/src/lib/tts-dialogue.ts (+79 -2)
📝 packages/client/src/lib/tts-service.ts (+12 -1)
📝 packages/shared/src/types/tts.ts (+9 -0)

📄 Description

Linked issue

Closes #1144

Why this change

When narratorVoiceEnabled is configured with single-voice mode (no <speaker> tags from the model), the entire reply currently plays in the character's voice — even the action prose. The configured narrator voice is set but never selected. Users who set up a separate narrator (intending a novel-style narrator-reads-the-action, character-speaks-the-dialogue split) hear a single voice reading every word.

Roleplay convention already disambiguates this without structured tags: "..." is speech, surrounding prose is narration. This PR acts on that convention. Applies to both on-demand playback (speaker icon) AND the streaming-TTS path (#1142).

What changed

Client — quote-aware dialogue/narration splitter

  • packages/client/src/lib/tts-dialogue.ts: new splitQuotedDialogueAndNarration(text, fallbackSpeaker) walks the text. Each quoted span (matched against the existing DIALOGUE_QUOTE_PATTERN_SOURCE — covers ASCII, smart double, guillemet, and Japanese corner/double-corner pairs) becomes a { speaker: fallbackSpeaker } utterance; surrounding prose becomes { speaker: "Narrator" }. The previous fallback that re-routed all-narrator output back to character voice has been removed — when narrator is enabled, narration-only chunks correctly stay on the narrator voice (matters for streaming where the first chunk may be action-only).
  • buildTTSVoiceRequests invokes the new splitter when narratorVoiceEnabled && !dialogueOnly && !hasSpeakerTags && voiceMode === "single". Other paths (speaker-tagged output, dialogue-only, per-character voices) are untouched.

Client — quote-aware sentence chunker

  • packages/client/src/lib/sentence-chunker.ts: new isInsideUnclosedQuote(text, pos) walks [0..pos) tracking the same five quote pairs the splitter recognizes. ASCII " is treated as a toggle (no separate close form); smart/guillemet/Japanese pairs use a paired stack. A sentence-end candidate that falls inside an open quote is skipped — so a multi-sentence dialogue block like "Hello. How are you. I am fine." emits as one chunk at the closing quote, not fragmented into pieces with unbalanced quotes the splitter can't classify.

Without this chunker change, the streaming-TTS path (#1142) would fragment quoted dialogue mid-stream — each piece would have an unbalanced quote, fall through the splitter's pattern match, and route to all-narrator. The visible symptom would be "dialogue-heavy reply plays entirely in the narrator voice when streaming." The on-demand path doesn't hit this because it works on the full message text, not a growing buffer.

Dependency

Includes #1141 (client-side playback rate) and #1142 (streaming TTS) as base commits. Once those merge, this PR's diff will shrink to just the narrator-split changes.

Validation

  • pnpm check passes locally

  • Container (Docker / Podman) built and ran without issue

  • Ran the app, clicked through the changes manually

  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)

  • Above manual verification completed (describe below)

  • Read and followed CONTRIBUTING.md

Manual verification notes

Generated PR — unchecked boxes are left for the merger to confirm manually per the repo's AI-PR guidance.

What was verified on the branch (against a running Marinara dev server, local mlx-audio TTS with separate "naesala" and "narrator" voices, local Gemma 4 26B LLM, Roleplay mode with narratorVoiceEnabled + voiceMode single):

  • A reply mixing "Hello, traveler." style dialogue with action prose plays each in its own voice (narrator for the prose, character for the quoted spans) — confirmed both for on-demand speaker-icon playback and for streaming-TTS sentence-by-sentence playback.
  • A streaming chunk containing only action prose (no "...") plays in the narrator voice — does NOT fall back to the character voice as it used to.
  • A multi-sentence quoted block like "Approach me. I have a question." emits as a single character-voice chunk; the chunker waits for the closing quote.
  • Toggling narratorVoiceEnabled off reverts to pre-existing single-voice behavior (entire reply on the configured cfg.voice).

To verify in browser:

  • Configure two distinct voices in TTS settings (character voice + narrator voice), enable narratorVoiceEnabled, voiceMode = single.
  • Send a roleplay message that mixes quoted dialogue with action prose.
  • Both on-demand (click speaker icon) and streaming (autoplay-streaming on) should produce mixed-voice playback.
  • Disable narrator voice — should revert to single-voice playback of the whole reply.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

No UI changes — purely routing logic that respects the existing TTS settings.

🤖 Generated with Claude Code


🔄 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/1143 **Author:** [@etherious1804](https://github.com/etherious1804) **Created:** 5/24/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `feat/tts-narrator-auto-split` --- ### 📝 Commits (3) - [`0954666`](https://github.com/Pasta-Devs/Marinara-Engine/commit/09546664294536995d2917c56babf6bcb6f50370) fix(tts): apply playback rate client-side for local OAI-compatible servers - [`efdf859`](https://github.com/Pasta-Devs/Marinara-Engine/commit/efdf8598af03c5a7dbce351a5b49d2b2a899b89e) feat(tts): stream audio per sentence as the model generates - [`393ee8c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/393ee8c5f8971a9678222d3cbfe24a6d2a861104) feat(tts): auto-split quoted dialogue from prose narration ### 📊 Changes **8 files changed** (+814 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatArea.tsx` (+35 -2) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+52 -23) 📝 `packages/client/src/components/panels/settings/TTSConfigCard.tsx` (+13 -0) ➕ `packages/client/src/hooks/use-streaming-tts.ts` (+368 -0) ➕ `packages/client/src/lib/sentence-chunker.ts` (+246 -0) 📝 `packages/client/src/lib/tts-dialogue.ts` (+79 -2) 📝 `packages/client/src/lib/tts-service.ts` (+12 -1) 📝 `packages/shared/src/types/tts.ts` (+9 -0) </details> ### 📄 Description ## Linked issue Closes #1144 ## Why this change When `narratorVoiceEnabled` is configured with single-voice mode (no `<speaker>` tags from the model), the entire reply currently plays in the character's voice — even the action prose. The configured narrator voice is set but never selected. Users who set up a separate narrator (intending a novel-style narrator-reads-the-action, character-speaks-the-dialogue split) hear a single voice reading every word. Roleplay convention already disambiguates this without structured tags: `"..."` is speech, surrounding prose is narration. This PR acts on that convention. Applies to both on-demand playback (speaker icon) AND the streaming-TTS path (#1142). ## What changed **Client — quote-aware dialogue/narration splitter** - `packages/client/src/lib/tts-dialogue.ts`: new `splitQuotedDialogueAndNarration(text, fallbackSpeaker)` walks the text. Each quoted span (matched against the existing `DIALOGUE_QUOTE_PATTERN_SOURCE` — covers ASCII, smart double, guillemet, and Japanese corner/double-corner pairs) becomes a `{ speaker: fallbackSpeaker }` utterance; surrounding prose becomes `{ speaker: "Narrator" }`. The previous fallback that re-routed all-narrator output back to character voice has been removed — when narrator is enabled, narration-only chunks correctly stay on the narrator voice (matters for streaming where the first chunk may be action-only). - `buildTTSVoiceRequests` invokes the new splitter when `narratorVoiceEnabled && !dialogueOnly && !hasSpeakerTags && voiceMode === "single"`. Other paths (speaker-tagged output, dialogue-only, per-character voices) are untouched. **Client — quote-aware sentence chunker** - `packages/client/src/lib/sentence-chunker.ts`: new `isInsideUnclosedQuote(text, pos)` walks `[0..pos)` tracking the same five quote pairs the splitter recognizes. ASCII `"` is treated as a toggle (no separate close form); smart/guillemet/Japanese pairs use a paired stack. A sentence-end candidate that falls inside an open quote is skipped — so a multi-sentence dialogue block like `"Hello. How are you. I am fine."` emits as one chunk at the closing quote, not fragmented into pieces with unbalanced quotes the splitter can't classify. Without this chunker change, the streaming-TTS path (#1142) would fragment quoted dialogue mid-stream — each piece would have an unbalanced quote, fall through the splitter's pattern match, and route to all-narrator. The visible symptom would be "dialogue-heavy reply plays entirely in the narrator voice when streaming." The on-demand path doesn't hit this because it works on the full message text, not a growing buffer. ## Dependency Includes #1141 (client-side playback rate) and #1142 (streaming TTS) as base commits. Once those merge, this PR's diff will shrink to just the narrator-split changes. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes > Generated PR — unchecked boxes are left for the merger to confirm manually per the repo's AI-PR guidance. **What was verified on the branch (against a running Marinara dev server, local mlx-audio TTS with separate "naesala" and "narrator" voices, local Gemma 4 26B LLM, Roleplay mode with narratorVoiceEnabled + voiceMode single):** - A reply mixing `"Hello, traveler."` style dialogue with action prose plays each in its own voice (narrator for the prose, character for the quoted spans) — confirmed both for on-demand speaker-icon playback and for streaming-TTS sentence-by-sentence playback. - A streaming chunk containing only action prose (no `"..."`) plays in the narrator voice — does NOT fall back to the character voice as it used to. - A multi-sentence quoted block like `"Approach me. I have a question."` emits as a single character-voice chunk; the chunker waits for the closing quote. - Toggling `narratorVoiceEnabled` off reverts to pre-existing single-voice behavior (entire reply on the configured `cfg.voice`). **To verify in browser:** - Configure two distinct voices in TTS settings (character voice + narrator voice), enable `narratorVoiceEnabled`, voiceMode = single. - Send a roleplay message that mixes quoted dialogue with action prose. - Both on-demand (click speaker icon) and streaming (autoplay-streaming on) should produce mixed-voice playback. - Disable narrator voice — should revert to single-voice playback of the whole reply. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) No UI changes — purely routing logic that respects the existing TTS settings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:11:54 +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#4944
No description provided.