Spaces:
Running
Running
jhj0517
commited on
Commit
·
2efa275
1
Parent(s):
46f7c1b
Fix type issue
Browse files
modules/diarize/diarize_pipeline.py
CHANGED
@@ -7,6 +7,7 @@ from pyannote.audio import Pipeline
|
|
7 |
from typing import Optional, Union
|
8 |
import torch
|
9 |
|
|
|
10 |
from modules.utils.paths import DIARIZATION_MODELS_DIR
|
11 |
from modules.diarize.audio_loader import load_audio, SAMPLE_RATE
|
12 |
|
@@ -44,7 +45,8 @@ class DiarizationPipeline:
|
|
44 |
def assign_word_speakers(diarize_df, transcript_result, fill_nearest=False):
|
45 |
transcript_segments = transcript_result["segments"]
|
46 |
for seg in transcript_segments:
|
47 |
-
seg
|
|
|
48 |
# assign speaker to segment (if any)
|
49 |
diarize_df['intersection'] = np.minimum(diarize_df['end'], seg['end']) - np.maximum(diarize_df['start'],
|
50 |
seg['start'])
|
@@ -64,7 +66,7 @@ def assign_word_speakers(diarize_df, transcript_result, fill_nearest=False):
|
|
64 |
seg["speaker"] = speaker
|
65 |
|
66 |
# assign speaker to words
|
67 |
-
if 'words' in seg:
|
68 |
for word in seg['words']:
|
69 |
if 'start' in word:
|
70 |
diarize_df['intersection'] = np.minimum(diarize_df['end'], word['end']) - np.maximum(
|
@@ -89,7 +91,7 @@ def assign_word_speakers(diarize_df, transcript_result, fill_nearest=False):
|
|
89 |
return transcript_result
|
90 |
|
91 |
|
92 |
-
class
|
93 |
def __init__(self, start, end, speaker=None):
|
94 |
self.start = start
|
95 |
self.end = end
|
|
|
7 |
from typing import Optional, Union
|
8 |
import torch
|
9 |
|
10 |
+
from modules.whisper.data_classes import *
|
11 |
from modules.utils.paths import DIARIZATION_MODELS_DIR
|
12 |
from modules.diarize.audio_loader import load_audio, SAMPLE_RATE
|
13 |
|
|
|
45 |
def assign_word_speakers(diarize_df, transcript_result, fill_nearest=False):
|
46 |
transcript_segments = transcript_result["segments"]
|
47 |
for seg in transcript_segments:
|
48 |
+
if isinstance(seg, Segment):
|
49 |
+
seg = seg.model_dump()
|
50 |
# assign speaker to segment (if any)
|
51 |
diarize_df['intersection'] = np.minimum(diarize_df['end'], seg['end']) - np.maximum(diarize_df['start'],
|
52 |
seg['start'])
|
|
|
66 |
seg["speaker"] = speaker
|
67 |
|
68 |
# assign speaker to words
|
69 |
+
if 'words' in seg and seg['words'] is not None:
|
70 |
for word in seg['words']:
|
71 |
if 'start' in word:
|
72 |
diarize_df['intersection'] = np.minimum(diarize_df['end'], word['end']) - np.maximum(
|
|
|
91 |
return transcript_result
|
92 |
|
93 |
|
94 |
+
class DiarizationSegment:
|
95 |
def __init__(self, start, end, speaker=None):
|
96 |
self.start = start
|
97 |
self.end = end
|