Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update state.py
Browse files
state.py
CHANGED
|
@@ -715,19 +715,17 @@ def analyze(inFileName):
|
|
| 715 |
printV("Loaded results", 4)
|
| 716 |
|
| 717 |
pipeline = st.session_state.pipeline
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 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 |
-
|
| 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)
|