Spaces:
Sleeping
Sleeping
Catch end-of-audio cases for annotationToNoiseList
Browse files- sonogram.py +15 -4
sonogram.py
CHANGED
|
@@ -172,8 +172,13 @@ class Sonogram():
|
|
| 172 |
speakerAtStep[i] = label
|
| 173 |
return speakerAtStep, stepTime, speakerHierarchy
|
| 174 |
|
| 175 |
-
def annotationToNoiseList(self,inAnnotation,stepSize=2,windowSize=90):
|
| 176 |
sas, st, sh = self.activeSpeaker(inAnnotation,step=stepSize)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
timeStepAggregate = []
|
| 178 |
timeStepClass = []
|
| 179 |
timeStepMembers = []
|
|
@@ -219,7 +224,7 @@ class Sonogram():
|
|
| 219 |
for item in timeStepAggregate:
|
| 220 |
timeStepClass.append(max(item, key=item.get))
|
| 221 |
|
| 222 |
-
|
| 223 |
categorySegmentList = []
|
| 224 |
for c in categories:
|
| 225 |
currList = []
|
|
@@ -230,7 +235,7 @@ class Sonogram():
|
|
| 230 |
for stepClass,timeIncrement,members in zip(timeStepClass,st,timeStepMembers):
|
| 231 |
if stepClass == c:
|
| 232 |
if currMembers == members:
|
| 233 |
-
duration += stepSize
|
| 234 |
else:
|
| 235 |
if tracking:
|
| 236 |
currList.append((currMembers,Segment(start,start+duration)))
|
|
@@ -241,7 +246,7 @@ class Sonogram():
|
|
| 241 |
|
| 242 |
start = timeIncrement
|
| 243 |
currMembers = members
|
| 244 |
-
duration += stepSize
|
| 245 |
tracking = True
|
| 246 |
else:
|
| 247 |
if tracking:
|
|
@@ -253,6 +258,12 @@ class Sonogram():
|
|
| 253 |
if tracking:
|
| 254 |
currList.append((currMembers,Segment(start,start+duration)))
|
| 255 |
categorySegmentList.append(currList)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
return categorySegmentList, st
|
| 257 |
|
| 258 |
def __call__(self,audioPath):
|
|
|
|
| 172 |
speakerAtStep[i] = label
|
| 173 |
return speakerAtStep, stepTime, speakerHierarchy
|
| 174 |
|
| 175 |
+
def annotationToNoiseList(self,inAnnotation,maxTime,stepSize=2,windowSize=90):
|
| 176 |
sas, st, sh = self.activeSpeaker(inAnnotation,step=stepSize)
|
| 177 |
+
exactTimelineMatch = False
|
| 178 |
+
# Check for magical exact match to end of audio
|
| 179 |
+
if (st[-1] + stepSize) / maxTime == 1:
|
| 180 |
+
# If true, we don't have to work as hard
|
| 181 |
+
exactTimelineMatch = True
|
| 182 |
timeStepAggregate = []
|
| 183 |
timeStepClass = []
|
| 184 |
timeStepMembers = []
|
|
|
|
| 224 |
for item in timeStepAggregate:
|
| 225 |
timeStepClass.append(max(item, key=item.get))
|
| 226 |
|
| 227 |
+
|
| 228 |
categorySegmentList = []
|
| 229 |
for c in categories:
|
| 230 |
currList = []
|
|
|
|
| 235 |
for stepClass,timeIncrement,members in zip(timeStepClass,st,timeStepMembers):
|
| 236 |
if stepClass == c:
|
| 237 |
if currMembers == members:
|
| 238 |
+
duration += min(stepSize,maxTime-timeIncrement)
|
| 239 |
else:
|
| 240 |
if tracking:
|
| 241 |
currList.append((currMembers,Segment(start,start+duration)))
|
|
|
|
| 246 |
|
| 247 |
start = timeIncrement
|
| 248 |
currMembers = members
|
| 249 |
+
duration += min(stepSize,maxTime-timeIncrement)
|
| 250 |
tracking = True
|
| 251 |
else:
|
| 252 |
if tracking:
|
|
|
|
| 258 |
if tracking:
|
| 259 |
currList.append((currMembers,Segment(start,start+duration)))
|
| 260 |
categorySegmentList.append(currList)
|
| 261 |
+
# Check where we left off
|
| 262 |
+
if not exactTimelineMatch:
|
| 263 |
+
# Create silence at end if needed
|
| 264 |
+
if maxTime-st[-1] > stepSize:
|
| 265 |
+
categorySegmentList[2].append((None,Segment(st[-1] + stepSize,maxTime))
|
| 266 |
+
|
| 267 |
return categorySegmentList, st
|
| 268 |
|
| 269 |
def __call__(self,audioPath):
|