python-sounddevice icon indicating copy to clipboard operation
python-sounddevice copied to clipboard

Anaconda: PyAudio install interferes with ASIO recognition

Open DDubbleDD opened this issue 5 years ago • 10 comments

I just wasted a couple of days looking into this issue. It seems that the Pyaudio/Portaudio install interferes with the python-sounddevice query_devices() function for ASIO devices. No matter what I did I could not see my ASIO drivers when performing the python-sounddevice query_device(). Even after I installed python-sounddevice with PIP and verified that it was returning the ASIO enable Portaudio version libportaudio64bit.dll with the get_portaudio_version() function. It wasn't until I removed Pyaudio/Portaudio from my Anaconda install that I could see my ASIO devices.

Q1: Do I have a need for pyaudio if I have python-sounddevice? Q2: Is there a way to make these work together?

Here is my python-sounddevice Python program: Sounddevice_DeviceQuery.py

import sounddevice as sd
print(sd.query_devices())
print(sd.get_portaudio_version())
print(sd.query_hostapis())

from ctypes.util import find_library
print(find_library('portaudio'))
print(find_library('libportaudio64bit'))

Example output BEFORE Removal of Pyaudio/Portaudio

(base) Z:\Projects\Python>C:/Users/****/AppData/Local/Continuum/anaconda3/python.exe Z:/Projects/Python/Sounddevice_DeviceQuery.py
   0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
>  1 Focusrite USB (Focusrite USB Au, MME (8 in, 0 out)
   2 Microphone (HD Webcam C310), MME (1 in, 0 out)
   3 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
<  4 Focusrite USB (Focusrite USB Au, MME (0 in, 8 out)
   5 FrontMic (Realtek HD Audio Front Mic input), Windows WDM-KS (2 in, 0 out)
   6 Stereo Mix (Realtek HD Audio Stereo input), Windows WDM-KS (2 in, 0 out)
   7 Speakers (Realtek HD Audio output), Windows WDM-KS (0 in, 2 out)
   8 Output (), Windows WDM-KS (0 in, 2 out)
   9 Output (), Windows WDM-KS (0 in, 2 out)
  10 Microphone (HD Webcam C310), Windows WDM-KS (1 in, 0 out)
  11 Focusrite USB (fniusbwave_48), Windows WDM-KS (8 in, 0 out)
  12 Analog Out (fniusbwave_48), Windows WDM-KS (0 in, 8 out)
(1246720, 'PortAudio V19.6.0-devel, revision 396fe4b6699ae929d3a685b3ef8a7e97396139a4')
({'name': 'MME', 'devices': [0, 1, 2, 3, 4], 'default_input_device': 1, 'default_output_device': 4}, {'name': 'Windows WDM-KS', 'devices': [5, 6, 7, 8, 9, 10, 11, 12], 'default_input_device': 11, 'default_output_device': 12})
Z:\Users\****\AppData\Local\Continuum\anaconda3\Library\bin\portaudio.dll
None

Example output AFTER Removal of Pyaudio/Portaudio

(base) H:\Projects\Python>Z:/Users/****/AppData/Local/Continuum/anaconda3/python.exe Z:/Projects/Python/Sounddevice_DeviceQuery.py
   0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
>  1 Focusrite USB (Focusrite USB Au, MME (2 in, 0 out)
   2 Microphone (HD Webcam C310), MME (2 in, 0 out)
   3 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
<  4 Focusrite USB (Focusrite USB Au, MME (0 in, 2 out)
   5 Primary Sound Capture Driver, Windows DirectSound (2 in, 0 out)
   6 Focusrite USB (Focusrite USB Audio), Windows DirectSound (2 in, 0 out)
   7 Microphone (HD Webcam C310), Windows DirectSound (2 in, 0 out)
   8 Primary Sound Driver, Windows DirectSound (0 in, 2 out)
   9 Focusrite USB (Focusrite USB Audio), Windows DirectSound (0 in, 2 out)
  10 ASIO4ALL v2, ASIO (2 in, 2 out)
  11 Focusrite USB ASIO, ASIO (6 in, 4 out)
  12 Focusrite USB (Focusrite USB Audio), Windows WASAPI (0 in, 2 out)
  13 Focusrite USB (Focusrite USB Audio), Windows WASAPI (2 in, 0 out)
  14 Microphone (HD Webcam C310), Windows WASAPI (1 in, 0 out)
  15 FrontMic (Realtek HD Audio Front Mic input), Windows WDM-KS (2 in, 0 out)
  16 Stereo Mix (Realtek HD Audio Stereo input), Windows WDM-KS (2 in, 0 out)
  17 Speakers (Realtek HD Audio output), Windows WDM-KS (0 in, 2 out)
  18 Output (), Windows WDM-KS (0 in, 2 out)
  19 Output (), Windows WDM-KS (0 in, 2 out)
  20 Microphone (HD Webcam C310), Windows WDM-KS (1 in, 0 out)
  21 Focusrite USB (fniusbwave_48), Windows WDM-KS (8 in, 0 out)
  22 Analog Out (fniusbwave_48), Windows WDM-KS (0 in, 8 out)
(1246720, 'PortAudio V19.6.0-devel, revision 396fe4b6699ae929d3a685b3ef8a7e97396139a4')
({'name': 'MME', 'devices': [0, 1, 2, 3, 4], 'default_input_device': 1, 'default_output_device': 4}, {'name': 'Windows DirectSound', 'devices': [5, 6, 7, 8, 9], 'default_input_device': 5, 'default_output_device': 8}, {'name': 'ASIO', 'devices': [10, 11], 'default_input_device': 10, 'default_output_device': 10}, {'name': 'Windows WASAPI', 'devices': [12, 13, 14], 'default_input_device': 13, 'default_output_device': 12}, {'name': 'Windows WDM-KS', 'devices': [15, 16, 17, 18, 19, 20, 21, 22], 'default_input_device': 21, 'default_output_device': 22})
None
None

DDubbleDD avatar Mar 11 '20 20:03 DDubbleDD

Q1: Do I have a need for pyaudio if I have python-sounddevice?

No.

But the other way round that's also the case.

Q2: Is there a way to make these work together?

I don't know. Probably.

You should probably try conda-forge instead of the default Anaconda channel.

And for future debugging, you can use this to find out which DLL is used:

import sounddevice as sd
print(sd._libname)

UPDATE: you can also try this:

import sounddevice as sd
print(sd._lib)

mgeier avatar Mar 12 '20 13:03 mgeier

Sorry, I just remembered that ASIO doesn't work on conda-forge either: https://github.com/conda-forge/portaudio-feedstock/issues/9

Anyway, it's probably best to uninstall the conda package portaudio.

mgeier avatar Mar 12 '20 13:03 mgeier

Thank you for the reply. I finally found a way to make both work AND support ASIO. First completely uninstall PyAudio and PortAudio. Then use Pip to install the WHL package from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio. This installs a version of Portaudio that supports ASIO. Now both PyAudio and Sounddevice can query the devices and see my ASIO drivers. I'm using Python 3.7.6 originally installed with Anaconda. This has been really frustrating process. I am still going to advise using the sounddevice package due to the Numpy array usage. For our application, that seems to be very valuable. Now on to figuring out our real application... DSP, multi-channel audio, callback functions, and real-time buffers without missing data.

DDubbleDD avatar Mar 12 '20 18:03 DDubbleDD

So the problem seems to be in the Anaconda ecosystem, see also the issue I mentioned above.

Is there anything we can do on the side of the sounddevice module?

mgeier avatar Apr 22 '20 10:04 mgeier

  1. Talk about ASIO a bit more in the documentation. Mention conflicts if Pyaudio is installed.
  2. Also, edit your first reply on March 12 in this thread. The function in Sounddevice to find the library is: sd._lib NOT sd._libname
  3. Add some troubleshooting steps?

print("sd.get_portaudio_version(): " + str(sd.get_portaudio_version())) print("sd._lib: " + str(sd._lib))

DDubbleDD avatar Apr 22 '20 12:04 DDubbleDD

Talk about ASIO a bit more in the documentation. Mention conflicts if Pyaudio is installed.

Would you mind making a PR for this?

edit your first reply on March 12 in this thread. The function in Sounddevice to find the library is: sd._lib NOT sd._libname

OK, I've updated the comment.

I'm normally more interested in sd._libname, because it tells me the file name that CFFI is trying to load. It looks like sd._lib also has this information in its repr, but I don't know how this looks on other OSs. How does this look on Windows?

Add some troubleshooting steps?

Sure, would you mind making a PR?

It's kinda hard for me to do this because I'm not a Windows user.

mgeier avatar May 01 '20 17:05 mgeier

For info, this is what I see on my Windows box (after removing the conda-installed copy of portaudio):

In [4]: sd._libname
Out[4]: 'C:\\Anaconda3\\lib\\site-packages\\_sounddevice_data\\portaudio-binaries\\libportaudio64bit.dll'

In [5]: sd._lib
Out[5]: <Lib object for 'C:\Anaconda3\lib\site-packages\_sounddevice_data\portaudio-binaries\libportaudio64bit.dll'>

neilser avatar May 24 '20 21:05 neilser

Thanks @neilser, that's good to know.

The path containing _sounddevice_data shows that the pre-packaged library from _sounddevice_data is used.

When installing the library with conda, the path would be different.

mgeier avatar May 25 '20 08:05 mgeier

Screenshot_20200605-193646

Oke54 avatar Jun 06 '20 07:06 Oke54

I just ran into this issue. Is there a reason why the package available on pypi is able to include portaudio compiled with ASIO support built-in, but the conda version cannot? Does this have to do with the fact that the conda-forge feedstock recipe would need to include the SDK as part of the repo to enable the automated builds?

bburan avatar Dec 09 '21 16:12 bburan