Skip to content

When setting the volume, don't raise an exception if the audio device doesn't support 2 channels.#16771

Merged
seanbudd merged 2 commits into
nvaccess:betafrom
jcsteh:volSingle
Jul 1, 2024
Merged

When setting the volume, don't raise an exception if the audio device doesn't support 2 channels.#16771
seanbudd merged 2 commits into
nvaccess:betafrom
jcsteh:volSingle

Conversation

@jcsteh

@jcsteh jcsteh commented Jun 29, 2024

Copy link
Copy Markdown
Contributor

Link to issue number:

Fixes #16770.

Summary of the issue:

WasapiWavePlayer.setVolume assumes that the audio device supports 2 channels. Some devices do not. This causes an exception when trying to set the second channel.

Description of user facing changes

Playing NVDA sounds no longer fails on a mono audio device.

Description of development approach

Catch E_INVALIDARG which is the documented error code for this situation. Alternatively, we could check the number of channels before trying to set, but I don't think there's any benefit to that approach and that would require more C++ code.

I also removed _wasPlay_errcheck. That was never actually called and was unnecessary because raising an exception for a failure is already handled by setting .restype to HRESULT. Furthermore, _wasPlay_errcheck was raising WindowsError with the wrong parameters, so it wouldn't have been what we wanted even if it had worked.

Testing strategy:

I don't have a device that reproduces this. I changed channel 1 to channel 2 in the code and verified that it doesn't raise an exception.

The original reporter @cary-rowen confirmed that this fixes the problem in #16771 (comment).

Known issues with pull request:

None.

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.

Summary by CodeRabbit

@cary-rowen

Copy link
Copy Markdown
Contributor

Hi @jcsteh
Yes, this fixes the problem I'm having.

Thanks

@jcsteh jcsteh marked this pull request as ready for review June 30, 2024 03:52
@jcsteh jcsteh requested a review from a team as a code owner June 30, 2024 03:52
@jcsteh jcsteh requested a review from seanbudd June 30, 2024 03:52
@coderabbitai

coderabbitai Bot commented Jun 30, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The recent changes to nvwave.py replace the import of S_OK with E_INVALIDARG from comtypes.hresult, remove the _wasPlay_errcheck function, and add exception handling for E_INVALIDARG in the setVolume function to address certain errors. Additionally, documentation in changes.md has been updated to note that NVDA sounds now play correctly on mono audio devices, resolving issue #16770.

Changes

Files Change Summary
source/nvwave.py Replaced S_OK import with E_INVALIDARG, removed _wasPlay_errcheck function, added exception handling for E_INVALIDARG in the setVolume function.
user_docs/en/changes.md Documented that NVDA sounds no longer fail on mono audio devices, addressing issue #16770.

Assessment against linked issues

Objective Addressed Explanation
Handling of WASAPI errors for specific audio output devices.
Confirmation that NVDA sounds play correctly on mono devices.
Ensure no new errors introduced in handling volume.
Removal of redundant or unnecessary functions.
Proper import of necessary constants.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Comment thread user_docs/en/changes.md
@cary-rowen

Copy link
Copy Markdown
Contributor

Hi @jcsteh @seanbudd
Can we target this PR to the Beta branch?

The reasons are as follows:

  1. Currently in the early stage of Beta.
  2. This change is small and unlikely to cause regression.
  3. The sound playback function using nnvwave.playWaveFile in NVDA will be Failed, which covers many features including tones.beep.
  4. Some add-ons call nvwave.playWaveFile before ui.message. If it fails, the speech will fail.
  5. Many Bluetooth headsets have two output modes. In order to obtain lower latency, NVDA users may choose an output mode that does not support dual channels, and this problem is caused.

Thanks

seanbudd
seanbudd previously approved these changes Jul 1, 2024
@seanbudd seanbudd changed the base branch from master to beta July 1, 2024 02:17
@seanbudd seanbudd dismissed their stale review July 1, 2024 02:17

The base branch was changed.

@seanbudd seanbudd added this to the 2024.3 milestone Jul 1, 2024
@seanbudd seanbudd merged commit 86f79e6 into nvaccess:beta Jul 1, 2024
@jcsteh jcsteh deleted the volSingle branch July 25, 2024 07:03
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.

WASAPI error on some audio output devices - execution of nvwave.playWaveFile failed.

3 participants