Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load ASIO driver when using GUI framework #502

Open
my1e5 opened this issue Nov 7, 2023 · 1 comment
Open

Failed to load ASIO driver when using GUI framework #502

my1e5 opened this issue Nov 7, 2023 · 1 comment

Comments

@my1e5
Copy link

my1e5 commented Nov 7, 2023

When I run this minimal example, everything works fine.

import sounddevice as sd
import numpy as np

FS = 44100
sd.default.device = 45  # This is an ASIO device

def run():
    print("Running playrec...")
    sd.playrec(np.zeros((FS, 1)), FS, channels=1)
    print("Done!")

if __name__ == "__main__":
    run()

But when I introduce the DearPyGui framework and try to execute the same function from a callback I get an error.

import numpy as np
import sounddevice as sd
import dearpygui.dearpygui as dpg

FS = 44100
sd.default.device = 45  # This is an ASIO device

def run():
    print("Running playrec...")
    sd.playrec(np.zeros((FS, 1)), FS, channels=1)
    print("Done!")

if __name__ == "__main__":
    dpg.create_context()
    with dpg.window():
        dpg.add_button(label="Run playrec", callback=run)
    dpg.create_viewport()
    dpg.setup_dearpygui()
    dpg.show_viewport()
    dpg.start_dearpygui()
    dpg.destroy_context()
Running playrec...
Traceback (most recent call last):
  File "C:\Users\User\Documents\test.py", line 11, in run
    sd.playrec(np.zeros((FS, 1)), FS, channels=1)
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\sounddevice.py", line 369, in playrec
    ctx.start_stream(Stream, samplerate,
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\sounddevice.py", line 2582, in start_stream
    self.stream = StreamClass(samplerate=samplerate,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\sounddevice.py", line 1800, in __init__
    _StreamBase.__init__(self, kind='duplex', wrap_callback='array',
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\sounddevice.py", line 898, in __init__
    _check(_lib.Pa_OpenStream(self._ptr, iparameters, oparameters,
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\sounddevice.py", line 2745, in _check
    raise PortAudioError(errormsg, err, hosterror_info)
sounddevice.PortAudioError: Error opening Stream: Unanticipated host error [PaErrorCode -9999]: 'Failed to load ASIO driver' [ASIO error 0]

This only happens when I try to use an ASIO device. For example, MME works fine. Does anyone know why this is happening?

Interestingly, if I put the import statement inside the function. It works. But you have to remove the initial import on line 2, if it's there it still breaks.

def run():
    print("Running playrec...")
    import sounddevice as sd
    sd.default.device = 45  # This is an ASIO device
    sd.playrec(np.zeros((FS, 1)), FS, channels=1)
    print("Done!")

Windows 10
sounddevice 0.4.6
Python 3.11.4

@mgeier
Copy link
Member

mgeier commented Dec 2, 2023

See #442.

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

No branches or pull requests

2 participants