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

Open
github-bot wants to merge 1 commit from github-bot/gh-82 into main AGit
Owner

@⁠permadiego on GitHub · 2026-11-24 00:19 UTC · original
permadiego:hle/speech-synthesis → main · +301 −41 · 2 files · 1 commits · open

What changed

The title's narration (accessibility speech) was silent: every stream the accessibility provider created (slot 0x68 from text, 0xa8 from SSML) was an empty WAVE file. It is now spoken by the host's WinRT speech synthesizer (Windows.Media.SpeechSynthesis) in its default voice.

  • Synthesis runs on a thread of its own in the multithreaded apartment, whatever the title's thread initialised.
  • The host's WAVE output is mixed to mono and resampled (linearly) to 16 kHz 16-bit PCM, the format the silent stub already used, so the title sees the same stream layout as before, now with samples.
  • SSML the host refuses is spoken as its plain text (markup dropped).
  • A stream handle is now the boxed WAVE file; closing a stream (slot 0x70) frees it. Synthesizer handles stay fixed.
  • With no voice installed, or off Windows, a stream is still a valid empty WAVE file, as before.
  • victory-hle now depends on windows on Windows (it was optional, for diagnostics only), adding Foundation, Media_SpeechSynthesis and Storage_Streams. victory-gpu already builds the crate, so this adds only those modules.

Not done: voices are not listed (enumerate_voices still reports none) and the title's voice choice is ignored; the default voice speaks everything.

Verification

cargo test -p victory-hle speech on Windows 10 with the David, Zira and Mark voices:

  • text and SSML each give more than half a second of 16 kHz audio with over 1,000 samples above 1,000 in magnitude (not silence); the stream reads back through the size and data slots exactly as the title reads it, and a too-small buffer is refused;
  • empty text gives a 44-byte WAVE file;
  • a synthetic 22,050 Hz stereo file (with an odd-sized chunk before data) mixes and resamples to 1,600 samples of the expected value; 8-bit and non-WAVE input is refused.

Not run in the game: I have no world run here, so the title playing the narration is untested.

🤖 Generated with Claude Code

**@⁠permadiego** on GitHub · 2026-11-24 00:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/82) `permadiego:hle/speech-synthesis` → `main` · +301 −41 · 2 files · 1 commits · open ## What changed The title's narration (accessibility speech) was silent: every stream the accessibility provider created (slot 0x68 from text, 0xa8 from SSML) was an empty WAVE file. It is now spoken by the host's WinRT speech synthesizer (`Windows.Media.SpeechSynthesis`) in its default voice. - Synthesis runs on a thread of its own in the multithreaded apartment, whatever the title's thread initialised. - The host's WAVE output is mixed to mono and resampled (linearly) to 16 kHz 16-bit PCM, the format the silent stub already used, so the title sees the same stream layout as before, now with samples. - SSML the host refuses is spoken as its plain text (markup dropped). - A stream handle is now the boxed WAVE file; closing a stream (slot 0x70) frees it. Synthesizer handles stay fixed. - With no voice installed, or off Windows, a stream is still a valid empty WAVE file, as before. - `victory-hle` now depends on `windows` on Windows (it was optional, for diagnostics only), adding `Foundation`, `Media_SpeechSynthesis` and `Storage_Streams`. `victory-gpu` already builds the crate, so this adds only those modules. Not done: voices are not listed (`enumerate_voices` still reports none) and the title's voice choice is ignored; the default voice speaks everything. ## Verification `cargo test -p victory-hle speech` on Windows 10 with the David, Zira and Mark voices: - text and SSML each give more than half a second of 16 kHz audio with over 1,000 samples above 1,000 in magnitude (not silence); the stream reads back through the size and data slots exactly as the title reads it, and a too-small buffer is refused; - empty text gives a 44-byte WAVE file; - a synthetic 22,050 Hz stereo file (with an odd-sized chunk before `data`) mixes and resamples to 1,600 samples of the expected value; 8-bit and non-WAVE input is refused. Not run in the game: I have no world run here, so the title playing the narration is untested. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Speech streams were always empty WAVE files, so narration was silent.
They are now spoken by the WinRT speech synthesizer in the host's
default voice, on a thread of our own in the multithreaded apartment,
then mixed to mono and resampled to the 16 kHz 16-bit PCM the silent
stub already used. SSML the host refuses is spoken as its plain text.
A stream handle is its boxed WAVE file, freed when the stream closes.
With no voice, or off Windows, streams stay empty WAVE files.

victory-hle now depends on windows on Windows (it was diagnostics-only)
with the Foundation, Media_Core, Media_SpeechSynthesis and
Storage_Streams features.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:40 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:12 UTC · original

Tested df5e928: pass (no regression).

  • Tested the Windows build under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), cargo xwin ... --target x86_64-pc-windows-msvc -p victory-hle: 83 passed, 1 failed, including the 4 tests this PR adds.
  • The one failure is modules::net::tests::only_loopback_is_reachable — Wine's ws2_32 lacks WSAConnectByList (the same gap as #118), not this PR.
  • The SAPI/narration path itself is not exercised on this machine; the suite covers the module logic.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7118859740) Tested `df5e928`: **pass (no regression)**. - Tested the Windows build under **Wine 11.22 + vkd3d-proton 3.1** on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), `cargo xwin ... --target x86_64-pc-windows-msvc -p victory-hle`: **83 passed, 1 failed**, including the 4 tests this PR adds. - The one failure is `modules::net::tests::only_loopback_is_reachable` — Wine's `ws2_32` lacks `WSAConnectByList` (the same gap as #118), not this PR. - The SAPI/narration path itself is not exercised on this machine; the suite covers the module logic. No game data used.
Author
Owner

@⁠Exorion1er on GitHub · 2026-11-24 09:33 UTC · original

#691 is the same feature (WinRT SpeechSynthesizer for the title's narration), but its branch includes a workspace-wide cargo fmt commit (36 files, about +1,800/−650), so it conflicts with main and would conflict with many open PRs. This PR changes only speech.rs and Cargo.toml and merges cleanly. #691's speech part has a few more tests, which could be carried over here.

Checked by reading both diffs. AI-assisted (Claude Code).

**@⁠Exorion1er** on GitHub · 2026-11-24 09:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7127579131) #691 is the same feature (WinRT `SpeechSynthesizer` for the title's narration), but its branch includes a workspace-wide `cargo fmt` commit (36 files, about +1,800/−650), so it conflicts with `main` and would conflict with many open PRs. This PR changes only `speech.rs` and `Cargo.toml` and merges cleanly. #691's speech part has a few more tests, which could be carried over here. Checked by reading both diffs. AI-assisted (Claude Code).
Author
Owner

@⁠gabrielvbraga on GitHub · 2026-11-24 13:47 UTC · original

Tested this branch on Windows 11 with pt-BR voices (Microsoft Maria and Daniel), a different setup from the Windows 10 / English voices above: cargo test -p victory-hle speech passes all 4 tests, including text_and_ssml_are_spoken_when_a_voice_is_installed.

I'd started the same thing in #825 before seeing this PR, and I'll drop mine in favour of this one. Two differences in my branch (https://github.com/gabrielvbraga/VIctory/tree/speech-synthesis) that may be worth taking:

  1. speak joins its thread with no time limit, so a synthesizer that never completes would block the title's thread for good. Mine keeps one long-lived speech thread and waits with recv_timeout (10 s), falling back to the silent stream.
  2. close_stream frees whatever handle it is given, so a second close of the same stream is a double free, and stream_size / stream_data on a closed handle read freed memory. Mine keeps open streams in a map keyed by handle: close frees only a handle still in the map, and an unknown handle reads as silence.

Happy to help if you want either change.

**@⁠gabrielvbraga** on GitHub · 2026-11-24 13:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7133343995) Tested this branch on Windows 11 with pt-BR voices (Microsoft Maria and Daniel), a different setup from the Windows 10 / English voices above: `cargo test -p victory-hle speech` passes all 4 tests, including `text_and_ssml_are_spoken_when_a_voice_is_installed`. I'd started the same thing in #825 before seeing this PR, and I'll drop mine in favour of this one. Two differences in my branch (https://github.com/gabrielvbraga/VIctory/tree/speech-synthesis) that may be worth taking: 1. `speak` joins its thread with no time limit, so a synthesizer that never completes would block the title's thread for good. Mine keeps one long-lived speech thread and waits with `recv_timeout` (10 s), falling back to the silent stream. 2. `close_stream` frees whatever handle it is given, so a second close of the same stream is a double free, and `stream_size` / `stream_data` on a closed handle read freed memory. Mine keeps open streams in a map keyed by handle: close frees only a handle still in the map, and an unknown handle reads as silence. Happy to help if you want either change.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:15 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-hle/Cargo.toml.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7148325978) <!-- victory-triage v1 head=df5e928aa0c5572dfc5289065a5b89795be27b94 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-hle/Cargo.toml`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠gabrielvbraga on GitHub · 2026-11-26 16:50 UTC · original

The two changes I suggested above are on this branch, rebased onto current main and passing clippy and tests: https://github.com/gabrielvbraga/VIctory/tree/speech-synthesis

Happy to send them as a small follow-up PR once this one is merged.

**@⁠gabrielvbraga** on GitHub · 2026-11-26 16:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7198173466) The two changes I suggested above are on this branch, rebased onto current main and passing clippy and tests: https://github.com/gabrielvbraga/VIctory/tree/speech-synthesis Happy to send them as a small follow-up PR once this one is merged.
This pull request has changes conflicting with the target branch.
  • crates/victory-hle/Cargo.toml
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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