Skip to content

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

Open
permadiego wants to merge 1 commit into
Marvisak:mainfrom
permadiego:hle/speech-synthesis
Open

permadiego wants to merge 1 commit into
Marvisak:mainfrom
permadiego:hle/speech-synthesis

Conversation

@permadiego

Copy link
Copy Markdown

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

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 <noreply@anthropic.com>
@DaviTostes

Copy link
Copy Markdown

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 net: only_loopback_is_reachable test panics on Windows 10 (WinHttpGetProxySettingsEx missing) #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.

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
… synthesizer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Exorion1er

Copy link
Copy Markdown
Contributor

#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

Copy link
Copy Markdown

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.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026

Copy link
Copy Markdown
Owner

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

Vaximous pushed a commit to Vaximous/VIctory that referenced this pull request Nov 25, 2026
…are on the card before the character bake; one host copy per placed texture

- The depth bounds test (Marvisak#82 by Kaivyyy, as is): a pipeline that enables
  it is made from a DEPTH_STENCIL1 stream under its own library name, and
  the title's OMSetDepthBounds reaches the host list. Before, such draws
  passed at every depth. On the test machine (RTX 4070) the first room is
  lit by its lamp for the first time: walls, table, bunks.
- Defaults: what shaders wrote is copied back by a thread of its own
  (stage 2), wide copy-back, card copies from 1 MiB up to 1,024 MB, and
  256 lists in the air. About 230 ms a frame where it was about 400.
  Off: VICTORY_RELAY=0, VICTORY_WIDE_BACK=0, VICTORY_CARD_BUFFERS_MIN_MB=16
  VICTORY_CARD_BUFFERS_MB=512, VICTORY_LATE_WAIT_LISTS=128.
- Textures picked by index are uploaded while loading and before a draw of
  the title's decoration bake, which samples them by index and runs once
  (VICTORY_EARLY_TEXTURES_MS, VICTORY_BAKE_TEXTURES_MS; 0 turns each off).
- Placed textures are keyed without the filler words of their description:
  two views that differed only there each had a host copy
  (VICTORY_PLACED_FILLER=1 keeps the old key).
- VICTORY_TEXTURE_ROOM_PERCENT (90, unchanged) sets how full the card may
  get before textures picked by index wait.

Known: the first room's walls are still missing in some launches, and
shaded areas are too dark (the bounce light has no ray-tracing structure
to trace yet).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
arnoudstorm pushed a commit to arnoudstorm/VIctory that referenced this pull request Nov 25, 2026
…are on the card before the character bake; one host copy per placed texture

- The depth bounds test (Marvisak#82 by Kaivyyy, as is): a pipeline that enables
  it is made from a DEPTH_STENCIL1 stream under its own library name, and
  the title's OMSetDepthBounds reaches the host list. Before, such draws
  passed at every depth. On the test machine (RTX 4070) the first room is
  lit by its lamp for the first time: walls, table, bunks.
- Defaults: what shaders wrote is copied back by a thread of its own
  (stage 2), wide copy-back, card copies from 1 MiB up to 1,024 MB, and
  256 lists in the air. About 230 ms a frame where it was about 400.
  Off: VICTORY_RELAY=0, VICTORY_WIDE_BACK=0, VICTORY_CARD_BUFFERS_MIN_MB=16
  VICTORY_CARD_BUFFERS_MB=512, VICTORY_LATE_WAIT_LISTS=128.
- Textures picked by index are uploaded while loading and before a draw of
  the title's decoration bake, which samples them by index and runs once
  (VICTORY_EARLY_TEXTURES_MS, VICTORY_BAKE_TEXTURES_MS; 0 turns each off).
- Placed textures are keyed without the filler words of their description:
  two views that differed only there each had a host copy
  (VICTORY_PLACED_FILLER=1 keeps the old key).
- VICTORY_TEXTURE_ROOM_PERCENT (90, unchanged) sets how full the card may
  get before textures picked by index wait.

Known: the first room's walls are still missing in some launches, and
shaded areas are too dark (the bounce light has no ray-tracing structure
to trace yet).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PastiiJay pushed a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
…are on the card before the character bake; one host copy per placed texture

- The depth bounds test (Marvisak#82 by Kaivyyy, as is): a pipeline that enables
  it is made from a DEPTH_STENCIL1 stream under its own library name, and
  the title's OMSetDepthBounds reaches the host list. Before, such draws
  passed at every depth. On the test machine (RTX 4070) the first room is
  lit by its lamp for the first time: walls, table, bunks.
- Defaults: what shaders wrote is copied back by a thread of its own
  (stage 2), wide copy-back, card copies from 1 MiB up to 1,024 MB, and
  256 lists in the air. About 230 ms a frame where it was about 400.
  Off: VICTORY_RELAY=0, VICTORY_WIDE_BACK=0, VICTORY_CARD_BUFFERS_MIN_MB=16
  VICTORY_CARD_BUFFERS_MB=512, VICTORY_LATE_WAIT_LISTS=128.
- Textures picked by index are uploaded while loading and before a draw of
  the title's decoration bake, which samples them by index and runs once
  (VICTORY_EARLY_TEXTURES_MS, VICTORY_BAKE_TEXTURES_MS; 0 turns each off).
- Placed textures are keyed without the filler words of their description:
  two views that differed only there each had a host copy
  (VICTORY_PLACED_FILLER=1 keeps the old key).
- VICTORY_TEXTURE_ROOM_PERCENT (90, unchanged) sets how full the card may
  get before textures picked by index wait.

Known: the first room's walls are still missing in some launches, and
shaded areas are too dark (the bounce light has no ray-tracing structure
to trace yet).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants