QLWD commited on
Commit
d39c358
·
verified ·
1 Parent(s): 081af9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -88,27 +88,32 @@ class AudioProcessor:
88
  def get_best_match(self, target_time, diarization_output):
89
  target_start_time = target_time['start_time']
90
  target_end_time = target_time['end_time']
91
-
 
 
 
 
 
92
  # 用于存储每个说话人时间段的重叠比例
93
  speaker_segments = []
94
  for segment, label in diarization_output.itertracks(yield_label=True):
95
  try:
96
  start_seconds = segment.start
97
  end_seconds = segment.end
98
-
99
  # 计算目标音频时间段和说话人时间段的重叠时间
100
  overlap = self.calculate_overlap(target_start_time, target_end_time, start_seconds, end_seconds)
101
  overlap_ratio = overlap / (end_seconds - start_seconds)
102
-
103
  # 记录说话人标签和重叠比例
104
  speaker_segments.append((label, overlap_ratio, start_seconds, end_seconds))
105
-
106
  except Exception as e:
107
  print(f"处理行时出错: '{segment}'. 错误: {e}")
108
 
109
- # 按照重叠比例排序,返回重叠比例最大的一段
110
- best_match = max(speaker_segments, key=lambda x: x[1], default=None)
111
- return best_match
112
 
113
  # 获取该说话人除了目标语音时间段外的所有时间段
114
  def get_speaker_time_segments(self, diarization_output, target_time, speaker_label):
 
88
  def get_best_match(self, target_time, diarization_output):
89
  target_start_time = target_time['start_time']
90
  target_end_time = target_time['end_time']
91
+
92
+ # 确保 diarization_output 是 Annotation 类型
93
+ if not isinstance(diarization_output, Annotation):
94
+ print(f"Error: Expected an Annotation object, but got {type(diarization_output)}")
95
+ return None # 或者返回一个空的默认值
96
+
97
  # 用于存储每个说话人时间段的重叠比例
98
  speaker_segments = []
99
  for segment, label in diarization_output.itertracks(yield_label=True):
100
  try:
101
  start_seconds = segment.start
102
  end_seconds = segment.end
103
+
104
  # 计算目标音频时间段和说话人时间段的重叠时间
105
  overlap = self.calculate_overlap(target_start_time, target_end_time, start_seconds, end_seconds)
106
  overlap_ratio = overlap / (end_seconds - start_seconds)
107
+
108
  # 记录说话人标签和重叠比例
109
  speaker_segments.append((label, overlap_ratio, start_seconds, end_seconds))
110
+
111
  except Exception as e:
112
  print(f"处理行时出错: '{segment}'. 错误: {e}")
113
 
114
+ # 按照重叠比例排序,返回重叠比例最大的一段
115
+ best_match = max(speaker_segments, key=lambda x: x[1], default=None)
116
+ return best_match
117
 
118
  # 获取该说话人除了目标语音时间段外的所有时间段
119
  def get_speaker_time_segments(self, diarization_output, target_time, speaker_label):