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

Open
github-bot wants to merge 2 commits from github-bot/gh-2770 into main AGit
Owner

@⁠kilolimaVI on GitHub · 2026-11-25 20:08 UTC · original
kilolimaVI:hle/speech-voices → main · +440 −62 · 3 files · 2 commits · draft

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.

**@⁠kilolimaVI** on GitHub · 2026-11-25 20:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2770) `kilolimaVI:hle/speech-voices` → `main` · +440 −62 · 3 files · 2 commits · draft 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:50 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:36 UTC · original

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 13f91cae. Nothing from the game was used.

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

**@⁠oni-swr** on GitHub · 2026-11-25 20:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7173915417) 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` 13f91cae. Nothing from the game was used. AI-assisted review (Claude Code / Claude Sonnet 5.5).
Author
Owner

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

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** on GitHub · 2026-11-25 20:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7174024402) 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.
Author
Owner

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

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7174037184) 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.
Author
Owner

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

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.

**@⁠kilolimaVI** on GitHub · 2026-11-25 20:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7174075375) 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.
Author
Owner

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

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7174294927) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2770/head:github-bot/gh-2770'
git switch 'github-bot/gh-2770'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2770'
git switch 'github-bot/gh-2770'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2770'
git switch 'github-bot/gh-2770'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2770'
git switch 'main'
git merge --squash 'github-bot/gh-2770'
git switch 'main'
git merge --ff-only 'github-bot/gh-2770'
git switch 'main'
git merge 'github-bot/gh-2770'
git push origin 'main'
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!2770
No description provided.