duongthienz commited on
Commit
ca9ec1a
·
verified ·
1 Parent(s): 0c6243d

Update state.py

Browse files
Files changed (1) hide show
  1. state.py +33 -13
state.py CHANGED
@@ -715,19 +715,17 @@ def analyze(inFileName):
715
  printV("Loaded results", 4)
716
 
717
  pipeline = st.session_state.pipeline
718
- try:
719
- noVoice, oneVoice, multiVoice = su.calcSpeakingTypes(pipeline, currAnnotation, currTotalTime)
720
- except Exception as e:
721
- print(f"calcSpeakingTypes failed ({e}), falling back to annotation-based voice split")
722
- # Fall back: derive voice categories directly from segment timeline.
723
- # - oneVoice: each named speaker segment
724
- # - noVoice: gaps between segments (real silence)
725
- # - multiVoice: empty (can't detect overlap without the classifier)
726
  from pyannote.core import Annotation, Segment
727
  noVoice = Annotation()
728
  multiVoice = Annotation()
729
  oneVoice = Annotation()
730
- # Sort all segments by start time
731
  all_segs = sorted(
732
  [(seg.start, seg.end, label)
733
  for label in currAnnotation.labels()
@@ -735,20 +733,42 @@ def analyze(inFileName):
735
  for seg in currAnnotation.subset([label]).itersegments()],
736
  key=lambda x: x[0]
737
  )
738
- # Fill oneVoice and detect gaps for noVoice
739
  prev_end = 0.0
740
  for start, end, label in all_segs:
741
  if start > prev_end + 0.1:
742
  noVoice[Segment(prev_end, start)] = 'silence'
743
  oneVoice[Segment(start, end)] = label
744
  prev_end = max(prev_end, end)
745
- # Trailing silence to end of file
746
  if currTotalTime > prev_end + 0.1:
747
- noVoice[Segment(prev_end, currTotalTime)] = 'silence'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
  sumNoVoice = su.sumTimes(noVoice)
749
  sumOneVoice = su.sumTimes(oneVoice)
750
  sumMultiVoice = su.sumTimes(multiVoice)
751
- print(f"DEBUG analyze({inFileName}): noVoice={sumNoVoice:.1f}s oneVoice={sumOneVoice:.1f}s multiVoice={sumMultiVoice:.1f}s total={currTotalTime:.1f}s")
752
 
753
  # df3
754
  df3 = utils.build_df3(noVoice, oneVoice, multiVoice)
 
715
  printV("Loaded results", 4)
716
 
717
  pipeline = st.session_state.pipeline
718
+ # For annotation-only files (RTTM/TXT/CSV), annotationToNoiseList
719
+ # misclassifies almost everything as multiVoice because the window-based
720
+ # classifier sees >2 speakers in every window. Instead derive voice
721
+ # categories directly from the annotation's segment gaps — more accurate
722
+ # and consistent for demo/pre-labeled files.
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()
 
729
  all_segs = sorted(
730
  [(seg.start, seg.end, label)
731
  for label in currAnnotation.labels()
 
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)
747
+ except Exception as e:
748
+ print(f"calcSpeakingTypes failed ({e}), falling back to annotation-based voice split")
749
+ from pyannote.core import Annotation, Segment
750
+ noVoice = Annotation()
751
+ multiVoice = Annotation()
752
+ oneVoice = Annotation()
753
+ all_segs = sorted(
754
+ [(seg.start, seg.end, label)
755
+ for label in currAnnotation.labels()
756
+ if label is not None and str(label).strip() != ""
757
+ for seg in currAnnotation.subset([label]).itersegments()],
758
+ key=lambda x: x[0]
759
+ )
760
+ prev_end = 0.0
761
+ for start, end, label in all_segs:
762
+ if start > prev_end + 0.1:
763
+ noVoice[Segment(prev_end, start)] = 'silence'
764
+ oneVoice[Segment(start, end)] = label
765
+ prev_end = max(prev_end, end)
766
+ if currTotalTime > prev_end + 0.1:
767
+ noVoice[Segment(prev_end, currTotalTime)] = 'silence'
768
  sumNoVoice = su.sumTimes(noVoice)
769
  sumOneVoice = su.sumTimes(oneVoice)
770
  sumMultiVoice = su.sumTimes(multiVoice)
771
+
772
 
773
  # df3
774
  df3 = utils.build_df3(noVoice, oneVoice, multiVoice)