Skip to content

Commit

Permalink
Fix type issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jhj0517 committed Oct 31, 2024
1 parent 46f7c1b commit 2efa275
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions modules/diarize/diarize_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Optional, Union
import torch

from modules.whisper.data_classes import *
from modules.utils.paths import DIARIZATION_MODELS_DIR
from modules.diarize.audio_loader import load_audio, SAMPLE_RATE

Expand Down Expand Up @@ -44,7 +45,8 @@ def __call__(self, audio: Union[str, np.ndarray], min_speakers=None, max_speaker
def assign_word_speakers(diarize_df, transcript_result, fill_nearest=False):
transcript_segments = transcript_result["segments"]
for seg in transcript_segments:
seg = seg.dict()
if isinstance(seg, Segment):
seg = seg.model_dump()
# assign speaker to segment (if any)
diarize_df['intersection'] = np.minimum(diarize_df['end'], seg['end']) - np.maximum(diarize_df['start'],
seg['start'])
Expand All @@ -64,7 +66,7 @@ def assign_word_speakers(diarize_df, transcript_result, fill_nearest=False):
seg["speaker"] = speaker

# assign speaker to words
if 'words' in seg:
if 'words' in seg and seg['words'] is not None:
for word in seg['words']:
if 'start' in word:
diarize_df['intersection'] = np.minimum(diarize_df['end'], word['end']) - np.maximum(
Expand All @@ -89,7 +91,7 @@ def assign_word_speakers(diarize_df, transcript_result, fill_nearest=False):
return transcript_result


class Segment:
class DiarizationSegment:
def __init__(self, start, end, speaker=None):
self.start = start
self.end = end
Expand Down

0 comments on commit 2efa275

Please sign in to comment.