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

Open
permadiego wants to merge 1 commit from upstream-pr/82 into main
permadiego commented 2026-11-24 00:19:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by permadiego on 2026-11-24T00:19:29Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5463632387 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/82). Originally posted by [permadiego](https://github.com/permadiego) on 2026-11-24T00:19:29Z. --- ## 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)
DaviTostes commented 2026-11-24 06:54:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:12:01Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118859740 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7118859740). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:12:01Z. --- 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.
Exorion1er commented 2026-11-24 10:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Exorion1er on 2026-11-24T09:33:30Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7127579131 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7127579131). Originally posted by [Exorion1er](https://github.com/Exorion1er) on 2026-11-24T09:33:30Z. --- #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).
gabrielvbraga commented 2026-11-24 14:04:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by gabrielvbraga on 2026-11-24T13:47:34Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133343995 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7133343995). Originally posted by [gabrielvbraga](https://github.com/gabrielvbraga) on 2026-11-24T13:47:34Z. --- 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.
Marvisak commented 2026-11-25 01:07:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:15:51Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148325978 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7148325978). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:15:51Z. --- <!-- 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)_
gabrielvbraga commented 2026-11-26 16:50:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by gabrielvbraga on 2026-11-26T16:50:57Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7198173466 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7198173466). Originally posted by [gabrielvbraga](https://github.com/gabrielvbraga) on 2026-11-26T16:50:57Z. --- 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.
kilolimaVI commented 2026-11-26 21:17:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-26T21:17:35Z.


Crash report and a fix for this PR.

Crash: speaking on several threads at once kills the test process with 0xc0000409 (STATUS_STACK_BUFFER_OVERRUN). Each speak creates and drops its own WinRT SpeechSynthesizer on a thread of its own, and concurrent create/drop of the synthesizer is what crashes. Reproduced with a stress test (8 threads × 3 lines each): it crashed on the first run on Windows 11, AMD Radeon 780M / Ryzen 7 8845HS, toolchain 1.98.1. The title speaks from several threads, so this would hit it too.

Fix: one dedicated speech thread owns a single lazily created synthesizer and takes lines from a queue (OnceLock<Option<Sender<Line>>>); callers wait for their answer up to 10 s. With it the same stress test passes 20/20 runs and clippy is clean.

Commits on top of this PR's head: https://github.com/kilolimaVI/VIctory/commits/pr82-fix
Happy to open it as a PR against this branch, or the fix can be cherry-picked.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203583814 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7203583814). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-26T21:17:35Z. --- Crash report and a fix for this PR. **Crash:** speaking on several threads at once kills the test process with `0xc0000409` (STATUS_STACK_BUFFER_OVERRUN). Each `speak` creates and drops its own WinRT `SpeechSynthesizer` on a thread of its own, and concurrent create/drop of the synthesizer is what crashes. Reproduced with a stress test (8 threads × 3 lines each): it crashed on the first run on Windows 11, AMD Radeon 780M / Ryzen 7 8845HS, toolchain 1.98.1. The title speaks from several threads, so this would hit it too. **Fix:** one dedicated speech thread owns a single lazily created synthesizer and takes lines from a queue (`OnceLock<Option<Sender<Line>>>`); callers wait for their answer up to 10 s. With it the same stress test passes 20/20 runs and clippy is clean. Commits on top of this PR's head: https://github.com/kilolimaVI/VIctory/commits/pr82-fix Happy to open it as a PR against this branch, or the fix can be cherry-picked. AI-assisted (Claude).
kilolimaVI commented 2026-11-27 10:24:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T10:24:44Z.


Brought onto current main with the concurrency fix as #3394, crediting you as co-author. Thanks for the original!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7215853698 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/82#issuecomment-7215853698). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T10:24:44Z. --- Brought onto current main with the concurrency fix as #3394, crediting you as co-author. Thanks for the original!
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/82:upstream-pr/82'
git switch 'upstream-pr/82'

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/82'
git switch 'upstream-pr/82'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/82'
git switch 'upstream-pr/82'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/82'
git switch 'main'
git merge --squash 'upstream-pr/82'
git switch 'main'
git merge --ff-only 'upstream-pr/82'
git switch 'main'
git merge 'upstream-pr/82'
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!82
No description provided.