Spaces:
Runtime error
Runtime error
Aryan Gosaliya commited on
Commit ·
d9da639
1
Parent(s): 7603254
debugging pyannote
Browse files- app/services/asr.py +7 -5
app/services/asr.py
CHANGED
|
@@ -58,13 +58,13 @@ def transcribe(audio_path: str) -> List[Dict]:
|
|
| 58 |
try:
|
| 59 |
diarization = diarization_pipeline(audio_path)
|
| 60 |
|
| 61 |
-
# --- DEBUGGING LINES
|
| 62 |
print("\n--- Diarization Output ---")
|
| 63 |
print(f"Type of diarization object: {type(diarization)}")
|
| 64 |
print("Diarization object content:")
|
| 65 |
print(diarization)
|
| 66 |
print("--- End Diarization Output ---\n")
|
| 67 |
-
# ----------------------------------
|
| 68 |
|
| 69 |
except Exception as e:
|
| 70 |
print(f"Error during diarization: {e}")
|
|
@@ -74,11 +74,14 @@ def transcribe(audio_path: str) -> List[Dict]:
|
|
| 74 |
|
| 75 |
# 3. Assign Speaker to Segments
|
| 76 |
out_segments = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
for seg in whisper_segments:
|
| 78 |
-
# Find the speaker for the segment's midpoint
|
| 79 |
midpoint = seg["start"] + (seg["end"] - seg["start"]) / 2
|
| 80 |
speaker = "UNKNOWN"
|
| 81 |
-
for turn, _, speaker_label in
|
| 82 |
if turn.start <= midpoint <= turn.end:
|
| 83 |
speaker = speaker_label
|
| 84 |
break
|
|
@@ -94,5 +97,4 @@ def transcribe(audio_path: str) -> List[Dict]:
|
|
| 94 |
|
| 95 |
if not out_segments:
|
| 96 |
return [{"start": 0.0, "end": 0.0, "speaker": "A", "text": ""}]
|
| 97 |
-
|
| 98 |
return out_segments
|
|
|
|
| 58 |
try:
|
| 59 |
diarization = diarization_pipeline(audio_path)
|
| 60 |
|
| 61 |
+
# --- DEBUGGING LINES (optional) ---
|
| 62 |
print("\n--- Diarization Output ---")
|
| 63 |
print(f"Type of diarization object: {type(diarization)}")
|
| 64 |
print("Diarization object content:")
|
| 65 |
print(diarization)
|
| 66 |
print("--- End Diarization Output ---\n")
|
| 67 |
+
# ----------------------------------
|
| 68 |
|
| 69 |
except Exception as e:
|
| 70 |
print(f"Error during diarization: {e}")
|
|
|
|
| 74 |
|
| 75 |
# 3. Assign Speaker to Segments
|
| 76 |
out_segments = []
|
| 77 |
+
|
| 78 |
+
# For pyannote 4.x, use diarization.speaker_diarization
|
| 79 |
+
annotation = diarization.speaker_diarization # This is an Annotation object
|
| 80 |
+
|
| 81 |
for seg in whisper_segments:
|
|
|
|
| 82 |
midpoint = seg["start"] + (seg["end"] - seg["start"]) / 2
|
| 83 |
speaker = "UNKNOWN"
|
| 84 |
+
for turn, _, speaker_label in annotation.itertracks(yield_label=True):
|
| 85 |
if turn.start <= midpoint <= turn.end:
|
| 86 |
speaker = speaker_label
|
| 87 |
break
|
|
|
|
| 97 |
|
| 98 |
if not out_segments:
|
| 99 |
return [{"start": 0.0, "end": 0.0, "speaker": "A", "text": ""}]
|
|
|
|
| 100 |
return out_segments
|