Jedi09 commited on
Commit
179896d
·
verified ·
1 Parent(s): 559cd81

Update diarization.py

Browse files
Files changed (1) hide show
  1. 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
- diarization = pipeline(audio_path, min_speakers=1, max_speakers=num_speakers)
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
 
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