question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Runtime error when attempting to initialize player in "exclusive_mode"

See original GitHub issue

Hi,

I am attempting to generate real-time audio with low latency on a Windows 10 system with python 3.7. If I try to set the exclusive_mode argument to speaker.player() to True, mediafoundation.py throws an error at line 92: RuntimeError: invalid argument

Here is a snippet of code that generates the error for me:

speaker = soundcard.default_speaker()
with speaker.player(samplerate=48000, blocksize=1200, exclusive_mode=True) as audioplayer:
    pass

The values of samplerate and blocksize (and channels, which I left as default) do not seem to matter here, the error always happens when I set exclusive_mode=True.

Here is the full error when I run the above snippet in an interactive session:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python\Anaconda3\lib\site-packages\soundcard\mediafoundation.py", line 435, in player
    return _Player(self._audio_client(), samplerate, channels, blocksize, False, exclusive_mode)
  File "C:\Python\Anaconda3\lib\site-packages\soundcard\mediafoundation.py", line 542, in __init__
    _com.check_error(hr)
  File "C:\Python\Anaconda3\lib\site-packages\soundcard\mediafoundation.py", line 92, in check_error
    raise RuntimeError("invalid argument")
RuntimeError: invalid argument

My PC has Realtek audio:

>>> print(speaker)
<Speaker Speakers (Realtek(R) Audio) (2 channels)>

Thanks! Overall this library seems very helpful and a bit easier to use than pyaudio.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bastibecommented, Apr 12, 2022

You can create the pull request at any time if you want to ask for help, just mark is as work-in-progress. I’m afraid I can’t help much at the moment, sorry.

1reaction
bastibecommented, Apr 7, 2022

Brilliant! Thank you for investigating this!

So we might be restricted to a pre-set sample rate if we open a device in exclusive mode. Or perhaps we have to change the device’s sample rate, as opposed to the AudioClient’s.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[FIXED] 'DirectX Failed to Initialize. Please Install the Correct ...
1. How to Fix the “DirectX Failed to Initialize” Error. 2. Update DirectX. 3. Upgrade the DirectX Suite.
Read more >
C++ Runtime Error For Windows Media Player 12
Everytime I play a show or music using Windows Media Player, it works fine til the end of the show/song. Then when it...
Read more >
[Bug] Cannot launch the game in 'exclusive' mode :: Brigand
But upon trying this I get either nothing and the game doesn't launch at all or I get this error : "Runtime Error...
Read more >
Error (51) FMOD_ERR_OUTPUT_INIT, no default playback ...
FMOD_ERR_OUTPUT_INIT is more like a device failed to init. We are seeing this a bit more lately and is most likely USB headset...
Read more >
Citrix Fixes and Known Issues – XenApp & XenDesktop ...
Windows Media Player throws an error "An error occured while playing the file" when attempting to play mp4 videos or "Windows Media Player...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found