Spaces:
Sleeping
Sleeping
Update diarization.py
Browse files- diarization.py +13 -22
diarization.py
CHANGED
|
@@ -69,32 +69,23 @@ def diarize_audio(audio_path: str, pipeline, num_speakers: int = None) -> List[T
|
|
| 69 |
try:
|
| 70 |
# Run diarization (auto-detect speakers or use specified count)
|
| 71 |
if num_speakers:
|
| 72 |
-
|
| 73 |
else:
|
| 74 |
-
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
print(f"🔍 Diarization result type: {type(diarization)}")
|
| 78 |
-
|
| 79 |
-
# Extract segments from Annotation object
|
| 80 |
segments = []
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 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
|
|
|
|
| 69 |
try:
|
| 70 |
# Run diarization (auto-detect speakers or use specified count)
|
| 71 |
if num_speakers:
|
| 72 |
+
result = pipeline(audio_path, min_speakers=1, max_speakers=num_speakers)
|
| 73 |
else:
|
| 74 |
+
result = pipeline(audio_path)
|
| 75 |
|
| 76 |
+
# Extract segments from DiarizeOutput object
|
|
|
|
|
|
|
|
|
|
| 77 |
segments = []
|
| 78 |
|
| 79 |
+
# DiarizeOutput has speaker_diarization attribute which is the Annotation
|
| 80 |
+
if hasattr(result, 'speaker_diarization'):
|
| 81 |
+
diarization = result.speaker_diarization
|
| 82 |
+
print(f"🔍 Using speaker_diarization attribute")
|
| 83 |
+
else:
|
| 84 |
+
diarization = result
|
| 85 |
+
|
| 86 |
+
# Now iterate over the Annotation object
|
| 87 |
+
for segment, track, speaker in diarization.itertracks(yield_label=True):
|
| 88 |
+
segments.append((segment.start, segment.end, speaker))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
print(f"✅ Diarization tamamlandı: {len(segments)} segment bulundu")
|
| 91 |
return segments
|