pyannoteAI Python SDK

0.4.0 · active · verified Fri Apr 10

The official pyannoteAI Python SDK provides a convenient way to interact with the pyannoteAI platform. It offers state-of-the-art AI models for tasks like speaker diarization (who spoke when), speaker identification, and STT orchestration (speech-to-text with speaker attribution) via a cloud API. The library is actively maintained, with frequent releases bringing new features and improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the pyannoteAI client with your API key and submit an audio file for speaker diarization. It then fetches and prints the diarization results. Remember to replace `YOUR_API_KEY_HERE` with a valid key from your pyannoteAI dashboard and use a publicly accessible audio URL.

import os
from pyannoteai.sdk import Client

# Ensure your API key is set as an environment variable or passed directly
# It's recommended to set PYANNOTE_API_KEY as an environment variable in production
api_key = os.environ.get('PYANNOTE_API_KEY', 'YOUR_API_KEY_HERE')

if api_key == 'YOUR_API_KEY_HERE':
    print("Warning: Please replace 'YOUR_API_KEY_HERE' with your actual pyannoteAI API key or set the PYANNOTE_API_KEY environment variable.")

client = Client(api_key)

# Example audio URL (replace with your audio file accessible via a direct public URL)
audio_url = "https://files.pyannote.ai/samples/two_speakers.wav"

try:
    # Submit a diarization job
    job_id = client.diarize(audio_url)
    print(f"Diarization job submitted with ID: {job_id}")

    # Wait for the job to complete and retrieve results
    # In a real application, you might use webhooks or polling for job status
    job_result = client.get_job_result(job_id)
    
    if job_result and job_result.get("status") == "completed":
        print("Diarization Result:")
        for segment in job_result.get("output", {}).get("segments", []):
            start = segment["start"]
            end = segment["end"]
            speaker = segment["speaker"]
            print(f"[ {start:.2f}s - {end:.2f}s ] Speaker {speaker}")
    else:
        print(f"Job {job_id} status: {job_result.get('status')}")
        print(f"Error: {job_result.get('error', 'Unknown error')}")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →