duongthienz commited on
Commit
2f4c60e
·
verified ·
1 Parent(s): ca9ec1a

Update state.py

Browse files
Files changed (1) hide show
  1. state.py +38 -5
state.py CHANGED
@@ -723,6 +723,7 @@ def analyze(inFileName):
723
  _is_annotation_file = inFileName.lower().endswith((".rttm", ".txt", ".csv"))
724
  if _is_annotation_file:
725
  from pyannote.core import Annotation, Segment
 
726
  noVoice = Annotation()
727
  multiVoice = Annotation()
728
  oneVoice = Annotation()
@@ -733,14 +734,46 @@ def analyze(inFileName):
733
  for seg in currAnnotation.subset([label]).itersegments()],
734
  key=lambda x: x[0]
735
  )
736
- prev_end = 0.0
 
737
  for start, end, label in all_segs:
738
- if start > prev_end + 0.1:
739
- noVoice[Segment(prev_end, start)] = 'silence'
740
- oneVoice[Segment(start, end)] = label
741
- prev_end = max(prev_end, end)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
742
  if currTotalTime > prev_end + 0.1:
743
  noVoice[Segment(prev_end, currTotalTime)] = 'silence'
 
 
 
 
744
  else:
745
  try:
746
  noVoice, oneVoice, multiVoice = su.calcSpeakingTypes(pipeline, currAnnotation, currTotalTime)
 
723
  _is_annotation_file = inFileName.lower().endswith((".rttm", ".txt", ".csv"))
724
  if _is_annotation_file:
725
  from pyannote.core import Annotation, Segment
726
+ from collections import defaultdict
727
  noVoice = Annotation()
728
  multiVoice = Annotation()
729
  oneVoice = Annotation()
 
734
  for seg in currAnnotation.subset([label]).itersegments()],
735
  key=lambda x: x[0]
736
  )
737
+ # Detect multi-voice: pairwise overlaps between speakers
738
+ speaker_segs = defaultdict(list)
739
  for start, end, label in all_segs:
740
+ speaker_segs[label].append((start, end))
741
+ multi_intervals = []
742
+ labels_list = list(speaker_segs.keys())
743
+ for i in range(len(labels_list)):
744
+ for j in range(i+1, len(labels_list)):
745
+ for s1, e1 in speaker_segs[labels_list[i]]:
746
+ for s2, e2 in speaker_segs[labels_list[j]]:
747
+ ov_s, ov_e = max(s1, s2), min(e1, e2)
748
+ if ov_e > ov_s + 0.05:
749
+ multi_intervals.append((ov_s, ov_e))
750
+ multi_intervals.sort()
751
+ merged_multi = []
752
+ for s, e in multi_intervals:
753
+ if merged_multi and s <= merged_multi[-1][1]:
754
+ merged_multi[-1] = (merged_multi[-1][0], max(merged_multi[-1][1], e))
755
+ else:
756
+ merged_multi.append([s, e])
757
+ for s, e in merged_multi:
758
+ multiVoice[Segment(s, e)] = 'overlap'
759
+ # No Voice: gaps in the union of all speech
760
+ speech_union = []
761
+ for start, end, _ in all_segs:
762
+ if speech_union and start <= speech_union[-1][1]:
763
+ speech_union[-1] = (speech_union[-1][0], max(speech_union[-1][1], end))
764
+ else:
765
+ speech_union.append([start, end])
766
+ prev_end = 0.0
767
+ for s, e in speech_union:
768
+ if s > prev_end + 0.1:
769
+ noVoice[Segment(prev_end, s)] = 'silence'
770
+ prev_end = e
771
  if currTotalTime > prev_end + 0.1:
772
  noVoice[Segment(prev_end, currTotalTime)] = 'silence'
773
+ # Single Voice: segments not overlapping any multi-voice region
774
+ for start, end, label in all_segs:
775
+ if not any(ms < end and me > start for ms, me in merged_multi):
776
+ oneVoice[Segment(start, end)] = label
777
  else:
778
  try:
779
  noVoice, oneVoice, multiVoice = su.calcSpeakingTypes(pipeline, currAnnotation, currTotalTime)