PyObjC-framework-Speech provides Python wrappers for the macOS Speech framework, enabling features like speech recognition. It's part of the PyObjC project, which bridges Python and Objective-C, and typically updates alongside macOS SDK releases, ensuring compatibility with the latest system features.
pip install pyobjc-framework-speechVerified import paths — ran on the pinned version, not inferred.
Checks the authorization status for speech recognition, requests it if not determined, and then initializes an `SFSpeechRecognizer` to check its availability and supported locales. Note that a full PyObjC application typically runs within an event loop to handle UI interactions and asynchronous callbacks properly. Running this script directly will trigger the permission dialog, but a `PyObjCTools.AppHelper.runConsoleEventLoop` might be needed for the callback to be fully processed if the script exits too quickly.
Upgrade to Python 3.10 or newer (Python 3.13 is supported by recent PyObjC releases, with experimental free-threading).
Implement `SFSpeechRecognizer.requestAuthorization_` and handle its callback. Crucially, ensure your app's `Info.plist` (for bundled apps) includes `NSSpeechRecognitionUsageDescription` and `NSMicrophoneUsageDescription` keys with descriptive strings.
Update imports from `AVFoundation` to `AVFAudio` for specific audio components. Ensure `pyobjc-framework-AVFoundation` is installed if you need the `AVFAudio` components (it is included in that distribution).
Review memory management patterns, especially around object creation and initialization, for code interacting deeply with Objective-C objects via `alloc().init()` and similar patterns.
Familiarize yourself with Cocoa's delegate pattern. For command-line tools or scripts, consider using `PyObjCTools.AppHelper.runConsoleEventLoop()` to ensure callbacks are processed and permission dialogs are handled correctly.