Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -273,18 +273,38 @@ def process_audio(model_choice, mode, voice_print_path, audio_path, speaker_name
|
|
273 |
if diarization_pipeline is None:
|
274 |
return "Pyannote diarization is not available.", None, None
|
275 |
|
|
|
276 |
diarization = diarization_pipeline({"waveform": waveform, "sample_rate": sample_rate})
|
277 |
-
data = []
|
278 |
|
279 |
-
#
|
280 |
-
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
else:
|
284 |
-
|
285 |
-
speaker = diarization.label(segment)
|
286 |
-
data.append({"start": segment.start, "end": segment.end, "speaker": speaker})
|
287 |
|
|
|
|
|
|
|
288 |
diarization_df = pd.DataFrame(data)
|
289 |
|
290 |
# Identify target speaker
|
|
|
273 |
if diarization_pipeline is None:
|
274 |
return "Pyannote diarization is not available.", None, None
|
275 |
|
276 |
+
|
277 |
diarization = diarization_pipeline({"waveform": waveform, "sample_rate": sample_rate})
|
|
|
278 |
|
279 |
+
# Run diarization - pass audio file path directly for better compatibility
|
280 |
+
#diarization = diarization_pipeline(audio_path)
|
281 |
+
|
282 |
+
# Correct API for pyannote 3.1+ with DiarizeOutput
|
283 |
+
data = []
|
284 |
+
|
285 |
+
# Check if we have the new API (DiarizeOutput with speaker_diarization attribute)
|
286 |
+
if hasattr(diarization, 'speaker_diarization'):
|
287 |
+
# New API (pyannote 3.1+) - iterate over speaker_diarization
|
288 |
+
for turn, speaker in diarization.speaker_diarization:
|
289 |
+
data.append({
|
290 |
+
"start": turn.start,
|
291 |
+
"end": turn.end,
|
292 |
+
"speaker": speaker
|
293 |
+
})
|
294 |
+
elif hasattr(diarization, 'itertracks'):
|
295 |
+
# Old API (pyannote < 3.1) - Annotation object
|
296 |
+
for segment, track, speaker in diarization.itertracks(yield_label=True):
|
297 |
+
data.append({
|
298 |
+
"start": segment.start,
|
299 |
+
"end": segment.end,
|
300 |
+
"speaker": speaker
|
301 |
+
})
|
302 |
else:
|
303 |
+
return "Unsupported pyannote.audio version. Please check the diarization output format.", None, None
|
|
|
|
|
304 |
|
305 |
+
if not data:
|
306 |
+
return "No speaker segments found in diarization.", None, None
|
307 |
+
|
308 |
diarization_df = pd.DataFrame(data)
|
309 |
|
310 |
# Identify target speaker
|