bastibe/SoundCard

OSError: ctypes.util.find_library() did not manage to locate a library called 'CoreAudio'

andresmntr opened this issue · 10 comments

Getting this error:

`
OSError: ctypes.util.find_library() did not manage to locate a library called 'CoreAudio'

When trying to import soundcard into my project.
OS: macOS

Any idea on how I can solve that?

What version of macOS and Python are your running?

macOS BigSur Version 11.2.1
python 3.8.5

Seeing the same issue with the same OS version and python 3.8.6:

Traceback (most recent call last):
  File "sound.py", line 1, in <module>
    import soundcard as sc
  File ".venv/lib/python3.8/site-packages/soundcard/__init__.py", line 11, in <module>
    from soundcard.coreaudio import *
  File ".venv/lib/python3.8/site-packages/soundcard/coreaudio.py", line 16, in <module>
    _ca = _ffi.dlopen('CoreAudio')
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: ctypes.util.find_library() did not manage to locate a library called 'CoreAudio'

I have solved it temporarily by following these steps

Seeing the same issue with the same OS version and python 3.8.6:

Traceback (most recent call last):
  File "sound.py", line 1, in <module>
    import soundcard as sc
  File ".venv/lib/python3.8/site-packages/soundcard/__init__.py", line 11, in <module>
    from soundcard.coreaudio import *
  File ".venv/lib/python3.8/site-packages/soundcard/coreaudio.py", line 16, in <module>
    _ca = _ffi.dlopen('CoreAudio')
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File ".venv/lib/python3.8/site-packages/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)
OSError: ctypes.util.find_library() did not manage to locate a library called 'CoreAudio'

I have temporarily avoided the error by adding this code in .../lib/python3.8/site-packages/cffi/api.py

    if name=='CoreAudio':
        path='/System/Library/Frameworks/CoreAudio.framework/CoreAudio'
    if name=='AudioUnit':
        path='/System/Library/Frameworks/AudioUnit.framework/AudioUnit'

like so:
solution

Hope it helps

Does this mean it's a CFFI issue? Or is this a problem in SoundCard?

I have the same issue. @andresmntr's solution worked for me. macOS 11.2.1, Python 3.8.5.

I have the same issue, on Monterey, over six months later :(

Would anyone with access to a Monterey system like to draft a pull request that works around this issue?

k1ffx commented

There was apparently a long list of Python items that were broken by Mac OS Big Sur, including this issue. See https://bugs.python.org/issue41179 and https://bugs.python.org/issue41100. The "mega-issue" was recently closed with fixes in Python 3.10. I just installed Python 3.10.9 on my Big Sur MacBook Air, and ctypes.util.find_library() now works properly.

Unfortunately, SoundCard on Mac still has issues. microphone.record() returns a zero-filled numpy array. Haven't checked yet if there is already an issue about this opened here.

EDIT: As best as I can tell, in _Recorder, after return from _au.AudioUnitRender(), the code always runs through the "special case if output is silence", which simply returns a zero-filled numpy array. That's as far as I could go with this.

Thanks -

Bruce

I just installed Python 3.10.9 on my Big Sur MacBook Air, and ctypes.util.find_library() now works properly.

That's very good to hear!

Since I don't have access to a modern Mac, one of you will have to step in with a solution to the silence issue. I have no way of debugging this, unfortunately.