Created
November 21, 2025 08:26
-
-
Save kenenbek/22c66fb788487f64ce8ecacfe1626535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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