Skip to content

support audio ducking for SAPI5 on Windows 11#13118

Merged
michaelDCurran merged 8 commits into
masterfrom
i12913
Jan 12, 2022
Merged

support audio ducking for SAPI5 on Windows 11#13118
michaelDCurran merged 8 commits into
masterfrom
i12913

Conversation

@michaelDCurran

Copy link
Copy Markdown
Member

Link to issue number:

Fixes #12913

Summary of the issue:

NVDA's SAPI5 synthDriver instructed Windows to duck and unduck background audio via hooked winmm waveOut functions. However, on Windows 11, it seems that these functions are no longer used by SAPI5, and therefore audio ducking no longer worked for SAPI5.

Description of how this pull request fixes the issue:

Rather than hooking winmm functions, instead make use of SAPI5's own events, and other SynthDriver methods to eanble and disable ducking.
Specifically:

  • On SAPISink.StartStream: enable ducking
  • On SAPISink.EndStream: disable ducking
  • SynthDriver.cancel: disable ducking
  • SynthDriver.pause: disable ducking if pausing and enable ducking if unpausing.
  • SynthDriver.speak: temporarily enable audio ducking around the call to speak so that audio ducking can enforce its initial delay before speaking (as StartStream and EndStream are asynchronous).

Testing strategy:

  • Tested SAPI5 synthDriver on Windows 11: Soke some text, ensuring that audio was ducked for the duration of the speech and then unducked. Used NVDA with SAPI5 for an extended period to ensure that rapid speech and key presses did not leave audio ducking in a ducked state.
  • Do above tests on Windows 10 and Windows 7.

Known issues with pull request:

None known.

Change log entries:

New features
Changes
Bug fixes

  • NVDA can again duck audio when using the SAPI5 synthesizer on Windows 11.
    For Developers

Code Review Checklist:

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

…audio ducking as SAPI5 does not use winmm on Windows 11. Rather, enable / disable audio ducking with SAPI's own events.
@michaelDCurran
michaelDCurran requested a review from a team as a code owner December 2, 2021 03:37
@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 73bf543ab4

@michaelDCurran

Copy link
Copy Markdown
Member Author

I would appreciate if someone could please test this try build on Windows 10 and confirm that SAPI5 still correctly ducks audio: https://ci.appveyor.com/api/buildjobs/rrkpf0o0ek08nt74/artifacts/output%2Fnvda_snapshot_try-i12913-24309%2C7157aba3.exe

@LeonarddeR LeonarddeR 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.

Looks good to me code wise.

Is it likely that the dllImportTableHooks functionality in NVDAHelper will be ever used for something else in the future? I assume it was implemented solely for SAPI5?

@cary-rowen

Copy link
Copy Markdown
Contributor

I tested this Try Version with SApi5 of Windows 10 21H2 (x64) build 19044.1387, and it seems that the ducking audio function is good.

@OzancanKaratas OzancanKaratas 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.

The function works correctly.

Platform: Windows 11 (x64)

Comment thread source/synthDrivers/sapi5.py Outdated
Comment on lines +343 to +352
# Although background audio is ducked in SAPISink.StartStream
# and unducks in SAPISink.EndStream,
# those events are asynchronous and therefor enabling audio ducking
# cannot enforce a delay before the speech stream starts,
# while audio is being faded down.
# Therefore, create a temporary AudioDucker object,
# and enable and disable it directly around the call to speak,
# So that enabling audio ducking suitably delays the speak call if necessary.
# Although speak does not block and audio ducking is disabled straight after,
# Audio will be still ducked for enough time for the subsequent StartStream to keep it enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than use a tempAudioDucker, why not give speak the responsibility of enabling audio ducking, and StropStream the responsibility of disabling. Why is StartStream needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When calling speak, it is possible that the synthesizer may not produce any audio, for instance if the text is empty or does not result in any pronounceable symbols. In that case, StartStream and EndStream will never be fired. This would be a very rare situation, but certainly not impossible. Really StartStream and EndStream are the true accurate places for controlling ducking. But because they are fired asynchronously, the enforced blocking when calling AudioDucker.enable (when not already ducked) will not block the start of speech, thus why we also need to do it temporarily around speak, to ensure that speak is delayed enough.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does temp audio ducker actually cause the audio to be ducked, or is it only used for timing?

Comment thread source/synthDrivers/sapi5.py Outdated
Comment thread source/synthDrivers/sapi5.py Outdated
michaelDCurran and others added 2 commits January 11, 2022 16:20
Co-authored-by: Reef Turner <[email protected]>
Co-authored-by: Reef Turner <[email protected]>

@feerrenrut feerrenrut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@michaelDCurran
michaelDCurran merged commit 20d5a25 into master Jan 12, 2022
@michaelDCurran
michaelDCurran deleted the i12913 branch January 12, 2022 03:34
@nvaccessAuto nvaccessAuto added this to the 2022.1 milestone Jan 12, 2022
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.

No speech aware audio ducking with NVDA2021.2, Windows11 and SAPI 5

7 participants