Speech: the title's narration plays through the host's SAPI voice #1822

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

@⁠kais7654 on GitHub · 2026-11-24 23:01 UTC · original
kais7654:speech/sapi → main · +303 −33 · 3 files · 1 commits · open

The accessibility module handed back 44 bytes of silence for every stream, so narration was silent even on a machine with voices. A view of SAPI through the COM bindings this crate already carries renders the line the title sends (SSML as sent, plain text as a fallback) into an HGlobal-backed stream at the 16 kHz mono 16-bit format the console uses, and the WAV goes to the title through the same vtable as before. A machine with no voice, no SAPI, or a line the engine refuses, still gets the silence it got. Stream handles are registry slots encoded into odd pointer values, so no handle the title passes back is ever dereferenced as memory. Test-only, 4 tests.

Generated by Mistral Vibe.

**@⁠kais7654** on GitHub · 2026-11-24 23:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1822) `kais7654:speech/sapi` → `main` · +303 −33 · 3 files · 1 commits · open The accessibility module handed back 44 bytes of silence for every stream, so narration was silent even on a machine with voices. A view of SAPI through the COM bindings this crate already carries renders the line the title sends (SSML as sent, plain text as a fallback) into an HGlobal-backed stream at the 16 kHz mono 16-bit format the console uses, and the WAV goes to the title through the same vtable as before. A machine with no voice, no SAPI, or a line the engine refuses, still gets the silence it got. Stream handles are registry slots encoded into odd pointer values, so no handle the title passes back is ever dereferenced as memory. Test-only, 4 tests. Generated by Mistral Vibe.
The accessibility module handed back 44 bytes of silence for every
stream, so narration was silent even on a machine with voices. A view
of SAPI through the COM bindings this crate already carries renders the
line the title sends (SSML as sent, plain text as a fallback) into an
HGlobal-backed stream at the 16 kHz mono 16-bit format the console uses,
and the WAV goes to the title through the same vtable as before. A
machine with no voice, no SAPI, or a line the engine refuses, still
gets the silence it got. Stream handles are registry slots encoded into
odd pointer values, so no handle the title passes back is ever
dereferenced as memory. Test-only, 4 tests.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:45:41 +00:00
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-24 23:06 UTC · original

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

**@⁠DesertGamer** on GitHub · 2026-11-24 23:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1822#issuecomment-7147029071) ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
Author
Owner

@⁠kais7654 on GitHub · 2026-11-24 23:16 UTC · original

SAPI integration looks right for the happy path. Two questions:

  1. What happens when no SAPI voice is installed (server editions, some stripped Windows)? A fallback to silence would prevent a crash.
  2. The 16 kHz mono format — does the title expect a specific sample rate, or does it resample?

@⁠ruipedro-pinheiro Good questions — both are covered, here's where:

No SAPI voice installed: the fallback to silence is already the PR's behavior, not a crash path. synthesize() returns None on every failure: CoInitializeEx failing (other than RPC_E_CHANGED_MODE), CoCreateInstance failing (which is what happens on server editions or stripped Windows with no SAPI/voice), Speak failing, GlobalLock returning null — every error path returns early with None, no panic, no unwinding through COM. stream_audio maps that None to the same 44-byte silence WAV the module handed back before this change, and the title gets a valid stream either way (stream size/data still answer from the WAV bytes). So a machine with no voice behaves exactly as main does today.

16 kHz mono: it's the format the title already receives — the pre-existing SILENCE constant on main is a 16 kHz mono 16-bit WAV (RIFF fmt: PCM, 1 channel, 16,000 Hz), so the streams we hand back keep the format the playback side already parses. The title reads a complete WAV file through the same vtable methods as before; if it resamples or request another rate, that logic is unchanged and outside this diff. SAPI writes into the WAV we format because SetBaseStream pins the WAVEFORMATEX before Speak, so the bytes are always 16 kHz PCM regardless of the voice's native rate.

**@⁠kais7654** on GitHub · 2026-11-24 23:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1822#issuecomment-7147205939) > SAPI integration looks right for the happy path. Two questions: > > 1. What happens when no SAPI voice is installed (server editions, some stripped Windows)? A fallback to silence would prevent a crash. > 2. The 16 kHz mono format — does the title expect a specific sample rate, or does it resample? @⁠ruipedro-pinheiro Good questions — both are covered, here's where: No SAPI voice installed: the fallback to silence is already the PR's behavior, not a crash path. synthesize() returns None on every failure: CoInitializeEx failing (other than RPC_E_CHANGED_MODE), CoCreateInstance failing (which is what happens on server editions or stripped Windows with no SAPI/voice), Speak failing, GlobalLock returning null — every error path returns early with None, no panic, no unwinding through COM. stream_audio maps that None to the same 44-byte silence WAV the module handed back before this change, and the title gets a valid stream either way (stream size/data still answer from the WAV bytes). So a machine with no voice behaves exactly as main does today. 16 kHz mono: it's the format the title already receives — the pre-existing SILENCE constant on main is a 16 kHz mono 16-bit WAV (RIFF fmt: PCM, 1 channel, 16,000 Hz), so the streams we hand back keep the format the playback side already parses. The title reads a complete WAV file through the same vtable methods as before; if it resamples or request another rate, that logic is unchanged and outside this diff. SAPI writes into the WAV we format because SetBaseStream pins the WAVEFORMATEX before Speak, so the bytes are always 16 kHz PCM regardless of the voice's native rate.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:29 UTC · original

Automated triage for the maintainers.

Needs work. crates/victory-hle/src/modules/speech.rs now synthesizes the title's narration with the host's SAPI voice (sapi::synthesize, in-process COM, no network). It hands the WAVE bytes back through stream_size/the copy slot, with silence as the fallback. The new Cargo lines are only feature flags of windows, which is already a dependency. The direction is sensible. One blocking issue:

  • Every stream is kept forever. stream_handle pushes each synthesized WAVE into the global STREAMS vector, and nothing ever removes one: close is still a no-op. A narrated menu creates a stream per spoken line, so a long session keeps growing, at about 32 KB per second of speech. Free the entry when the title closes or releases the stream. A handle that is an index into a vector that never shrinks would also need a free list, or a map keyed by a counter.

Smaller:

  • stream_bytes clones the whole WAVE on every size query and every copy. Returning a length, or copying under the lock, avoids that.
  • spoken strips SSML tags to plain text, which is fine as a first step. Say so in the module docs, which still describe narration as silent.

CI: no check runs on the head commit.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1822#issuecomment-7154852185) <!-- victory-triage v1 head=5942e74b8ce4f108796500b4fac315bd01ec5155 verdict=needs-work at=2026-11-25T06:33:00Z --> Automated triage for the maintainers. **Needs work.** `crates/victory-hle/src/modules/speech.rs` now synthesizes the title's narration with the host's SAPI voice (`sapi::synthesize`, in-process COM, no network). It hands the WAVE bytes back through `stream_size`/the copy slot, with silence as the fallback. The new Cargo lines are only feature flags of `windows`, which is already a dependency. The direction is sensible. One blocking issue: - **Every stream is kept forever.** `stream_handle` pushes each synthesized WAVE into the global `STREAMS` vector, and nothing ever removes one: `close` is still a no-op. A narrated menu creates a stream per spoken line, so a long session keeps growing, at about 32 KB per second of speech. Free the entry when the title closes or releases the stream. A handle that is an index into a vector that never shrinks would also need a free list, or a map keyed by a counter. Smaller: - `stream_bytes` clones the whole WAVE on every size query and every copy. Returning a length, or copying under the lock, avoids that. - `spoken` strips SSML tags to plain text, which is fine as a first step. Say so in the module docs, which still describe narration as silent. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/1822/head:github-bot/gh-1822'
git switch 'github-bot/gh-1822'

Merge

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