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

Update diarization.py

Browse files
Files changed (1) hide show
  1. 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
- # Extract segments - handle both old and new pyannote API
 
 
 
77
  segments = []
78
 
79
- # Try new API first (pyannote 3.x)
80
- if hasattr(diarization, 'itertracks'):
81
- for turn, _, speaker in diarization.itertracks(yield_label=True):
82
- segments.append((turn.start, turn.end, speaker))
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
- # Direct iteration if it's a list-like object
88
- else:
89
- # Try to iterate over the diarization result
90
- for item in diarization:
91
- if hasattr(item, 'start') and hasattr(item, 'end'):
92
- speaker = getattr(item, 'speaker', 'SPEAKER_00')
93
- segments.append((item.start, item.end, speaker))
 
 
 
 
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