Speech synthesis via Windows.Media.SpeechSynthesis — would you take it? #825

Closed
opened 2026-11-26 04:14:01 +00:00 by github-bot · 4 comments
Owner

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

speech.rs returns an empty WAVE stream for every request, so the title's accessibility narration is silent. I'd like to implement it with the host's WinRT synthesizer, which already returns a WAVE stream and accepts both plain text (slot 0x68) and SSML (slot 0xa8).

Plan:

  • create_stream synthesizes with SpeechSynthesizer::SynthesizeTextToStreamAsync / SynthesizeSsmlToStreamAsync and keeps the bytes in a per-stream buffer; stream_size / stream_data serve them; closing frees them.
  • Synthesis runs on a dedicated thread of ours, so no COM/WinRT apartment is initialized on the title's threads.
  • Any failure (no voices installed, bad SSML) falls back to today's silent stream, so nothing that works now can break.
  • Tests: synthesize "Hello" and check the stream is valid WAVE with samples; an #[ignore] test writes the WAV out to listen to.

Questions before I start:

  1. Is adding windows (features Media_SpeechSynthesis, Storage_Streams, Foundation) as a non-optional Windows dependency of victory-hle acceptable, or would you prefer it behind a feature?
  2. The silent stream is 16 kHz mono 16-bit. Does the title rely on that format, or does it read the header? If it matters I can resample to 16 kHz.
  3. Should enumerate_voices start reporting the host's voices, or stay empty for now (default voice only)? I don't know the callback's signature yet.

I can't run the title (no console), so I can test synthesis on Windows 11 / RTX 5060 Ti but not the in-game narration; that part would need a check on your side.

**@⁠gabrielvbraga** on GitHub · 2026-11-24 11:41 UTC · [original](https://github.com/Marvisak/VIctory/issues/825) `speech.rs` returns an empty WAVE stream for every request, so the title's accessibility narration is silent. I'd like to implement it with the host's WinRT synthesizer, which already returns a WAVE stream and accepts both plain text (slot 0x68) and SSML (slot 0xa8). Plan: - `create_stream` synthesizes with `SpeechSynthesizer::SynthesizeTextToStreamAsync` / `SynthesizeSsmlToStreamAsync` and keeps the bytes in a per-stream buffer; `stream_size` / `stream_data` serve them; closing frees them. - Synthesis runs on a dedicated thread of ours, so no COM/WinRT apartment is initialized on the title's threads. - Any failure (no voices installed, bad SSML) falls back to today's silent stream, so nothing that works now can break. - Tests: synthesize "Hello" and check the stream is valid WAVE with samples; an `#[ignore]` test writes the WAV out to listen to. Questions before I start: 1. Is adding `windows` (features `Media_SpeechSynthesis`, `Storage_Streams`, `Foundation`) as a non-optional Windows dependency of victory-hle acceptable, or would you prefer it behind a feature? 2. The silent stream is 16 kHz mono 16-bit. Does the title rely on that format, or does it read the header? If it matters I can resample to 16 kHz. 3. Should `enumerate_voices` start reporting the host's voices, or stay empty for now (default voice only)? I don't know the callback's signature yet. I can't run the title (no console), so I can test synthesis on Windows 11 / RTX 5060 Ti but not the in-game narration; that part would need a check on your side.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:01 +00:00
Author
Owner

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

Quick prototype results (standalone program, nothing in the repo yet), Windows 11, windows 0.62.2:

  • SynthesizeTextToStreamAsync and SynthesizeSsmlToStreamAsync both return valid RIFF/WAVE streams.
  • Format with the voices installed here (Microsoft Maria and Daniel, pt-BR): 16,000 Hz, mono, 16-bit, the same as today's silent stream, so on this machine no resampling is needed (question 2).
  • Features needed: Foundation, Foundation_Collections, Media_Core, Media_SpeechSynthesis, Storage_Streams (the stream type and the synthesize methods are gated behind Media_Core).
  • With no voice for the requested language installed, the default voice reads it anyway (an English line read by a pt-BR voice), so voice selection by language (set_custom_voice / enumerate_voices) will matter for players whose system voices don't match the title's language.
**@⁠gabrielvbraga** on GitHub · 2026-11-24 11:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/825#issuecomment-7130639737) Quick prototype results (standalone program, nothing in the repo yet), Windows 11, `windows` 0.62.2: - `SynthesizeTextToStreamAsync` and `SynthesizeSsmlToStreamAsync` both return valid RIFF/WAVE streams. - Format with the voices installed here (Microsoft Maria and Daniel, pt-BR): 16,000 Hz, mono, 16-bit, the same as today's silent stream, so on this machine no resampling is needed (question 2). - Features needed: `Foundation`, `Foundation_Collections`, `Media_Core`, `Media_SpeechSynthesis`, `Storage_Streams` (the stream type and the synthesize methods are gated behind `Media_Core`). - With no voice for the requested language installed, the default voice reads it anyway (an English line read by a pt-BR voice), so voice selection by language (`set_custom_voice` / `enumerate_voices`) will matter for players whose system voices don't match the title's language.
Author
Owner

@⁠gabrielvbraga on GitHub · 2026-11-24 12:08 UTC · original

Implementation ready, but pull requests are limited to collaborators, so I couldn't open one. It's a single commit on my fork: https://github.com/gabrielvbraga/VIctory/tree/speech-synthesis (185bd7b)

To bring it in:
git fetch https://github.com/gabrielvbraga/VIctory speech-synthesis
git cherry-pick 185bd7b

What it does:

  • Lines are synthesized by Windows.Media.SpeechSynthesis from plain text (slot 0x68) and SSML (slot 0xa8), on a dedicated "victory speech" thread; COM is initialized there only, never on the title's threads. Title threads wait at most 10 s per line.
  • Any failure (no voice installed, SSML the host refuses, timeout) falls back to the silent stream, so nothing that worked before can break.
  • Streams have their own handles and audio, freed on close; a handle that isn't open reads as silence, so a double close is harmless.
  • victory-hle's windows dependency is now non-optional with Foundation, Media_Core, Media_SpeechSynthesis and Storage_Streams added (question 1); I can move speech behind a feature instead if you prefer.
  • Not done (shortcut noted in the file): the default voice speaks every line; enumerate_voices still reports none.

Tested on Windows 11: both clippy runs from CI (with and without --all-features) and cargo test --workspace pass; the ignored test lines_are_spoken writes a text line and an SSML line to the temp folder and both play correctly. In-game narration still needs a check on your side, since I can't run the title.

If you'd rather receive it another way (patch file, or collaborator access for a PR), just say.

**@⁠gabrielvbraga** on GitHub · 2026-11-24 12:08 UTC · [original](https://github.com/Marvisak/VIctory/issues/825#issuecomment-7131026612) Implementation ready, but pull requests are limited to collaborators, so I couldn't open one. It's a single commit on my fork: https://github.com/gabrielvbraga/VIctory/tree/speech-synthesis (185bd7b) To bring it in: git fetch https://github.com/gabrielvbraga/VIctory speech-synthesis git cherry-pick 185bd7b What it does: - Lines are synthesized by `Windows.Media.SpeechSynthesis` from plain text (slot 0x68) and SSML (slot 0xa8), on a dedicated "victory speech" thread; COM is initialized there only, never on the title's threads. Title threads wait at most 10 s per line. - Any failure (no voice installed, SSML the host refuses, timeout) falls back to the silent stream, so nothing that worked before can break. - Streams have their own handles and audio, freed on close; a handle that isn't open reads as silence, so a double close is harmless. - victory-hle's `windows` dependency is now non-optional with `Foundation`, `Media_Core`, `Media_SpeechSynthesis` and `Storage_Streams` added (question 1); I can move speech behind a feature instead if you prefer. - Not done (shortcut noted in the file): the default voice speaks every line; `enumerate_voices` still reports none. Tested on Windows 11: both clippy runs from CI (with and without `--all-features`) and `cargo test --workspace` pass; the ignored test `lines_are_spoken` writes a text line and an SSML line to the temp folder and both play correctly. In-game narration still needs a check on your side, since I can't run the title. If you'd rather receive it another way (patch file, or collaborator access for a PR), just say.
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-24 13:21 UTC · original

Heads up: there are already two open PRs for the same thing. #82 (permadiego, "speak the title's narration with the host's speech synthesizer") and #691 (arthercz, "speak accessibility narration through the host's WinRT synthesizer"). Your plan and prototype (text slot 0x68, SSML slot 0xa8, per-stream buffer) look very close to #691. It would help to say on #691 or #82 what your branch does differently, if anything, and to post your Windows 11 test there, rather than add a third version.

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 13:21 UTC · [original](https://github.com/Marvisak/VIctory/issues/825#issuecomment-7132711231) Heads up: there are already two open PRs for the same thing. #82 (permadiego, "speak the title's narration with the host's speech synthesizer") and #691 (arthercz, "speak accessibility narration through the host's WinRT synthesizer"). Your plan and prototype (text slot 0x68, SSML slot 0xa8, per-stream buffer) look very close to #691. It would help to say on #691 or #82 what your branch does differently, if anything, and to post your Windows 11 test there, rather than add a third version.
Author
Owner

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

Thanks for the pointer, I missed those. #82 covers this and more (resampling, SSML fallback), so I've tested it here and posted the results there, along with two small differences from my branch (a timeout on synthesis and safe handling of repeated or unknown stream handles). Closing this in favour of #82.

**@⁠gabrielvbraga** on GitHub · 2026-11-24 13:47 UTC · [original](https://github.com/Marvisak/VIctory/issues/825#issuecomment-7133353580) Thanks for the pointer, I missed those. #82 covers this and more (resampling, SSML fallback), so I've tested it here and posted the results there, along with two small differences from my branch (a timeout on synthesis and safe handling of repeated or unknown stream handles). Closing this in favour of #82.
This discussion has been locked. Commenting is limited to contributors.
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#825
No description provided.