SoundCard icon indicating copy to clipboard operation
SoundCard copied to clipboard

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

Open andresmntr opened this issue 4 years ago • 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?

andresmntr avatar Feb 23 '21 19:02 andresmntr

What version of macOS and Python are your running?

bastibe avatar Feb 24 '21 13:02 bastibe

macOS BigSur Version 11.2.1 python 3.8.5

andresmntr avatar Feb 25 '21 08:02 andresmntr

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'

phoenix-meadowlark avatar Feb 28 '21 23:02 phoenix-meadowlark

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

andresmntr avatar Mar 01 '21 13:03 andresmntr

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

bastibe avatar Mar 02 '21 14:03 bastibe

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

GaffaSnobb avatar May 27 '21 09:05 GaffaSnobb

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

7ombie avatar Jan 13 '22 02:01 7ombie

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

bastibe avatar Jan 14 '22 12:01 bastibe

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

k1ffx avatar Dec 14 '22 20:12 k1ffx

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.

bastibe avatar Dec 19 '22 10:12 bastibe