PyObjC CoreAudio Framework
PyObjC is a bridge between Python and Objective-C, enabling Python scripts to interact with Objective-C class libraries, including Apple's Cocoa frameworks. This `pyobjc-framework-coreaudio` package provides Python wrappers for the macOS CoreAudio framework. It is actively maintained with frequent releases, often aligning with new macOS SDK versions and updates to supported Python versions.
Warnings
- breaking Python 3.9 support was dropped in PyObjC 12.0. While some packaging metadata in 12.1 may have incorrectly indicated Python 3.9 support, it is not officially supported.
- breaking Python 3.8 support was dropped in PyObjC 11.0.
- breaking The `AVFAudio` package, previously merged into `AVFoundation`, was split into its own top-level package starting from PyObjC 12.0. Users must now import `AVFAudio` directly.
- breaking PyObjC 11.1 introduced changes to align the core bridge's behavior with `clang`'s Automatic Reference Counting (ARC) for Objective-C initializer (`init`) methods. Methods in the 'init' family now correctly steal a reference to `self` and return a new one, potentially affecting manual memory management or object lifecycle expectations.
- gotcha CoreAudio is a very low-level framework, and its PyObjC bindings lack direct documentation or simple Python examples. Many C structures require explicit handling, and APIs for implementing CoreAudio plugins are not supported. Using it effectively requires deep knowledge of Apple's CoreAudio C API.
- gotcha PyObjC 10.3 temporarily broke the ability for Python classes to define `__init__` methods when they or their superclasses also implemented `__new__`. This issue was resolved in PyObjC 10.3.1.
Install
-
pip install pyobjc-framework-coreaudio
Imports
- CoreAudio
import CoreAudio
Quickstart
# The CoreAudio framework is very low-level and lacks simple Python examples.
# Refer to Apple's CoreAudio documentation for usage, as its API is complex.
# import CoreAudio
# e.g., to get a list of audio devices (this is conceptual and untested):
# try:
# from CoreAudio import AudioObjectGetPropertyData, AudioObjectPropertyAddress
# from CoreAudio import kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster
# from CoreAudio import AudioHardwareGetPropertyInfo, AudioHardwareGetProperty
# # ... (complex setup involving structs, callbacks, etc. not suitable for quickstart)
# print("CoreAudio imported, but direct usage is complex.")
# except ImportError:
# print("Could not import CoreAudio. Ensure pyobjc-framework-coreaudio is installed on macOS.")