
pyannoteAI/Live 1 Realtime Diarization
State of art real-time diarization from pyannote
Live-1 is pyannoteAI's streaming speaker diarization model. It labels who is speaking in a live call as the audio arrives. You stream 16 kHz mono audio over a WebSocket in 100 ms chunks and get back speaker start and end events. In our tests those events typically arrived well under a second behind the live audio. It's built for meeting assistants, sales and support copilots, and other real-time voice apps, and each stream can run for up to 5 hours.
import asyncio
import json
import os
import subprocess
import websockets
MODEL_ID = "" # Add Model ID from Baseten Dashboard
endpoint_url = (
f"wss://model-{MODEL_ID}.api.baseten.co"
"/environments/production/websocket"
)
headers = {"Authorization": f"Api-Key {os.getenv('BASETEN_API_KEY')}"}
audio_url = (
"https://test-audios-public.s3.us-west-2.amazonaws.com"
"/10-sec-01-podcast.m4a"
)
# 100 ms of 16 kHz mono float32 PCM; every frame must be exactly this size
CHUNK_BYTES = 6400
# Decode any audio format to raw 16 kHz mono float32 PCM.
pcm = subprocess.run(
["ffmpeg", "-loglevel", "error", "-i", audio_url,
"-f", "f32le", "-ac", "1", "-ar", "16000", "-"],
capture_output=True, check=True,
).stdout
async def send_audio(ws):
for i in range(0, len(pcm), CHUNK_BYTES):
await ws.send(pcm[i : i + CHUNK_BYTES].ljust(CHUNK_BYTES, b"\0"))
await asyncio.sleep(0.1) # stream at real-time pace
# Flushes in-flight audio; the server sends the remaining events,
# then closes the socket.
await ws.send(json.dumps({"type": "end_of_stream"}))
async def main():
# A scaled-to-zero deployment takes a few minutes to accept its
# first connection.
async with websockets.connect(
endpoint_url, additional_headers=headers, open_timeout=300
) as ws:
sender = asyncio.create_task(send_audio(ws))
# Ends when the server closes after end_of_stream.
async for message in ws:
print(message)
await sender
asyncio.run(main())Output
{
"type": "diarization_speaker_start",
"data": {
"timestamp": 0,
"speaker": "SPEAKER_00"
}
}