HLE: speak the title's narration with the host's default voice #2760

Closed
github-bot wants to merge 1 commit from gh-pr/2760/head into gh-pr/2760/base
Owner

@⁠kilolimaVI on GitHub · 2026-11-25 19:52 UTC · original
kilolimaVI:hle/speech-synthesis → main · +192 −53 · 3 files · 1 commits · closed without merging

Narration ("Screen Narration" in the title's accessibility settings) was silent: every speech stream was an empty WAVE file. Text (slot 0x68) and SSML (slot 0xa8) are now spoken by the host's default voice through WinRT SpeechSynthesizer, and the title reads back the WAVE file it makes. Where the host has no working voice, the stream is the previous silence, so nothing gets worse.

What is in it

  • crates/victory-hle/src/modules/speech.rs: synthesis, per-stream handles that own their audio (freed on close, slot 0x70), tests
  • crates/victory-hle/Cargo.toml: Media_Core, Media_SpeechSynthesis, Storage_Streams features of windows
  • README.md: the runtime services row

Tested

  • ASUS Vivobook S16, Ryzen 7 8845HS, Radeon 780M, Windows 11 26300, debug build
  • cargo test -p victory-hle --lib speech: 3 passed; the_host_voice_speaks_text_and_ssml synthesized real audio for both text and SSML (not skipped)
  • cargo test --workspace: 781 passed, 0 failed, 9 ignored
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean

Not tested

  • In the title itself: I don't have the game files. The WAVE format the host makes (rate, channels) may differ from what the console returned; if the title expects a fixed format, it may need converting.
  • Voice listing (slot 0x40) and custom voices remain unimplemented; the default voice is always used.

AI use
Code, tests and description written with Claude (Claude Opus 5.5); I built and ran the tests on the hardware above.

**@⁠kilolimaVI** on GitHub · 2026-11-25 19:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2760) `kilolimaVI:hle/speech-synthesis` → `main` · +192 −53 · 3 files · 1 commits · closed without merging Narration ("Screen Narration" in the title's accessibility settings) was silent: every speech stream was an empty WAVE file. Text (slot 0x68) and SSML (slot 0xa8) are now spoken by the host's default voice through WinRT `SpeechSynthesizer`, and the title reads back the WAVE file it makes. Where the host has no working voice, the stream is the previous silence, so nothing gets worse. **What is in it** - `crates/victory-hle/src/modules/speech.rs`: synthesis, per-stream handles that own their audio (freed on close, slot 0x70), tests - `crates/victory-hle/Cargo.toml`: `Media_Core`, `Media_SpeechSynthesis`, `Storage_Streams` features of `windows` - `README.md`: the runtime services row **Tested** - ASUS Vivobook S16, Ryzen 7 8845HS, Radeon 780M, Windows 11 26300, debug build - `cargo test -p victory-hle --lib speech`: 3 passed; `the_host_voice_speaks_text_and_ssml` synthesized real audio for both text and SSML (not skipped) - `cargo test --workspace`: 781 passed, 0 failed, 9 ignored - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean **Not tested** - In the title itself: I don't have the game files. The WAVE format the host makes (rate, channels) may differ from what the console returned; if the title expects a fixed format, it may need converting. - Voice listing (slot 0x40) and custom voices remain unimplemented; the default voice is always used. **AI use** Code, tests and description written with Claude (Claude Opus 5.5); I built and ran the tests on the hardware above.
Text and SSML streams were empty WAVE files, so narration was silent. They are now synthesized with Windows speech synthesis (WinRT SpeechSynthesizer) into the WAVE file the title reads back; with no working host voice the stream is the old silence. Voice listing and custom voices are still not supported.

Assisted-by: Claude (Claude Opus 5.5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:37 +00:00
github-bot closed this pull request 2026-11-26 05:13:37 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:08 UTC · original

Good shape: WinRT SpeechSynthesizer -> stream -> DataReader -> WAVE bytes, with SILENCE as the fallback so narration stays valid-but-empty on hosts without a voice. Honestly documented shortcut (default voice only, no voice enumeration since the title's voice-info record layout is unknown).

**@⁠kotekompotek** on GitHub · 2026-11-25 20:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2760#issuecomment-7173236605) Good shape: WinRT SpeechSynthesizer -> stream -> DataReader -> WAVE bytes, with SILENCE as the fallback so narration stays valid-but-empty on hosts without a voice. Honestly documented shortcut (default voice only, no voice enumeration since the title's voice-info record layout is unknown).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:22 UTC · original

Reviewed and tested 9e29b4b6 on Windows 11 (rustc 1.98.1 MSVC) against main (13f91ca).

Blocking bug reproduced on Windows 11: concurrent WinRT SpeechSynthesizer crashes with 0xc0000409

Running the standard parallel test suite (cargo test -p victory-hle --lib --locked) intermittently aborts the test binary with exit code: 0xc0000409 (STATUS_STACK_BUFFER_OVERRUN) while the speech tests run concurrently.

Controlled reproduction on the same Windows 11 machine:

  • cargo test -p victory-hle --lib --locked -- modules::speech:: (20 consecutive parallel runs): 7/20 runs (35%) crashed with 0xc0000409 (-1073740791) (runs 1, 2, 14, 16, 18, 19, 20).
  • cargo test -p victory-hle --lib --locked -- --test-threads=1: 148 passed, 0 failed (0 crashes).
  • cargo test -p victory-hle --lib --locked -- --skip modules::speech:: (6 consecutive parallel runs): 6/6 passed (145 passed, 0 failed).
  • Control on #2757 (same machine, 6 consecutive full parallel runs): 6/6 passed (147 passed, 0 failed).

Root cause: synthesize() (speech.rs:50-83) instantiates a fresh WinRT SpeechSynthesizer::new(), blocks on .join(), and immediately drops it on arbitrary caller threads without explicit COM/WinRT apartment lifecycle management or serialization. Concurrent activation/synthesis/teardown across threads (e.g., streams_are_wave_files and the_host_voice_speaks_text_and_ssml) triggers a WinRT/speech runtime __fastfail (0xc0000409). Moving synthesis onto a dedicated serialized worker (or serializing a lazily initialized synthesizer with explicit apartment init) should eliminate both the crash and repeated synthesizer startup cost.

Additional code-review notes

  1. Unchecked raw stream handles (speech.rs:104-107, 145-151): wave() and close_stream() cast any non-null *const u8 directly to &Vec<u8> / Box::from_raw, so a double-close, &SYNTHESIZER, or bogus handle causes UB/heap corruption; close() (0x50) also leaves open streams untracked. A handle table (as in #1822) would avoid raw-pointer UB.
  2. PCM format: synthesize() passes the host WinRT WAV bytes straight through without resampling/downmixing to the 16 kHz mono 16-bit PCM format used by SILENCE (unlike #82).
  3. Caller-thread blocking: create_stream / create_stream_ssml synchronously instantiate SpeechSynthesizer and .join() on the title's calling thread.
  4. Build/policy/merge: compiles under --locked, clippy (default & --all-features) 0 warnings, cargo xtask policy 184 files ok; clean merge-tree against 13f91ca, conflicts with #82 and #1822 in Cargo.toml and speech.rs.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2760#issuecomment-7173563514) Reviewed and tested `9e29b4b6` on Windows 11 (`rustc 1.98.1` MSVC) against `main` (`13f91ca`). ### Blocking bug reproduced on Windows 11: concurrent WinRT `SpeechSynthesizer` crashes with `0xc0000409` Running the standard parallel test suite (`cargo test -p victory-hle --lib --locked`) intermittently aborts the test binary with **`exit code: 0xc0000409 (STATUS_STACK_BUFFER_OVERRUN)`** while the speech tests run concurrently. Controlled reproduction on the same Windows 11 machine: - `cargo test -p victory-hle --lib --locked -- modules::speech::` (20 consecutive parallel runs): **7/20 runs (35%) crashed with `0xc0000409` (`-1073740791`)** (runs 1, 2, 14, 16, 18, 19, 20). - `cargo test -p victory-hle --lib --locked -- --test-threads=1`: **148 passed, 0 failed** (0 crashes). - `cargo test -p victory-hle --lib --locked -- --skip modules::speech::` (6 consecutive parallel runs): **6/6 passed** (`145 passed, 0 failed`). - Control on `#2757` (same machine, 6 consecutive full parallel runs): **6/6 passed** (`147 passed, 0 failed`). Root cause: `synthesize()` (`speech.rs:50-83`) instantiates a fresh WinRT `SpeechSynthesizer::new()`, blocks on `.join()`, and immediately drops it on arbitrary caller threads without explicit COM/WinRT apartment lifecycle management or serialization. Concurrent activation/synthesis/teardown across threads (e.g., `streams_are_wave_files` and `the_host_voice_speaks_text_and_ssml`) triggers a WinRT/speech runtime `__fastfail` (`0xc0000409`). Moving synthesis onto a dedicated serialized worker (or serializing a lazily initialized synthesizer with explicit apartment init) should eliminate both the crash and repeated synthesizer startup cost. ### Additional code-review notes 1. **Unchecked raw stream handles (`speech.rs:104-107, 145-151`)**: `wave()` and `close_stream()` cast any non-null `*const u8` directly to `&Vec<u8>` / `Box::from_raw`, so a double-close, `&SYNTHESIZER`, or bogus handle causes UB/heap corruption; `close()` (`0x50`) also leaves open streams untracked. A handle table (as in `#1822`) would avoid raw-pointer UB. 2. **PCM format**: `synthesize()` passes the host WinRT WAV bytes straight through without resampling/downmixing to the 16 kHz mono 16-bit PCM format used by `SILENCE` (unlike `#82`). 3. **Caller-thread blocking**: `create_stream` / `create_stream_ssml` synchronously instantiate `SpeechSynthesizer` and `.join()` on the title's calling thread. 4. **Build/policy/merge**: compiles under `--locked`, `clippy` (default & `--all-features`) 0 warnings, `cargo xtask policy` 184 files ok; clean `merge-tree` against `13f91ca`, conflicts with `#82` and `#1822` in `Cargo.toml` and `speech.rs`.
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-25 20:29 UTC · original

Thanks @⁠fuzeofficial for the thorough test and review, and @⁠kotekompotek for the look. I confirm the crash: creating and dropping a WinRT SpeechSynthesizer per call from arbitrary threads isn't safe under concurrency, and the handle and PCM-format points are fair too.

I also hadn't seen #82, which predates this, already synthesizes on a dedicated MTA thread and converts to 16 kHz mono PCM. Rather than compete with it, I'm closing this in favor of #82. My voice-selection change (listing host voices for slot 0x40 and honoring the picked voice) isn't in #82, so I'll rebase that onto #82's approach as a follow-up.

**@⁠kilolimaVI** on GitHub · 2026-11-25 20:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2760#issuecomment-7173746580) Thanks @⁠fuzeofficial for the thorough test and review, and @⁠kotekompotek for the look. I confirm the crash: creating and dropping a WinRT `SpeechSynthesizer` per call from arbitrary threads isn't safe under concurrency, and the handle and PCM-format points are fair too. I also hadn't seen #82, which predates this, already synthesizes on a dedicated MTA thread and converts to 16 kHz mono PCM. Rather than compete with it, I'm closing this in favor of #82. My voice-selection change (listing host voices for slot 0x40 and honoring the picked voice) isn't in #82, so I'll rebase that onto #82's approach as a follow-up.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
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
github/Marvisak--VIctory!2760
No description provided.