Skip to content

hle: synthesize text and SSML with installed Windows voices - #35

Merged
simnJS merged 2 commits into
MiamiGame:mainfrom
AliceWood:hle/host-speech-synthesis
Nov 24, 2026
Merged

simnJS merged 2 commits into
MiamiGame:mainfrom
AliceWood:hle/host-speech-synthesis

Conversation

@AliceWood

@AliceWood AliceWood commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Fixes #7. The accessibility provider used to return a 44-byte empty WAVE for every narration request. It now enumerates installed Windows voices, lets the caller select one or restore the default, and renders plain text and SSML to 48 kHz, 16-bit mono PCM in memory. Each stream owns its audio until the caller closes it.

The review follow-up (c9ae4cf) returns the original 44-byte, 16 kHz silent WAVE for blank text, unavailable voices, or a failed speech engine or transcoder. Host failures produce a warning. Malformed SSML retains its format error. XTP replaces SSML audio references with their fallback text and markup before calling the synthesizer, so the host never receives the audio source. This uses the Windows XML DOM with external resolution disabled.

Depends on: none.

Area

xtp-hle speech provider and tests, the README, and the R6 status in docs/analysis/hle.md.

Tests

I compared upstream eeb1f03, the original PR 22c9206, and the follow-up c9ae4cf on the same Windows host, using debug builds and synthetic inputs. The probe requested “test” as both plain text and an SSML sentence, then read the WAVE through the provider's stream API.

Input Upstream audio payload This change
Plain text 0 bytes at 16 kHz 138,716 bytes at 48 kHz
SSML 0 bytes at 16 kHz 138,716 bytes at 48 kHz
  • With XTP_REQUIRE=no-voice, all nine tests selected by cargo test --locked -p xtp-hle modules::speech:: passed on the follow-up. They exercise an installed Windows voice, the WAVE fields, nested SSML audio fallback, malformed markup, a null stream handle, and a speech engine closed between requests.

  • Empty and whitespace-only plain text returned 0x8000FFFF on 22c9206. On c9ae4cf both return S_OK and the 44-byte empty WAVE. Malformed SSML returned 0x80131537 on both revisions.

  • On c9ae4cf, cargo xtask pr-check --base origin/main passed formatting, both Clippy configurations, asset policy, and commit conventions. Workspace testing stopped in the GPU crate. Eight failing tests matched the upstream run at eeb1f03. A ninth, watch::tests::written_pages_are_reported_to_every_asker, failed once on the follow-up and then passed in the full GPU suite and in isolation on both builds.

  • cargo test --locked -p xtp-hle had 169 passed, 1 failed, and 2 ignored in the follow-up's unit tests. Upstream had 166 passed, 1 failed, and 2 ignored. In both, modules::xmem::tests::title_calls_succeed_under_open_heaps failed at the same assertion.

  • cargo xtask pr-check passes on my machine

  • New or changed behaviour has tests that need no game files, or I explain below why it cannot

  • Ran on a title: no. The comparison used synthetic input.

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

AI assistance: Codex wrote the implementation, tests, and documentation and ran the comparisons. I reviewed and approved commit 22c9206 before opening the PR. Codex implemented and tested the follow-up in c9ae4cf.

For the follow-up, Codex consulted the maintainer review, the Windows bindings for XML and speech, the public stream-data reference, and W3C's description of fallback content. Stream-data errors · SSML audio semantics

Codex consulted XTP's existing provider and analysis notes, the installed windows crate bindings, and Microsoft's public API references for the voice callback, voice metadata, speech synthesis, and stream transcoding. Its information about xcl came from the XTP issue and analysis notes. A search excerpt identified a Windows speech error during testing. No implementation code was taken from those sources. Voice callback · Voice information · Windows voice selection · Stream transcoding

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>. The PR totals 459 changed lines excluding Cargo.lock. The review follow-up adds host-failure handling, offline SSML audio fallback, and regression coverage for both in the speech provider.
  • Docs updated where behaviour, commands or variables changed (README, docs/)

@github-actions github-actions Bot added the overlap another open PR changes the same files label Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Other open pull requests change the same files. Check that they do not do the same work, and agree with their authors on which lands first: the other one will then need a rebase.

Pull request Files changed by both
#26 README.md, docs/analysis/hle.md

This comment is kept up to date automatically and removed when the overlap ends.

@github-actions github-actions Bot added area/hle touches crates/xtp-hle area/docs docs/, Markdown area/deps Cargo.lock size/M 100 to 399 changed lines labels Nov 24, 2026

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a careful piece of work. I reviewed the diff only (it was not run on a title):

  • the slot layout, voice struct, callback contract and gender mapping match the public GDK reference;
  • handle ownership is clean, and nothing reaches an audio device;
  • the supply chain is clean: only the in-tree xtp-testkit plus windows features, each of which is needed;
  • CI's Windows runner exercised the real voice path;
  • the Codex disclosure and your personal sign-off are fine under CONTRIBUTING.

One change before merge:

  1. Degrade to the empty WAVE on host failures. Today create (speech.rs:80), create_stream (:133) and the transcoder path (narrator.rs:81, :86-89) return an error where the title used to get S_OK and the empty WAVE. That could happen on a host with a voice but no working Media Foundation (N editions, Server). Since the title path is untested, please log a warning and fall back to Synthesizer::Silent / SILENCE. Keeping the SSML parse error is fine. Please also short-circuit empty or whitespace-only text to the empty WAVE, and add a test for "".

Smaller points, take or leave:

  1. Mark R6 done in docs/analysis/hle.md (line 177 and the R6 section), as #23 did for R7.
  2. In the WAVE test, also assert format tag 1 (PCM), the byte rate and the block align. Or rewrite the output into a canonical 44-byte header, so that we don't depend on Media Foundation's WAV writer layout.
  3. Consider making SILENCE 48 kHz, so that both paths report one format.
  4. The docs give HRESULT_FROM_WIN32(ERROR_NOT_FOUND) for an invalid stream handle; we return E_INVALIDARG for null. Minor.
  5. Could you check whether the Windows engine fetches external <audio src> in SSML? If it does, we should strip it, since XTP is offline by design.
  6. FYI: #26 edits the same README "Runtime services" row, so whichever lands second needs a quick re-merge of that line.

@github-actions github-actions Bot added size/L 400 to 999 changed lines and removed size/M 100 to 399 changed lines labels Nov 24, 2026
@AliceWood
AliceWood requested a review from simnJS November 24, 2026 21:39

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AliceWood, all addressed:

  • host failures and blank text fall back to the empty WAVE;
  • the not-found HRESULT;
  • full PCM assertions;
  • SSML <audio> elements are reduced to their fallback content before synthesis, so nothing is fetched;
  • R6 marked done.

CI is green. Merging.

@simnJS
simnJS merged commit a5b6f61 into MiamiGame:main Nov 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/deps Cargo.lock area/docs docs/, Markdown area/hle touches crates/xtp-hle overlap another open PR changes the same files size/L 400 to 999 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Speech synthesis through the host: narration speaks

2 participants