Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update state.py
Browse files
state.py
CHANGED
|
@@ -719,16 +719,32 @@ def analyze(inFileName):
|
|
| 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:
|
| 723 |
-
#
|
| 724 |
-
|
|
|
|
|
|
|
| 725 |
noVoice = Annotation()
|
| 726 |
multiVoice = Annotation()
|
| 727 |
oneVoice = Annotation()
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 732 |
sumNoVoice = su.sumTimes(noVoice)
|
| 733 |
sumOneVoice = su.sumTimes(oneVoice)
|
| 734 |
sumMultiVoice = su.sumTimes(multiVoice)
|
|
|
|
| 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()
|
| 734 |
+
if label is not None and str(label).strip() != ""
|
| 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)
|