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

Open
kilolimaVI wants to merge 2 commits from upstream-pr/2770 into main
kilolimaVI commented 2026-11-25 20:08:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-25T20:08:55Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6612780989 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2770). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-25T20:08:55Z. --- 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.
oni-swr commented 2026-11-25 21:03:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T20:36:16Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173915417 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7173915417). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T20:36:16Z. --- 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).
kilolimaVI commented 2026-11-25 21:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-25T20:40:37Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7174024402 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7174024402). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-25T20:40:37Z. --- 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.
kotekompotek commented 2026-11-25 21:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:41:07Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7174037184 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7174037184). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T20:41:07Z. --- 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 commented 2026-11-25 21:03:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-25T20:42:35Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7174075375 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7174075375). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-25T20:42:35Z. --- 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 commented 2026-11-25 21:03:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:52:01Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7174294927 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2770#issuecomment-7174294927). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:52:01Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2770:upstream-pr/2770'
git switch 'upstream-pr/2770'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2770'
git switch 'upstream-pr/2770'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2770'
git switch 'upstream-pr/2770'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2770'
git switch 'main'
git merge --squash 'upstream-pr/2770'
git switch 'main'
git merge --ff-only 'upstream-pr/2770'
git switch 'main'
git merge 'upstream-pr/2770'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2768
No description provided.