HLE: speak the title's narration with the host's speech synthesizer #3394

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

@⁠kilolimaVI on GitHub · 2026-11-26 21:52 UTC · original
kilolimaVI:hle/speech-on-main → main · +413 −39 · 2 files · 2 commits · open

README: "Speech is silent". This is #82 by @⁠permadiego brought onto current main, plus a fix for a crash in it.

What it does: the title's XSpeechSynthesizer calls go to the Windows speech synthesizer (WinRT SpeechSynthesizer): text and SSML become 16 kHz mono WAV streams the title plays.

The fix: #82 created and dropped a synthesizer per line on a thread of its own. Speaking from several threads at once (the title does) crashed the process with 0xc0000409: a stress test of 8 threads × 3 lines crashed on its first run. Here one speech thread owns a single lazily made synthesizer and takes lines from a queue; callers wait up to 10 s for their answer.

Merge onto main: one conflict, in crates/victory-hle/Cargo.toml (main's windows features for modules::fidelityfx); both feature sets kept.

Checked on 63bcca4, Windows 11, AMD Radeon 780M / Ryzen 7 8845HS, toolchain 1.98.1:

  • cargo test -p victory-hle --lib --locked -- speech: 5 passed (including lines_spoken_on_many_threads_at_once_all_come_back)
  • same, 10 runs in parallel: 0/10 failures
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings, and with --all-features: clean

Not checked in the title (no game files). Supersedes #82.

AI-assisted (Claude), reviewed and tested by me.

**@⁠kilolimaVI** on GitHub · 2026-11-26 21:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/3394) `kilolimaVI:hle/speech-on-main` → `main` · +413 −39 · 2 files · 2 commits · open README: "Speech is silent". This is #82 by @⁠permadiego brought onto current main, plus a fix for a crash in it. **What it does:** the title's `XSpeechSynthesizer` calls go to the Windows speech synthesizer (WinRT `SpeechSynthesizer`): text and SSML become 16 kHz mono WAV streams the title plays. **The fix:** #82 created and dropped a synthesizer per line on a thread of its own. Speaking from several threads at once (the title does) crashed the process with `0xc0000409`: a stress test of 8 threads × 3 lines crashed on its first run. Here one speech thread owns a single lazily made synthesizer and takes lines from a queue; callers wait up to 10 s for their answer. **Merge onto main:** one conflict, in `crates/victory-hle/Cargo.toml` (main's `windows` features for `modules::fidelityfx`); both feature sets kept. **Checked** on 63bcca4, Windows 11, AMD Radeon 780M / Ryzen 7 8845HS, toolchain 1.98.1: - `cargo test -p victory-hle --lib --locked -- speech`: 5 passed (including `lines_spoken_on_many_threads_at_once_all_come_back`) - same, 10 runs in parallel: 0/10 failures - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`, and with `--all-features`: clean Not checked in the title (no game files). Supersedes #82. AI-assisted (Claude), reviewed and tested by me.
#82 by permadiego, brought onto current main, with one speech thread owning the synthesizer: concurrent WinRT SpeechSynthesizer create/drop crashed the process (0xc0000409).

Co-Authored-By: permadiego <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:06:30 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 22:09 UTC · original · approved these changes

LGTM — verified on Windows against origin/main (63bcca4).

  • Wiring Windows host speech synthesis into modules::speech (with SSML stripping, resampling/mixing, and multi-threaded synthesis coverage) works cleanly on Windows.
  • cargo test -p victory-hle --lib modules::speech:: -- --test-threads=1: 5 passed, 0 failed (empty_text_is_an_empty_wave_file, host_audio_is_mixed_and_resampled, lines_spoken_on_many_threads_at_once_all_come_back, ssml_text_without_markup, text_and_ssml_are_spoken_when_a_voice_is_installed).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 22:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3394#pullrequestreview-6081006362) · **approved these changes** LGTM — verified on Windows against `origin/main` (`63bcca4`). - Wiring Windows host speech synthesis into `modules::speech` (with SSML stripping, resampling/mixing, and multi-threaded synthesis coverage) works cleanly on Windows. - `cargo test -p victory-hle --lib modules::speech:: -- --test-threads=1`: 5 passed, 0 failed (`empty_text_is_an_empty_wave_file`, `host_audio_is_mixed_and_resampled`, `lines_spoken_on_many_threads_at_once_all_come_back`, `ssml_text_without_markup`, `text_and_ssml_are_spoken_when_a_voice_is_installed`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 22:24 UTC · original · approved these changes

Looks solid. Isolating SpeechSynthesizer on a dedicated MTA worker thread (crates/victory-hle/src/modules/speech.rs) cleanly avoids polluting title threads' COM apartments and prevents the multi-threaded synthesizer teardown crash, while resetting the synthesizer on error and falling back from malformed SSML to plain text and silence when unavailable. The added WinRT features in crates/victory-hle/Cargo.toml:41-45 stay properly gated under [target.'cfg(windows)'.dependencies] and build under --locked.

Verified merged onto origin/main (63bcca43) on Windows 11 with a host voice installed:

  • cargo xtask policy (191 files ok) and cargo clippy --locked -p victory-hle --all-targets -- -D warnings (both default and --all-features) pass cleanly.
  • cargo test --locked -p victory-hle --lib -- modules::speech:: passes 5/5 (0.36 s), exercising live text and SSML synthesis plus 8-thread × 3-call concurrency.
  • Additional edge-case checks passed: long narration (~120 items, 5,243,086-byte WAV matching the RIFF header with no DataReader truncation), malformed SSML fallback to plain text (57,324 bytes) and whitespace-only SSML (44 bytes), FFI null-pointer / short-buffer / idempotent read / close_stream(null) boundaries, and malformed WAV inputs (u32::MAX chunk length, zero channels/rate, 1-sample 48 kHz downsample, trailing bytes).

Two minor non-blocking notes:

  • to_console accepts 0xFFFE (WAVE_FORMAT_EXTENSIBLE) with bits == 16 without checking that SubFormat is KSDATAFORMAT_SUBTYPE_PCM (fine for the host synthesizer, which emits PCM, though worth noting if ever fed arbitrary WAVs).
  • The doc comment above lines_spoken_on_many_threads_at_once_all_come_back still describes creating/dropping a synthesizer per thread rather than routing through the shared worker queue.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 22:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3394#pullrequestreview-6081101867) · **approved these changes** Looks solid. Isolating `SpeechSynthesizer` on a dedicated MTA worker thread (`crates/victory-hle/src/modules/speech.rs`) cleanly avoids polluting title threads' COM apartments and prevents the multi-threaded synthesizer teardown crash, while resetting the synthesizer on error and falling back from malformed SSML to `plain` text and silence when unavailable. The added WinRT features in `crates/victory-hle/Cargo.toml:41-45` stay properly gated under `[target.'cfg(windows)'.dependencies]` and build under `--locked`. Verified merged onto `origin/main` (`63bcca43`) on Windows 11 with a host voice installed: - `cargo xtask policy` (191 files ok) and `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` (both default and `--all-features`) pass cleanly. - `cargo test --locked -p victory-hle --lib -- modules::speech::` passes 5/5 (0.36 s), exercising live text and SSML synthesis plus 8-thread × 3-call concurrency. - Additional edge-case checks passed: long narration (~120 items, 5,243,086-byte WAV matching the RIFF header with no `DataReader` truncation), malformed SSML fallback to plain text (57,324 bytes) and whitespace-only SSML (44 bytes), FFI null-pointer / short-buffer / idempotent read / `close_stream(null)` boundaries, and malformed WAV inputs (`u32::MAX` chunk length, zero channels/rate, 1-sample 48 kHz downsample, trailing bytes). Two minor non-blocking notes: - `to_console` accepts `0xFFFE` (`WAVE_FORMAT_EXTENSIBLE`) with `bits == 16` without checking that `SubFormat` is `KSDATAFORMAT_SUBTYPE_PCM` (fine for the host synthesizer, which emits PCM, though worth noting if ever fed arbitrary WAVs). - The doc comment above `lines_spoken_on_many_threads_at_once_all_come_back` still describes creating/dropping a synthesizer per thread rather than routing through the shared worker queue.
Review follow-ups from fuzeofficial on #3394: to_console now checks that an extensible file's SubFormat is KSDATAFORMAT_SUBTYPE_PCM (a test covers PCM and IEEE-float sub-formats), and the many-threads test's doc comment describes the shared speech thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 12:06 UTC · original

@⁠fuzeofficlal thanks, both notes are addressed in the latest commit:

  • to_console now takes WAVE_FORMAT_EXTENSIBLE only when its SubFormat is KSDATAFORMAT_SUBTYPE_PCM; the new test extensible_wave_files_count_only_with_a_pcm_sub_format checks a PCM one is read and an IEEE-float one is refused.
  • The doc comment on lines_spoken_on_many_threads_at_once_all_come_back now describes the shared speech thread.

Re-checked on 63bcca4: cargo test -p victory-hle --lib --locked -- speech 6 passed; clippy -D warnings default and --all-features clean.

AI-assisted (Claude).

**@⁠kilolimaVI** on GitHub · 2026-11-27 12:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/3394#issuecomment-7217846662) @⁠fuzeofficlal thanks, both notes are addressed in the latest commit: - `to_console` now takes `WAVE_FORMAT_EXTENSIBLE` only when its `SubFormat` is `KSDATAFORMAT_SUBTYPE_PCM`; the new test `extensible_wave_files_count_only_with_a_pcm_sub_format` checks a PCM one is read and an IEEE-float one is refused. - The doc comment on `lines_spoken_on_many_threads_at_once_all_come_back` now describes the shared speech thread. Re-checked on 63bcca4: `cargo test -p victory-hle --lib --locked -- speech` 6 passed; clippy `-D warnings` default and `--all-features` clean. AI-assisted (Claude).
This pull request can be merged automatically.
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/3394/head:github-bot/gh-3394'
git switch 'github-bot/gh-3394'

Merge

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