Update app.py
Browse files
app.py
CHANGED
|
@@ -54,6 +54,28 @@ def get_speaker_at(diarization, time_sec):
|
|
| 54 |
return None
|
| 55 |
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
def find_leading_noise_cutoff(diarization, whisper_start, search_back_sec=4.0):
|
| 58 |
"""
|
| 59 |
برمیگرده به عقب از شروعِ حدسیِ Whisper، دنبال یه بلوک نویز/بیگویندهی
|
|
@@ -200,8 +222,7 @@ def run_alignment_pass(segments_raw, align_waveform, diarization):
|
|
| 200 |
align_waveform, word_dicts, word_dicts[0]["start"], word_dicts[-1]["end"], cutoff_start=cutoff
|
| 201 |
)
|
| 202 |
|
| 203 |
-
|
| 204 |
-
speaker = get_speaker_at(diarization, mid_time)
|
| 205 |
|
| 206 |
segments.append({
|
| 207 |
"text": seg.text.strip(),
|
|
|
|
| 54 |
return None
|
| 55 |
|
| 56 |
|
| 57 |
+
def get_speaker_for_segment(diarization, seg_start, seg_end):
|
| 58 |
+
"""
|
| 59 |
+
بهجای اعتماد به یه لحظهی تنها (که ممکنه نزدیک مرز بین دو گوینده باشه)،
|
| 60 |
+
چند نقطه در طول جمله رو چک میکنه و گویندهای که بیشترین رأی رو آورده
|
| 61 |
+
برمیگردونه - این دقت رو بهتر میکنه ولی صد در صد تضمینشده نیست.
|
| 62 |
+
"""
|
| 63 |
+
duration = seg_end - seg_start
|
| 64 |
+
if duration <= 0:
|
| 65 |
+
return get_speaker_at(diarization, seg_start)
|
| 66 |
+
|
| 67 |
+
sample_points = [seg_start + duration * frac for frac in (0.2, 0.4, 0.5, 0.6, 0.8)]
|
| 68 |
+
votes = {}
|
| 69 |
+
for t in sample_points:
|
| 70 |
+
speaker = get_speaker_at(diarization, t)
|
| 71 |
+
if speaker is not None:
|
| 72 |
+
votes[speaker] = votes.get(speaker, 0) + 1
|
| 73 |
+
|
| 74 |
+
if not votes:
|
| 75 |
+
return None
|
| 76 |
+
return max(votes, key=votes.get)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
def find_leading_noise_cutoff(diarization, whisper_start, search_back_sec=4.0):
|
| 80 |
"""
|
| 81 |
برمیگرده به عقب از شروعِ حدسیِ Whisper، دنبال یه بلوک نویز/بیگویندهی
|
|
|
|
| 222 |
align_waveform, word_dicts, word_dicts[0]["start"], word_dicts[-1]["end"], cutoff_start=cutoff
|
| 223 |
)
|
| 224 |
|
| 225 |
+
speaker = get_speaker_for_segment(diarization, realigned[0]["start"], realigned[-1]["end"])
|
|
|
|
| 226 |
|
| 227 |
segments.append({
|
| 228 |
"text": seg.text.strip(),
|