Skip to content

Fix SAPI5 WASAPI audio#18658

Merged
seanbudd merged 6 commits intonvaccess:masterfrom
gexgd0419:fix-sapi5
Aug 11, 2025
Merged

Fix SAPI5 WASAPI audio#18658
seanbudd merged 6 commits intonvaccess:masterfrom
gexgd0419:fix-sapi5

Conversation

@gexgd0419
Copy link
Copy Markdown
Contributor

@gexgd0419 gexgd0419 commented Aug 9, 2025

Link to issue number:

Fixes #17967.

Summary of the issue:

When rate boost is enabled and the rate is fast enough, if some audio takes longer time to process, an audio gap might appear in the speech audio.

Description of user facing changes:

The audio gap issue should be fixed.

Description of developer facing changes:

None.

Description of development approach:

Wait for at least 50ms of audio data before sending the first chunk to the output device.

This mitigates the problem when the first small chunk is immediately played, but during processing of the next chunk, there isn't enough audio to cover this duration, leaving audible gaps.

Also the return value of IStream::Write is changed to S_OK instead of an error code during cancellation.

Testing strategy:

Tested with VW Julie with the text "i unselected" to confirm there's no gap in the audio.

Known issues with pull request:

This might slightly increase the speech delay since audio won't be immediately played.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@coderabbitai summary

@gexgd0419 gexgd0419 marked this pull request as ready for review August 10, 2025 04:04
@gexgd0419 gexgd0419 requested a review from a team as a code owner August 10, 2025 04:04
@gexgd0419 gexgd0419 requested a review from SaschaCowley August 10, 2025 04:04
@seanbudd
Copy link
Copy Markdown
Member

Thanks @gexgd0419 !

It seems all known issues with the changes to SAPI4 and SAPI5 are solved now? Much appreciated

@seanbudd seanbudd enabled auto-merge (squash) August 11, 2025 03:04
@seanbudd seanbudd merged commit 1435e58 into nvaccess:master Aug 11, 2025
30 checks passed
@gexgd0419 gexgd0419 deleted the fix-sapi5 branch August 12, 2025 02:49
@gexgd0419 gexgd0419 mentioned this pull request Aug 12, 2025
5 tasks
@SaschaCowley SaschaCowley added this to the 2025.3 milestone Aug 18, 2025
seanbudd pushed a commit that referenced this pull request Aug 22, 2025
Fixes #18674. Fixes #18676. Fixes #18760.
Summary of the issue:

NVDA becomes unresponsive for a small period of time when speaking some text in SAPI5 voices.

#18658 leaves more audio data for the EndStream handler to be played, which causes NVDA to be frozen when the EndStream handler is feeding the remaining audio chunks.
Description of user facing changes:

The above issue should be fixed.
Description of developer facing changes:

None
Description of development approach:

Moves the feeding logic in EndStream to the dedicated speak thread, avoiding blocking the SAPI5 thread that EndStream runs on.

The main thread no longer waits for cancellation to complete in order to prevent freezing.

The dedicated speak thread for WASAPI will be stopped and restarted when WASAPI is turned on or off, in order to prevent errors accessing the player when WASAPI is turned off and the player no longer exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sapi 5 performance issues in nvda 2025 beta

3 participants