[PR #7547] [MERGED] feat(avatars): lip sync with text-to-speech #7787

Closed
opened 2026-10-24 04:07:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7547
Author: @SpicyMarinara
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/avatars-tts-lipsync


📝 Commits (5)

  • 15af58f feat(avatars): shared contract for the 2D and 3D avatar agents
  • df53866 fix(avatars): refuse Windows device names in stored paths and point code at the developer notes
  • 1aff83b feat(avatars): move the speaking character's mouth with text-to-speech
  • dbf22c4 fix(avatars): keep the mouth shape while the mouth closes after a sound
  • b6e6c18 fix(avatars): keep a text-to-speech reading with the chat it was requested in

📊 Changes

44 files changed (+2599 additions, -6 deletions)

View changed files

📝 docs/agents/agents-overview.md (+1 -0)
➕ docs/agents/avatars.md (+52 -0)
📝 docs/development/optional-agent-packages.md (+19 -0)
📝 packages/client/package.json (+5 -0)
📝 packages/client/src/components/chat/ChatArea.tsx (+1 -0)
📝 packages/client/src/components/chat/ChatMessage.tsx (+1 -0)
➕ packages/client/src/features/avatars/audio/avatar-audio.ts (+105 -0)
➕ packages/client/src/features/avatars/audio/voice-envelope.ts (+144 -0)
➕ packages/client/src/features/avatars/contract.ts (+198 -0)
➕ packages/client/src/features/avatars/director/avatar-director.ts (+24 -0)
➕ packages/client/src/features/avatars/generation/AvatarGenerationPanel.tsx (+8 -0)
➕ packages/client/src/features/avatars/renderers/mesh-avatar/MeshAvatarSetupPanel.tsx (+7 -0)
➕ packages/client/src/features/avatars/renderers/mesh-avatar/mesh-avatar-renderer.ts (+20 -0)
➕ packages/client/src/features/avatars/renderers/pngtuber/PngtuberSetupPanel.tsx (+7 -0)
➕ packages/client/src/features/avatars/renderers/pngtuber/pngtuber-renderer.ts (+19 -0)
➕ packages/client/src/features/avatars/renderers/vrm/VrmSetupPanel.tsx (+7 -0)
➕ packages/client/src/features/avatars/renderers/vrm/vrm-renderer.ts (+20 -0)
➕ packages/client/src/features/avatars/setup/AvatarAgentSetup.tsx (+13 -0)
➕ packages/client/src/features/avatars/stage/AvatarStage.tsx (+15 -0)
📝 packages/client/src/lib/tts-dialogue.ts (+3 -0)

...and 24 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Refs #7537 (epic: 2D and 3D avatar agents), lane TTS lip sync.

Depends on https://github.com/Pasta-Devs/Marinara-Engine/pull/7539, the shared avatar contract (opened ready against staging, Refs #7537, not merged yet). Its commits show in this diff until it merges; this lane's changes are the last three commits only (1aff83b61, dbf22c4af, b6e6c18b7).

Why this change

  • Mari decided that avatar mouths follow the TTS audio when text to speech plays, and the visible text while a reply streams. The director (another lane) needs two things from TTS: how loud the voice is right now, and whose voice it is.
  • TTS playback in Safari and on iOS was hard to get right (#5889: autoplay blocks, gesture retries, one primed audio element reused for every clip). Lip sync must not put any of that at risk.

What changed

  • When text to speech reads a Roleplay reply, the avatar audio module now reports the speaking character's voice level, so their avatar's mouth can follow it. Nothing is visible from this PR alone: the director lane subscribes to this feed, and the base lane draws the avatars.
  • features/avatars/audio/avatar-audio.ts (fills the contract stub subscribeAvatarAudio): while TTS plays a line, it publishes an AvatarAudioLevelSource for that line's character, and null when the voice pauses, stops, moves to narration or another speaker, or the chat changes. A reading belongs to the chat it was requested in, which the Roleplay callers pass with the request. Only that chat's avatars follow the voice: switching to another chat (even while the voice is still loading) stops the mouth there, and coming back while it still plays picks it up again. A reading with no chat, like the voice preview in settings, moves no mouth. It watches the TTS service only while the director is subscribed.
  • features/avatars/audio/voice-envelope.ts: each clip is decoded a second time, on the side, by one OfflineAudioContext that is created once and kept. The decode turns the clip into a 20 ms loudness track. That track is noise-gated, normalised to the clip's loud parts and smoothed: the mouth opens fast and closes a little slower. level() reads the track at the playback element's currentTime. viseme() gives a coarse shape from how bright the sound is: ou for dark sounds, aa for open ones, ih for s/sh. While the mouth closes after a sound, it keeps that sound's shape. Each clip's track is cached by its Blob, so a replay does not decode again. A clip the browser cannot decode gives no level, and the voice still plays.
  • lib/tts-service.ts (minimal): a read-only getPlayback() that returns the element, the Blob, the reading's chat and the line's character. speak() and speakSequence() accept an optional chatId, and requests an optional characterId. Neither is sent to the provider or used in cache keys. No playback, gesture or autoplay code changed.
  • components/chat/ChatArea.tsx (auto-play) and components/chat/ChatMessage.tsx (Speak): each passes the chat it already knows (targetChatId, message.chatId) as chatId. One line each.
  • lib/tts-dialogue.ts and lib/tts-roleplay-speaker-extractor.ts: each voice request now carries the characterId that the existing voice lookup already resolved, so the mouth that moves belongs to the character whose voice speaks. Cache keys do not include it, so cached clips still replay.
  • docs/agents/avatars.md: filled the "Lip sync with text-to-speech" section.
  • Regression scripts/regressions/avatar-tts-lipsync.regression.ts. It checks the loudness track (silence, gating, attack and release, quieter parts, mouth shapes) and the request builders. It also drives the real ttsService with a stubbed audio element, fetch and Web Audio through a three-speaker reading, pause and resume, a chat switch, restart, stop, an undecodable clip and unsubscribing, and asserts that no realtime AudioContext is ever created. It covers a chat switch while the voice is still loading, a stage that mounts in another chat while a voice plays, and a reading with no chat.

Decisions and deviations

  • No AnalyserNode on the playback element (the lane brief asked for createMediaElementSource + AnalyserNode). createMediaElementSource reroutes that element's sound through the AudioContext for good, and TTS reuses one element for every clip. On iOS a context goes suspended/interrupted after backgrounding, a call or Siri. From then on every autoplayed voice would play silently until a later tap resumed the context, while the app still showed "playing". Web Audio output also follows iOS's ring/silent switch, which a plain <audio> element does not. A decoded loudness track gives the same level and needs no gesture. It keeps the element out of Web Audio entirely, so the Safari/iOS code needs no change. The trade-off is one extra decode per clip, a few milliseconds, and only while an avatar stage is listening.
  • Four files outside the lane's list, all on the TTS request path and owned by no other lane: tts-dialogue.ts and tts-roleplay-speaker-extractor.ts (each got one optional field and one line), and the two Roleplay speak calls in ChatArea.tsx and ChatMessage.tsx (one chatId option line each). Matching speaker names inside the audio module would have needed the chat's participants, and the audio API in the contract cannot receive them. Guessing the reading's chat from whichever chat is open when the clip starts playing gave the wrong chat when the user switched chats while a voice loaded, so the callers now say which chat it is. No contract file was changed.
  • Not covered here:
    • Game Mode voices play through Game narration's own audio elements (GameNarration.tsx), not the shared TTS player, so Game avatars follow the text. Hooking that up means editing the Game line display code, which belongs to the director lane; it can feed AvatarAudioLevelSources itself, or a follow-up can.
    • Personas: user messages have no Speak button, and the voice lookup resolves only chat characters, so a persona's mouth follows the text.

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

Commands run by the agent (results as reported; the boxes above are for the human reviewer):

  • pnpm install --frozen-lockfile --prefer-offline --store-dir <main checkout>/.pnpm-store and pnpm build:shared: ok.
  • pnpm check on b6e6c18b7 (current head): passed (impeccable, localization with no new keys, Prettier, ESLint, e2e and token-estimation types, full build).
  • Regressions via node scripts/run-regressions.mjs --filter <name>: tts (7 files: avatar-tts-lipsync, roleplay-vn-tts, tts-cache-clear, tts-pcm, tts-safari-play-guard, tts-source-persistence, tts-voice-assignment-route), avatar (6 files, including avatar-contract), roleplay-vn (2 files), agent-activation (2), spatial-context, open-issues: all passed.
  • Negative control: making the module ignore the chat switch fails avatar-tts-lipsync at "switching chats withdraws the voice" (reverted).
  • Bundle: no client chunk contains the audio module yet, because nothing imports it until the director lane subscribes, so the main bundle is unchanged. tts-service stays in its existing chunk.
  • Local CodeRabbit (coderabbit review --agent --committed --base-commit df538660f, Pasta-Devs org, this lane's commit only): 1 minor finding, left as it is. It asked to update the translated docs or link a [docs-i18n] follow-up for docs/agents/avatars.md. That follow-up is #7540, linked under "Docs and release impact".
  • Own review after the first push found one defect, fixed in dbf22c4af. When a sound ended, the mouth shape dropped to "rest" while the mouth was still half open, so a renderer could snap it. The shape now holds until the mouth is shut, and the regression checks it.
  • Review round on dbf22c4af, fixed in b6e6c18b7:
    • Fixed (major): a reading went to the wrong chat. The module tied a reading to whichever chat was open when its audio first played, or when the first stage subscribed. So switching chats while the voice was still loading (auto-play or Speak, with progressive playback off by default), or opening another chat with the same character while a voice played, made that chat's avatar lip-sync the other chat's voice, and left the reading chat's avatar still. Now the two Roleplay callers pass the chat they already know as chatId, TTSPlayback carries it in place of the sequence number that only served the guess, and a reading with no chat moves no avatar.
    • Proof: the extended avatar-tts-lipsync regression passes. Against the old code it fails at "chat B's avatars stay still for chat A's voice" (switching while loading). A scratch copy without that block, kept outside the repo, fails at "a stage mounted in another chat does not take chat A's voice" (late stage). The fix was restored and the tree is clean.
    • Fixed (docs nit): the guide said narration never moves a mouth. With Only read dialogues off, a character's own narration is read in their voice, so their mouth moves for it too. The guide now says so.
  • Regressions on b6e6c18b7 via node scripts/run-regressions.mjs --filter <name>: tts 7/7, avatar 6/6, roleplay-vn 2/2, agent-activation 2/2, spatial-context 1/1, open-issues 1/1, roleplay-streaming, character-identity, chat-message-css-security and frozen-server-client-timeouts 1/1 each: all passed.
  • Local CodeRabbit on b6e6c18b7 (coderabbit review --agent --committed --base-commit d115a4406, after two rate-limit waits): 2 minor findings, both outside this lane's files, not changed here:
    • docs/agents/avatars.md outline placeholders and "staging" in the intro. These are the contract's outline and other lanes' sections; the guide is filled lane by lane, as answered on the GitHub thread below.
    • AVATAR_OWNER_ID_PATTERN accepts Windows device names (nul, con). It is in a frozen contract file. Real owner ids come from nanoid(), 21 characters, so they can never be a device name, and avatar storage on this branch is still a stub that throws. Raised as a follow-up for the contract or base lane rather than patched here.
  • GitHub CodeRabbit on 1aff83b61: 1 thread, answered and resolved without a change. It asked to call lip sync "forthcoming" in the guide. The guide's intro already says the feature is still being built and fills in as parts land. Each lane writes its section for the finished behaviour, and no avatar package is in the catalog yet.

Manual verification notes

Nothing about avatars is visible until the director and base lanes land. Until then, these checks confirm that TTS still plays exactly as before:

  • Desktop Chrome, Firefox and Safari: turn on TTS and Roleplay messages auto-play, send a message, and confirm the reply is read aloud. Press Speak on an older message, then try Pause speaking, Resume speaking, Restart speaking and stop. Change Line volume while it plays.
  • Desktop Safari: with auto-play on, send a message, then switch to another tab before the reply finishes. Come back. If Safari blocks the voice, the "tap to play" toast appears and one tap plays it.
  • iOS Safari (and the installed PWA): with the ring/silent switch on silent, press Speak on a message and confirm the voice is audible as before. Send a message with auto-play on and confirm the reply is read, or asks for one tap. Lock the phone during playback, unlock it, and start another reply.
  • Android Chrome and the Android app WebView: auto-play a reply and press Speak on a message. The voice plays as before.
  • Optional, with the dev server (pnpm dev:client) on desktop Chrome: in DevTools run const a = await import("/src/features/avatars/audio/avatar-audio.ts"); a.subscribeAvatarAudio((id, s) => { console.log(id, s); if (s) { const t = setInterval(() => s.isPlaying() ? console.log(s.level().toFixed(2), s.viseme?.()) : clearInterval(t), 100); } });. Then press Speak on a character's message. The character's id is logged, then levels that rise and fall with the voice. Narration logs null.

After the director and base lanes land (Mari's staging test list):

  • Desktop Chrome, Firefox and Safari: in a Roleplay chat with 2D or 3D Avatars on, press Speak on a reply with two speakers. Each character's mouth moves only during their own lines, closes in pauses, and stays still during lines read in the narrator's voice. Pause, then resume. Switch to another chat mid-reading, then come back. Then press Speak again and, before the voice starts, open another chat that has the same character: that chat's avatar stays still, and the first chat's avatar moves when you go back.
  • iOS Safari and Android Chrome/WebView: the same, plus confirm the voice stays audible and the mouth keeps moving after locking and unlocking the phone mid-reply.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Docs: docs/agents/avatars.md ("Lip sync with text-to-speech"). Translation follow-up already exists: #7540 covers docs/agents/avatars.md once the lanes have filled it.

UI evidence (if applicable)

No UI in this lane.


🔄 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/7547 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/avatars-tts-lipsync` --- ### 📝 Commits (5) - [`15af58f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/15af58f103a860121319c6010dd0d0be38a5ffe2) feat(avatars): shared contract for the 2D and 3D avatar agents - [`df53866`](https://github.com/Pasta-Devs/Marinara-Engine/commit/df538660f776c785451e6cfd981eda93dba7939f) fix(avatars): refuse Windows device names in stored paths and point code at the developer notes - [`1aff83b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1aff83b6184bf7a9ab02e716a5223924fa5bb559) feat(avatars): move the speaking character's mouth with text-to-speech - [`dbf22c4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dbf22c4af42746132dd129de9f466f180042cbbe) fix(avatars): keep the mouth shape while the mouth closes after a sound - [`b6e6c18`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b6e6c18b7271d21b252307574c56647abeb4ae6d) fix(avatars): keep a text-to-speech reading with the chat it was requested in ### 📊 Changes **44 files changed** (+2599 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `docs/agents/agents-overview.md` (+1 -0) ➕ `docs/agents/avatars.md` (+52 -0) 📝 `docs/development/optional-agent-packages.md` (+19 -0) 📝 `packages/client/package.json` (+5 -0) 📝 `packages/client/src/components/chat/ChatArea.tsx` (+1 -0) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+1 -0) ➕ `packages/client/src/features/avatars/audio/avatar-audio.ts` (+105 -0) ➕ `packages/client/src/features/avatars/audio/voice-envelope.ts` (+144 -0) ➕ `packages/client/src/features/avatars/contract.ts` (+198 -0) ➕ `packages/client/src/features/avatars/director/avatar-director.ts` (+24 -0) ➕ `packages/client/src/features/avatars/generation/AvatarGenerationPanel.tsx` (+8 -0) ➕ `packages/client/src/features/avatars/renderers/mesh-avatar/MeshAvatarSetupPanel.tsx` (+7 -0) ➕ `packages/client/src/features/avatars/renderers/mesh-avatar/mesh-avatar-renderer.ts` (+20 -0) ➕ `packages/client/src/features/avatars/renderers/pngtuber/PngtuberSetupPanel.tsx` (+7 -0) ➕ `packages/client/src/features/avatars/renderers/pngtuber/pngtuber-renderer.ts` (+19 -0) ➕ `packages/client/src/features/avatars/renderers/vrm/VrmSetupPanel.tsx` (+7 -0) ➕ `packages/client/src/features/avatars/renderers/vrm/vrm-renderer.ts` (+20 -0) ➕ `packages/client/src/features/avatars/setup/AvatarAgentSetup.tsx` (+13 -0) ➕ `packages/client/src/features/avatars/stage/AvatarStage.tsx` (+15 -0) 📝 `packages/client/src/lib/tts-dialogue.ts` (+3 -0) _...and 24 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Refs #7537 (epic: 2D and 3D avatar agents), lane **TTS lip sync**. Depends on https://github.com/Pasta-Devs/Marinara-Engine/pull/7539, the shared avatar contract (opened ready against `staging`, Refs #7537, not merged yet). Its commits show in this diff until it merges; this lane's changes are the last three commits only (1aff83b61, dbf22c4af, b6e6c18b7). ## Why this change - Mari decided that avatar mouths follow the TTS audio when text to speech plays, and the visible text while a reply streams. The director (another lane) needs two things from TTS: how loud the voice is right now, and whose voice it is. - TTS playback in Safari and on iOS was hard to get right (#5889: autoplay blocks, gesture retries, one primed audio element reused for every clip). Lip sync must not put any of that at risk. ## What changed - When text to speech reads a Roleplay reply, the avatar audio module now reports the speaking character's voice level, so their avatar's mouth can follow it. Nothing is visible from this PR alone: the director lane subscribes to this feed, and the base lane draws the avatars. - `features/avatars/audio/avatar-audio.ts` (fills the contract stub `subscribeAvatarAudio`): while TTS plays a line, it publishes an `AvatarAudioLevelSource` for that line's character, and `null` when the voice pauses, stops, moves to narration or another speaker, or the chat changes. A reading belongs to the chat it was requested in, which the Roleplay callers pass with the request. Only that chat's avatars follow the voice: switching to another chat (even while the voice is still loading) stops the mouth there, and coming back while it still plays picks it up again. A reading with no chat, like the voice preview in settings, moves no mouth. It watches the TTS service only while the director is subscribed. - `features/avatars/audio/voice-envelope.ts`: each clip is decoded a second time, on the side, by one `OfflineAudioContext` that is created once and kept. The decode turns the clip into a 20 ms loudness track. That track is noise-gated, normalised to the clip's loud parts and smoothed: the mouth opens fast and closes a little slower. `level()` reads the track at the playback element's `currentTime`. `viseme()` gives a coarse shape from how bright the sound is: `ou` for dark sounds, `aa` for open ones, `ih` for `s`/`sh`. While the mouth closes after a sound, it keeps that sound's shape. Each clip's track is cached by its Blob, so a replay does not decode again. A clip the browser cannot decode gives no level, and the voice still plays. - `lib/tts-service.ts` (minimal): a read-only `getPlayback()` that returns the element, the Blob, the reading's chat and the line's character. `speak()` and `speakSequence()` accept an optional `chatId`, and requests an optional `characterId`. Neither is sent to the provider or used in cache keys. No playback, gesture or autoplay code changed. - `components/chat/ChatArea.tsx` (auto-play) and `components/chat/ChatMessage.tsx` (**Speak**): each passes the chat it already knows (`targetChatId`, `message.chatId`) as `chatId`. One line each. - `lib/tts-dialogue.ts` and `lib/tts-roleplay-speaker-extractor.ts`: each voice request now carries the `characterId` that the existing voice lookup already resolved, so the mouth that moves belongs to the character whose voice speaks. Cache keys do not include it, so cached clips still replay. - `docs/agents/avatars.md`: filled the "Lip sync with text-to-speech" section. - Regression `scripts/regressions/avatar-tts-lipsync.regression.ts`. It checks the loudness track (silence, gating, attack and release, quieter parts, mouth shapes) and the request builders. It also drives the real `ttsService` with a stubbed audio element, fetch and Web Audio through a three-speaker reading, pause and resume, a chat switch, restart, stop, an undecodable clip and unsubscribing, and asserts that no realtime `AudioContext` is ever created. It covers a chat switch while the voice is still loading, a stage that mounts in another chat while a voice plays, and a reading with no chat. ### Decisions and deviations - **No `AnalyserNode` on the playback element** (the lane brief asked for `createMediaElementSource` + `AnalyserNode`). `createMediaElementSource` reroutes that element's sound through the AudioContext for good, and TTS reuses one element for every clip. On iOS a context goes `suspended`/`interrupted` after backgrounding, a call or Siri. From then on every autoplayed voice would play silently until a later tap resumed the context, while the app still showed "playing". Web Audio output also follows iOS's ring/silent switch, which a plain `<audio>` element does not. A decoded loudness track gives the same level and needs no gesture. It keeps the element out of Web Audio entirely, so the Safari/iOS code needs no change. The trade-off is one extra decode per clip, a few milliseconds, and only while an avatar stage is listening. - **Four files outside the lane's list**, all on the TTS request path and owned by no other lane: `tts-dialogue.ts` and `tts-roleplay-speaker-extractor.ts` (each got one optional field and one line), and the two Roleplay speak calls in `ChatArea.tsx` and `ChatMessage.tsx` (one `chatId` option line each). Matching speaker names inside the audio module would have needed the chat's participants, and the audio API in the contract cannot receive them. Guessing the reading's chat from whichever chat is open when the clip starts playing gave the wrong chat when the user switched chats while a voice loaded, so the callers now say which chat it is. No contract file was changed. - **Not covered here:** - Game Mode voices play through Game narration's own audio elements (`GameNarration.tsx`), not the shared TTS player, so Game avatars follow the text. Hooking that up means editing the Game line display code, which belongs to the director lane; it can feed `AvatarAudioLevelSource`s itself, or a follow-up can. - Personas: user messages have no **Speak** button, and the voice lookup resolves only chat characters, so a persona's mouth follows the text. ## 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` Commands run by the agent (results as reported; the boxes above are for the human reviewer): - `pnpm install --frozen-lockfile --prefer-offline --store-dir <main checkout>/.pnpm-store` and `pnpm build:shared`: ok. - `pnpm check` on b6e6c18b7 (current head): passed (impeccable, localization with no new keys, Prettier, ESLint, e2e and token-estimation types, full build). - Regressions via `node scripts/run-regressions.mjs --filter <name>`: `tts` (7 files: `avatar-tts-lipsync`, `roleplay-vn-tts`, `tts-cache-clear`, `tts-pcm`, `tts-safari-play-guard`, `tts-source-persistence`, `tts-voice-assignment-route`), `avatar` (6 files, including `avatar-contract`), `roleplay-vn` (2 files), `agent-activation` (2), `spatial-context`, `open-issues`: all passed. - Negative control: making the module ignore the chat switch fails `avatar-tts-lipsync` at "switching chats withdraws the voice" (reverted). - Bundle: no client chunk contains the audio module yet, because nothing imports it until the director lane subscribes, so the main bundle is unchanged. `tts-service` stays in its existing chunk. - Local CodeRabbit (`coderabbit review --agent --committed --base-commit df538660f`, Pasta-Devs org, this lane's commit only): 1 minor finding, left as it is. It asked to update the translated docs or link a `[docs-i18n]` follow-up for `docs/agents/avatars.md`. That follow-up is #7540, linked under "Docs and release impact". - Own review after the first push found one defect, fixed in dbf22c4af. When a sound ended, the mouth shape dropped to "rest" while the mouth was still half open, so a renderer could snap it. The shape now holds until the mouth is shut, and the regression checks it. - Review round on dbf22c4af, fixed in b6e6c18b7: - **Fixed (major): a reading went to the wrong chat.** The module tied a reading to whichever chat was open when its audio first played, or when the first stage subscribed. So switching chats while the voice was still loading (auto-play or **Speak**, with progressive playback off by default), or opening another chat with the same character while a voice played, made that chat's avatar lip-sync the other chat's voice, and left the reading chat's avatar still. Now the two Roleplay callers pass the chat they already know as `chatId`, `TTSPlayback` carries it in place of the sequence number that only served the guess, and a reading with no chat moves no avatar. - Proof: the extended `avatar-tts-lipsync` regression passes. Against the old code it fails at "chat B's avatars stay still for chat A's voice" (switching while loading). A scratch copy without that block, kept outside the repo, fails at "a stage mounted in another chat does not take chat A's voice" (late stage). The fix was restored and the tree is clean. - **Fixed (docs nit):** the guide said narration never moves a mouth. With **Only read dialogues** off, a character's own narration is read in their voice, so their mouth moves for it too. The guide now says so. - Regressions on b6e6c18b7 via `node scripts/run-regressions.mjs --filter <name>`: `tts` 7/7, `avatar` 6/6, `roleplay-vn` 2/2, `agent-activation` 2/2, `spatial-context` 1/1, `open-issues` 1/1, `roleplay-streaming`, `character-identity`, `chat-message-css-security` and `frozen-server-client-timeouts` 1/1 each: all passed. - Local CodeRabbit on b6e6c18b7 (`coderabbit review --agent --committed --base-commit d115a4406`, after two rate-limit waits): 2 minor findings, both outside this lane's files, not changed here: - `docs/agents/avatars.md` outline placeholders and "`staging`" in the intro. These are the contract's outline and other lanes' sections; the guide is filled lane by lane, as answered on the GitHub thread below. - `AVATAR_OWNER_ID_PATTERN` accepts Windows device names (`nul`, `con`). It is in a frozen contract file. Real owner ids come from `nanoid()`, 21 characters, so they can never be a device name, and avatar storage on this branch is still a stub that throws. Raised as a follow-up for the contract or base lane rather than patched here. - GitHub CodeRabbit on 1aff83b61: 1 thread, answered and resolved without a change. It asked to call lip sync "forthcoming" in the guide. The guide's intro already says the feature is still being built and fills in as parts land. Each lane writes its section for the finished behaviour, and no avatar package is in the catalog yet. ### Manual verification notes Nothing about avatars is visible until the director and base lanes land. Until then, these checks confirm that TTS still plays exactly as before: - Desktop Chrome, Firefox and Safari: turn on TTS and **Roleplay messages** auto-play, send a message, and confirm the reply is read aloud. Press **Speak** on an older message, then try **Pause speaking**, **Resume speaking**, **Restart speaking** and stop. Change **Line volume** while it plays. - Desktop Safari: with auto-play on, send a message, then switch to another tab before the reply finishes. Come back. If Safari blocks the voice, the "tap to play" toast appears and one tap plays it. - iOS Safari (and the installed PWA): with the ring/silent switch on silent, press **Speak** on a message and confirm the voice is audible as before. Send a message with auto-play on and confirm the reply is read, or asks for one tap. Lock the phone during playback, unlock it, and start another reply. - Android Chrome and the Android app WebView: auto-play a reply and press **Speak** on a message. The voice plays as before. - Optional, with the dev server (`pnpm dev:client`) on desktop Chrome: in DevTools run `const a = await import("/src/features/avatars/audio/avatar-audio.ts"); a.subscribeAvatarAudio((id, s) => { console.log(id, s); if (s) { const t = setInterval(() => s.isPlaying() ? console.log(s.level().toFixed(2), s.viseme?.()) : clearInterval(t), 100); } });`. Then press **Speak** on a character's message. The character's id is logged, then levels that rise and fall with the voice. Narration logs `null`. After the director and base lanes land (Mari's staging test list): - Desktop Chrome, Firefox and Safari: in a Roleplay chat with 2D or 3D Avatars on, press **Speak** on a reply with two speakers. Each character's mouth moves only during their own lines, closes in pauses, and stays still during lines read in the narrator's voice. Pause, then resume. Switch to another chat mid-reading, then come back. Then press **Speak** again and, before the voice starts, open another chat that has the same character: that chat's avatar stays still, and the first chat's avatar moves when you go back. - iOS Safari and Android Chrome/WebView: the same, plus confirm the voice stays audible and the mouth keeps moving after locking and unlocking the phone mid-reply. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Docs: `docs/agents/avatars.md` ("Lip sync with text-to-speech"). Translation follow-up already exists: #7540 covers `docs/agents/avatars.md` once the lanes have filled it. ## UI evidence (if applicable) No UI in this lane. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:30 +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#7787
No description provided.