spatialaudio / python-sounddevice

:sound: Play and Record Sound with Python :snake:
https://python-sounddevice.readthedocs.io/
MIT License
980 stars 145 forks source link

C++ Compiled Application Data Queue Empty? #445

Open msj121 opened 1 year ago

msj121 commented 1 year ago

Hi,

I can run the python code directly no problem from python. C++ compiled code run from Terminal (macos) Unix file also works. I am having some trouble when double clicking the package created by cmake for sounddevice to receive data.

        q = queue.Queue()
        def callback(indata, frames, time, status):
            q.put(bytes(indata))
        if args.samplerate is None:
            device_info = sd.query_devices(args.device, 'input')
            args.samplerate = int(device_info['default_samplerate'])
        with sd.RawInputStream(samplerate=args.samplerate, blocksize = 8000, device=args.device, dtype='int16',
                                    channels=1, callback=callback):
         ....

In c++ code:

    Py_Initialize();
    fp = _Py_wfopen("test.py", L"r");
    PyRun_SimpleFile(fp, "test.py");
    Py_Finalize();

Where test.py is the working python code. Compiled everything runs fine when running the file from terminal but when compiled into a "dragndrop" from cmake it can get the device information (and sample rate) but it gets no data in the "q" variable.

Any ideas what I might be missing?

Thanks!

mgeier commented 1 year ago

I don't really know Python's C API and I wasn't even aware that it allows running a script.

If you provide a complete runnable (but still minimal) example, someone might be able to try this at home and further diagnose the problem.