HLE: speak the title's narration with the host's default voice #2758
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2760"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-25T19:52:02Z.
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), testscrates/victory-hle/Cargo.toml:Media_Core,Media_SpeechSynthesis,Storage_Streamsfeatures ofwindowsREADME.md: the runtime services rowTested
cargo test -p victory-hle --lib speech: 3 passed;the_host_voice_speaks_text_and_ssmlsynthesized real audio for both text and SSML (not skipped)cargo test --workspace: 781 passed, 0 failed, 9 ignoredcargo clippy --workspace --all-targets --locked -- -D warnings: cleanNot tested
AI use
Code, tests and description written with Claude (Claude Opus 5.5); I built and ran the tests on the hardware above.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:08:05Z.
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).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:22:01Z.
Reviewed and tested
9e29b4b6on Windows 11 (rustc 1.98.1MSVC) againstmain(13f91ca).Blocking bug reproduced on Windows 11: concurrent WinRT
SpeechSynthesizercrashes with0xc0000409Running the standard parallel test suite (
cargo test -p victory-hle --lib --locked) intermittently aborts the test binary withexit 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 with0xc0000409(-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).#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 WinRTSpeechSynthesizer::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_filesandthe_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
speech.rs:104-107, 145-151):wave()andclose_stream()cast any non-null*const u8directly 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.synthesize()passes the host WinRT WAV bytes straight through without resampling/downmixing to the 16 kHz mono 16-bit PCM format used bySILENCE(unlike#82).create_stream/create_stream_ssmlsynchronously instantiateSpeechSynthesizerand.join()on the title's calling thread.--locked,clippy(default &--all-features) 0 warnings,cargo xtask policy184 files ok; cleanmerge-treeagainst13f91ca, conflicts with#82and#1822inCargo.tomlandspeech.rs.Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-25T20:29:25Z.
Thanks @fuzeofficial for the thorough test and review, and @kotekompotek for the look. I confirm the crash: creating and dropping a WinRT
SpeechSynthesizerper 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