Skip to content

HLE: list the host's voices to the title and speak in the one it picks - #2770

Draft
kilolimaVI wants to merge 2 commits into
Marvisak:mainfrom
kilolimaVI:hle/speech-voices
Draft

kilolimaVI wants to merge 2 commits into
Marvisak:mainfrom
kilolimaVI:hle/speech-voices

Conversation

@kilolimaVI

@kilolimaVI kilolimaVI commented Nov 25, 2026 •

Copy link
Copy Markdown

Stacked on #2760; only the top commit belongs here.

GTA VI's narration settings let the player pick a voice, but voice listing (slot 0x40) reported no voices and a custom voice (slot 0x60) was ignored. Now:

  • XSpeechSynthesizerEnumerateInstalledVoices calls back once per host voice (WinRT SpeechSynthesizer::AllVoices) with an XSpeechSynthesizerVoiceInformation record laid out as documented (description, display name, gender 0 female / 1 male, voice id, language), stopping when the callback returns false. The strings live until the call returns.
  • A synthesizer handle now owns its state: the voice the title picked by id (XSpeechSynthesizerSetCustomVoice), until SetDefaultVoice. An id the host does not have is refused with E_INVALIDARG. Streams are spoken in the picked voice, or the default if that voice disappears.

Tested

  • ASUS Vivobook S16, Ryzen 7 8845HS, Radeon 780M, Windows 11 26300, debug build
  • cargo test -p victory-hle --lib speech: 5 passed, none skipped (two new: the listing read back as the title reads it, and a picked voice speaks)
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean

Not tested

  • In the title itself (no game files): whether its settings list the voices and switch between them.
  • Which error code the console returns for an unknown voice id (not documented); E_INVALIDARG is a guess.

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)
Voice listing (slot 0x40) called back with no voices, and a custom voice was ignored. The host's WinRT voices are now listed as XSpeechSynthesizerVoiceInformation records (description, display name, gender, id, language), and a synthesizer keeps the voice the title picks by id until it sets the default again; an id the host does not have is refused with E_INVALIDARG.

Assisted-by: Claude (Claude Opus 5.5)
@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Independent verification of head 3d4d19b0 (WARP/CPU): looks good.

  • Diff: speech streams now carry audio from the host's WinRT speech synthesis, with silence kept as the fallback; voices are listed to the title and a picked voice is used; synthesizer and stream handles are heap-allocated and freed on close (slot 0x70 now has its own close). README and Cargo.toml features match. Scope is fine.
  • Tests: victory-hle --lib 150 pass, 0 fail (baseline 146). Clippy -D warnings is clean.
  • Negative control: when I made stream() ignore the host's audio (always silence), a_picked_voice_speaks_and_an_unknown_one_is_refused fails (the audio is too short). This machine has host voices, so the test is not skipped. Without a voice, the voice tests skip with a message, as designed.
  • Minor: a title that closes a stream or synthesizer twice is a double free (the SAFETY comments rely on the title closing each once), where the old static handles tolerated it. Not blocking.

Method: WARP/CPU only (no physical GPU; VICTORY_WARP=1, VICTORY_D3D12_WARP=1, Windows SDK dxil.dll on PATH, so DXIL validation ran), cargo test -p <crate> --lib --locked and cargo clippy -p <crate> --all-targets --locked -- -D warnings, compared with origin/main 13f91ca. Nothing from the game was used.

AI-assisted review (Claude Code / Claude Sonnet 5.5).

@kilolimaVI

Copy link
Copy Markdown
Author

Thanks @oni-swr, especially for the negative control: good to know the voice test fails when the audio is fake.

On the double close: agreed. Two more things apply here, both from review of my (now closed) speech PR this is stacked on:

  • WinRT synthesizers made and dropped on several threads at once crash the process (0xc0000409, 7/20 parallel runs on another reviewer's machine).
  • The handles are raw pointers, so a double close is a double free, as you noted.

Both are fixed in the same change on DexNom/VIctory: one speech thread owning the synthesizer, handles as keys into a table (double or foreign closes refused), and output converted to 16 kHz mono; 20 consecutive parallel runs pass there. Here I'm converting this to a draft until #82 (the earlier speech PR) is rebased or merged, then I'll rebuild voice listing on top of it with those fixes.

@kilolimaVI
kilolimaVI marked this pull request as draft November 25, 2026 20:40
@kotekompotek

Copy link
Copy Markdown

Builds on #2760's synthesize path with real voice enumeration - SpeechSynthesizer::AllVoices mapped into the title's VoiceInformation records so the title's picked voice is actually honored rather than always default. The record layout for the voice list was the unknown flagged in #2760; this apparently resolves it. Untested-live caveat in the README stays honest.

@kilolimaVI

Copy link
Copy Markdown
Author

Thanks @kotekompotek. The record layout isn't guessed: it's the documented XSpeechSynthesizerVoiceInformation from the public GDK reference (Description, DisplayName, Gender as uint32 Female=0/Male=1, VoiceId, Language), and the callback matches XSpeechSynthesizerInstalledVoicesCallback. As noted above, this is a draft until #82 lands, since #2760 is closed in its favor.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Tested 3d4d19b0 on Windows 11 (rustc 1.98.1 MSVC) against main (13f91ca).

  • Same concurrent WinRT 0xC0000409 crash reproduces here: running cargo test -p victory-hle --lib --locked -- modules::speech:: 20 consecutive times in parallel crashed in 8/20 runs (40%) with exit code -1073740791 (0xC0000409) (runs 4, 8, 10, 13, 14, 15, 16, 17), because both voices() (speech.rs:75-94) and synthesize() (speech.rs:107-149) still construct/drop WinRT SpeechSynthesizer concurrently on arbitrary caller threads.
  • Additional notes for the planned rebuild (since #2760 was closed):
    1. Moving WinRT SpeechSynthesizer calls onto a dedicated serialized worker thread with explicit apartment init should eliminate the 0xC0000409 crashes.
    2. create/close (speech.rs:217-234) and stream/close_stream (speech.rs:156-175, 273-279) still cast raw pointers directly to Box::from_raw, leaving double-close or bogus handles as UB; a handle table would guard both.
    3. synthesize() passes the host WAV bytes through without normalizing to 16 kHz mono 16-bit PCM (unlike #82), and voices() currently swallows WinRT enumeration errors silently.
  • Build/policy checks: cargo clippy -p victory-hle --all-targets -- -D warnings (default & --all-features) 0 warnings; cargo xtask policy 184 files ok; enumerate_voices CString lifetime and replace('�', "") handling look clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants