PyObjC ShazamKit Framework

12.1 · active · verified Tue Apr 14

PyObjC-framework-shazamkit provides Python bindings for Apple's ShazamKit framework on macOS, allowing Python applications to identify music and audio using Shazam's technology. It's part of the larger PyObjC project, which offers comprehensive access to macOS frameworks. The current version is 12.1, with releases typically tied to macOS SDK updates and Python version support changes.

Warnings

Install

Imports

Quickstart

This quickstart verifies that the PyObjC ShazamKit binding can be imported and its core components (classes, constants) are accessible. Note that actual ShazamKit functionality (audio recording, matching) requires microphone permissions, an `SHSessionDelegate` implementation, and often an `NSRunLoop` for asynchronous operations, which are beyond this basic setup.

import platform
from ShazamKit import SHMediaItem, SHErrorDomain, SHSession

if platform.system() != "Darwin":
    print("ShazamKit is a macOS-only framework. This code will only execute PyObjC specific parts on macOS.")
else:
    try:
        # Verify core PyObjC bridge and ShazamKit framework are loadable
        _ = SHMediaItem  # Accessing a class to ensure it's bound
        _ = SHSession
        error_domain = SHErrorDomain # Accessing a constant

        print(f"Successfully imported ShazamKit framework on macOS.")
        print(f"SHMediaItem class type: {type(SHMediaItem)}")
        print(f"SHErrorDomain constant: {error_domain}")

        # To use ShazamKit effectively, you would typically:
        # 1. Request microphone permissions.
        # 2. Create an SHSession with a custom SHSessionDelegate (inheriting from objc.retains('SHSessionDelegate')).
        # 3. Capture audio and create an SHSignature.
        # 4. Call session.matchSignature(signature).
        # This quickstart merely confirms the library's basic availability.

    except ImportError:
        print("Error: ShazamKit framework not found. Ensure 'pyobjc-framework-shazamkit' is installed and you are on macOS.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →