File size: 1,023 Bytes
2a1be35 2692919 2a1be35 6af24e4 2a1be35 6af24e4 2a1be35 6af24e4 2a1be35 1ce219b 2a1be35 557cbad 2a1be35 6af24e4 2a1be35 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import gradio as gr
#from pyannote.audio import Pipeline
import tempfile
import os
from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained(
"pyannote/speaker-diarization-community-1", token=os.getenv('HF_TOKEN')
)
def diarize(audio_file_path):
"""
Perform speaker diarization on uploaded audio file.
"""
# Run diarization
diarization = pipeline(audio_file_path)
# Collect readable results
results = []
for turn, speaker in diarization.speaker_diarization:
results.append(
f"{speaker} speaks between t={turn.start:.3f}s and t={turn.end:.3f}s"
)
return "\n".join(results)
# 🎛️ Gradio interface
demo = gr.Interface(
fn=diarize,
inputs=gr.Audio(type="filepath", label="Upload Audio (.wav)"),
outputs=gr.Textbox(label="Speaker Segments"),
title="🎙️ Speaker Diarization Demo",
description="Upload an audio file and detect who speaks when using Pyannote Audio."
)
if __name__ == "__main__":
demo.launch() |