Spaces:
Runtime error
Runtime error
Update diarization.py
Browse files- diarization.py +19 -15
diarization.py
CHANGED
|
@@ -73,24 +73,28 @@ def diarize_audio(audio_path: str, pipeline, num_speakers: int = None) -> List[T
|
|
| 73 |
else:
|
| 74 |
diarization = pipeline(audio_path)
|
| 75 |
|
| 76 |
-
#
|
|
|
|
|
|
|
|
|
|
| 77 |
segments = []
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
# Fallback for different output format
|
| 84 |
-
elif hasattr(diarization, 'get_timeline'):
|
| 85 |
-
for segment, _, speaker in diarization.get_timeline().itertracks(yield_label=True):
|
| 86 |
segments.append((segment.start, segment.end, speaker))
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
print(f"✅ Diarization tamamlandı: {len(segments)} segment bulundu")
|
| 96 |
return segments
|
|
|
|
| 73 |
else:
|
| 74 |
diarization = pipeline(audio_path)
|
| 75 |
|
| 76 |
+
# Debug: print what we got
|
| 77 |
+
print(f"🔍 Diarization result type: {type(diarization)}")
|
| 78 |
+
|
| 79 |
+
# Extract segments from Annotation object
|
| 80 |
segments = []
|
| 81 |
|
| 82 |
+
# The result should be an Annotation object with itertracks method
|
| 83 |
+
# Access it properly - the pipeline returns an Annotation directly
|
| 84 |
+
try:
|
| 85 |
+
for segment, track, speaker in diarization.itertracks(yield_label=True):
|
|
|
|
|
|
|
|
|
|
| 86 |
segments.append((segment.start, segment.end, speaker))
|
| 87 |
+
except AttributeError:
|
| 88 |
+
# If itertracks doesn't exist, try accessing _tracks or similar
|
| 89 |
+
print(f"🔍 Available attributes: {dir(diarization)}")
|
| 90 |
+
|
| 91 |
+
# Try to access the annotation if wrapped
|
| 92 |
+
if hasattr(diarization, 'annotation'):
|
| 93 |
+
for segment, track, speaker in diarization.annotation.itertracks(yield_label=True):
|
| 94 |
+
segments.append((segment.start, segment.end, speaker))
|
| 95 |
+
elif hasattr(diarization, '_annotation'):
|
| 96 |
+
for segment, track, speaker in diarization._annotation.itertracks(yield_label=True):
|
| 97 |
+
segments.append((segment.start, segment.end, speaker))
|
| 98 |
|
| 99 |
print(f"✅ Diarization tamamlandı: {len(segments)} segment bulundu")
|
| 100 |
return segments
|