Skip to content

Instantly share code, notes, and snippets.

@kenenbek
Created November 21, 2025 08:26
Show Gist options
  • Select an option

  • Save kenenbek/22c66fb788487f64ce8ecacfe1626535 to your computer and use it in GitHub Desktop.

Select an option

Save kenenbek/22c66fb788487f64ce8ecacfe1626535 to your computer and use it in GitHub Desktop.
def diarize_audio(audio_file, num_speakers=None, device=None):
# Set device
if device is None:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print(f"Using device: {device}")
# Load pipeline
print("Loading diarization pipeline...")
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-community-1")
pipeline.to(device)
# Perform diarization
print(f"Performing diarization on {audio_file}...")
with ProgressHook() as hook:
if num_speakers:
diarization = pipeline(audio_file, hook=hook, num_speakers=num_speakers)
else:
diarization = pipeline(audio_file, hook=hook)
print("Diarization complete!")
return diarization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment