[PR #6745] [MERGED] feat(tts): support PCM output with browser-playable WAV wrapping #7309

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6745
Author: @SirAdoni
Created: 9/27/2026
Status: ✅ Merged
Merged: 9/28/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/issue-6709


📝 Commits (10+)

  • 5cdbcaf feat(tts): support browser-playable PCM responses (#6709)
  • 8814e2e chore: preserve unrelated changelog formatting
  • 47ad738 Merge remote-tracking branch 'origin/staging' into codex/merge-6745
  • 8ed6644 fix(tts): validate WAV chunks and verify PCM playback across browsers
  • 22f65ec Merge remote-tracking branch 'origin/staging' into codex/merge-6745
  • 81e5c88 Merge remote-tracking branch 'origin/staging' into codex/merge-6745
  • f55dacd fix(tts): reject zero-valued PCM WAV format fields
  • 296116d Merge remote-tracking branch 'origin/staging' into codex/merge-6745
  • 2d65cae fix(tts): validate PCM WAV frame layout
  • 37ea8d5 Merge remote-tracking branch 'origin/staging' into codex/merge-6745

📊 Changes

7 files changed (+537 additions, -4 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
➕ e2e/tts-pcm-settings.e2e.ts (+41 -0)
📝 packages/client/src/components/panels/settings/TTSConfigCard.tsx (+1 -0)
📝 packages/client/src/localization/locales/en.json (+1 -0)
📝 packages/server/src/routes/tts.routes.ts (+153 -3)
📝 packages/shared/src/types/tts.ts (+1 -1)
➕ scripts/regressions/tts-pcm.regression.ts (+338 -0)

📄 Description

Linked issue

Closes #6709

Why this change

Some OpenAI-compatible speech providers return raw PCM, which cannot be used directly by the existing browser audio playback. This adds PCM to the existing output-format setting and packages the returned samples as WAV for playback, without replacing the TTS provider or playback systems.

What changed

  • Add the PCM option to the shared TTS schema and existing settings selector; send response_format: pcm through the existing speech route.
  • Wrap signed 16-bit little-endian PCM in a WAV container without changing its samples. Use the provider's Content-Type rate and channels metadata. Only the official HTTPS OpenAI endpoint receives the documented 24 kHz mono fallback.
  • Reject missing/invalid/duplicate custom-provider layout metadata, empty PCM, and incomplete frames with a useful gateway error rather than guessing a layout and producing distorted audio.
  • Preserve MP3/WAV responses and avoid double-wrapping WAV returned under a PCM header. Reject truncated WAV containers on that path.
  • Add an English localized label, Unreleased changelog entry, and synthetic route/browser regression proof. No new dependency or data migration.

Validation

Final integration head: 820cb7896, based on staging 34834afa1 (including chat variables and phone navigation).

  • pnpm check passes after the final header/frame checks.
  • TTS_PCM_BROWSER_PROOF=1 node scripts/run-regressions.mjs --filter tts-pcm passes against the real speech route. Valid PCM output decodes in desktop Chromium, Android-sized Chromium and iPhone-sized WebKit, preserving samples, rate, channels and duration.
  • Malformed fixtures cover missing/truncated chunks, zero or inconsistent frame fields, invalid float headers and incomplete PCM frames. Valid padded metadata and complete float frames pass through unchanged. The malformed layout and incomplete-frame cases reproduced HTTP 200 before their fixes and now return 502.
  • On the combined staging base, all three speech-settings save/reload cases, all seven UI smoke cases and all four chat-variable regression files pass. The subsequent two-file change only tightens speech response validation; its route and three-decoder proof were rerun above.
  • Local CodeRabbit review findings about malformed audio were addressed. One buffer-view suggestion was rejected with code evidence: the wrapper allocates and returns the entire zero-offset Uint8Array, so its .buffer contains exactly the response bytes; the route regression also compares every byte. Final supplemental local review of both changed files completed with zero findings.
  • The hosted review's frame-alignment, incomplete-frame and IEEE-float findings are addressed. Hosted review completed on 820cb7896 with no new findings. All required checks and the complete Linux regression suite (421/421 files) passed before merge. Compressed formats retain codec-specific handling; WAVEFORMATEX permits zero sample width for some compressed formats.

Human verification checklist:

  • 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

Manually verify saved PCM selection after reload and speech playback with the intended provider. Confirm MP3/WAV still work, custom PCM providers supply layout metadata, and missing metadata yields an actionable error. Check both themes and mobile. No human verification is claimed.

Docs and release impact

Unreleased changelog updated. No version bump or changes under docs/.

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs updated or follow-up issue opened, if applicable
  • Version/release files updated, if applicable

UI evidence (if applicable)

Before/after screenshots in dark and light themes, desktop Chromium and iPhone-sized WebKit. Download the self-contained HTML gallery from the gist to view its embedded original PNG captures. All screenshots use disposable synthetic data; browser emulation is not a physical-device test.

Summary by CodeRabbit

  • New Features
    • Added PCM as an audio format for text-to-speech settings. PCM audio is converted to WAV for playback without changing its samples, and the selection remains saved after reloading.
  • Bug Fixes
    • Invalid PCM metadata, empty audio, and incomplete sample frames are rejected. Custom providers must supply valid sample-rate and channel information; supported OpenAI-compatible requests can use defaults. Malformed WAV responses and other invalid audio responses are also rejected.

🔄 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/6745 **Author:** [@SirAdoni](https://github.com/SirAdoni) **Created:** 9/27/2026 **Status:** ✅ Merged **Merged:** 9/28/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/issue-6709` --- ### 📝 Commits (10+) - [`5cdbcaf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5cdbcaf731506a0b39b9edc26e7803969882c3d9) feat(tts): support browser-playable PCM responses (#6709) - [`8814e2e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8814e2e4952a45809614e88adb08efbed6310975) chore: preserve unrelated changelog formatting - [`47ad738`](https://github.com/Pasta-Devs/Marinara-Engine/commit/47ad7387bdc05ad0d320c9760c66ca4b002d1927) Merge remote-tracking branch 'origin/staging' into codex/merge-6745 - [`8ed6644`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8ed66447305e6be7445412cca5791221bd2e4880) fix(tts): validate WAV chunks and verify PCM playback across browsers - [`22f65ec`](https://github.com/Pasta-Devs/Marinara-Engine/commit/22f65ec06275eb50e3ef5a727630c17195be742a) Merge remote-tracking branch 'origin/staging' into codex/merge-6745 - [`81e5c88`](https://github.com/Pasta-Devs/Marinara-Engine/commit/81e5c882c73382d2b36843cb9b18fdec76694cb5) Merge remote-tracking branch 'origin/staging' into codex/merge-6745 - [`f55dacd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f55dacd682a3971cd82df55495b61007c7f736fd) fix(tts): reject zero-valued PCM WAV format fields - [`296116d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/296116da52c8993dc4ed0a910803383d0d5f52ec) Merge remote-tracking branch 'origin/staging' into codex/merge-6745 - [`2d65cae`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2d65caeea1acc1602f1e909323bdca4927494d02) fix(tts): validate PCM WAV frame layout - [`37ea8d5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/37ea8d5475308f5e9f61d4ea91f9145eaf504553) Merge remote-tracking branch 'origin/staging' into codex/merge-6745 ### 📊 Changes **7 files changed** (+537 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) ➕ `e2e/tts-pcm-settings.e2e.ts` (+41 -0) 📝 `packages/client/src/components/panels/settings/TTSConfigCard.tsx` (+1 -0) 📝 `packages/client/src/localization/locales/en.json` (+1 -0) 📝 `packages/server/src/routes/tts.routes.ts` (+153 -3) 📝 `packages/shared/src/types/tts.ts` (+1 -1) ➕ `scripts/regressions/tts-pcm.regression.ts` (+338 -0) </details> ### 📄 Description ## Linked issue Closes #6709 ## Why this change Some OpenAI-compatible speech providers return raw PCM, which cannot be used directly by the existing browser audio playback. This adds PCM to the existing output-format setting and packages the returned samples as WAV for playback, without replacing the TTS provider or playback systems. ## What changed - Add the PCM option to the shared TTS schema and existing settings selector; send `response_format: pcm` through the existing speech route. - Wrap signed 16-bit little-endian PCM in a WAV container without changing its samples. Use the provider's Content-Type `rate` and `channels` metadata. Only the official HTTPS OpenAI endpoint receives the documented 24 kHz mono fallback. - Reject missing/invalid/duplicate custom-provider layout metadata, empty PCM, and incomplete frames with a useful gateway error rather than guessing a layout and producing distorted audio. - Preserve MP3/WAV responses and avoid double-wrapping WAV returned under a PCM header. Reject truncated WAV containers on that path. - Add an English localized label, Unreleased changelog entry, and synthetic route/browser regression proof. No new dependency or data migration. ## Validation Final integration head: `820cb7896`, based on staging `34834afa1` (including chat variables and phone navigation). - `pnpm check` passes after the final header/frame checks. - `TTS_PCM_BROWSER_PROOF=1 node scripts/run-regressions.mjs --filter tts-pcm` passes against the real speech route. Valid PCM output decodes in desktop Chromium, Android-sized Chromium and iPhone-sized WebKit, preserving samples, rate, channels and duration. - Malformed fixtures cover missing/truncated chunks, zero or inconsistent frame fields, invalid float headers and incomplete PCM frames. Valid padded metadata and complete float frames pass through unchanged. The malformed layout and incomplete-frame cases reproduced HTTP 200 before their fixes and now return 502. - On the combined staging base, all three speech-settings save/reload cases, all seven UI smoke cases and all four chat-variable regression files pass. The subsequent two-file change only tightens speech response validation; its route and three-decoder proof were rerun above. - Local CodeRabbit review findings about malformed audio were addressed. One buffer-view suggestion was rejected with code evidence: the wrapper allocates and returns the entire zero-offset `Uint8Array`, so its `.buffer` contains exactly the response bytes; the route regression also compares every byte. Final supplemental local review of both changed files completed with zero findings. - The hosted review's frame-alignment, incomplete-frame and IEEE-float findings are addressed. Hosted review completed on `820cb7896` with no new findings. All required checks and the complete Linux regression suite (421/421 files) passed before merge. Compressed formats retain codec-specific handling; [WAVEFORMATEX permits zero sample width for some compressed formats](https://learn.microsoft.com/en-us/windows/win32/api/mmeapi/ns-mmeapi-waveformatex). Human verification checklist: - [ ] `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) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Manually verify saved PCM selection after reload and speech playback with the intended provider. Confirm MP3/WAV still work, custom PCM providers supply layout metadata, and missing metadata yields an actionable error. Check both themes and mobile. No human verification is claimed. ## Docs and release impact Unreleased changelog updated. No version bump or changes under `docs/`. - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs updated or follow-up issue opened, if applicable - [ ] Version/release files updated, if applicable ## UI evidence (if applicable) [Before/after screenshots in dark and light themes, desktop Chromium and iPhone-sized WebKit](https://gist.github.com/SpicyMarinara/c5d46329abce510507ea1ca78e70b3bd). Download the self-contained HTML gallery from the gist to view its embedded original PNG captures. All screenshots use disposable synthetic data; browser emulation is not a physical-device test. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added PCM as an audio format for text-to-speech settings. PCM audio is converted to WAV for playback without changing its samples, and the selection remains saved after reloading. * **Bug Fixes** * Invalid PCM metadata, empty audio, and incomplete sample frames are rejected. Custom providers must supply valid sample-rate and channel information; supported OpenAI-compatible requests can use defaults. Malformed WAV responses and other invalid audio responses are also rejected. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:18: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#7309
No description provided.