czyoung commited on
Commit
aa23222
·
verified ·
1 Parent(s): 06b6d56

Update calcSpeakingTypes()

Browse files
Files changed (1) hide show
  1. sonogram_utility.py +11 -78
sonogram_utility.py CHANGED
@@ -8,6 +8,7 @@ import torch
8
  import torchaudio
9
  import pandas as pd
10
  import datetime as dt
 
11
 
12
  def colors(n):
13
  '''
@@ -405,87 +406,19 @@ def calcCategories(myAnnotation,categories):
405
  cleanCategories.append(newCategory)
406
  return cleanCategories,extraCategories
407
 
408
- def calcSpeakingTypes(myAnnotation,maxTime):
409
- noVoice = [Segment(0,maxTime)]
410
- oneVoice = []
411
- multiVoice = []
412
- for speaker in myAnnotation.labels():
413
- timesToProcess = []
414
- for timeSegment in myAnnotation.subset([speaker]).itersegments():
415
- timesToProcess.append((speaker,timeSegment))
416
- while len(timesToProcess) > 0:
417
- currID, currSegment = timesToProcess[0]
418
- timesToProcess.remove(timesToProcess[0])
419
- resetCheck = False
420
- # Check in multi
421
- for compareID,timeSegment in multiVoice:
422
- overlapTime = checkForOverlap(currSegment,timeSegment)
423
- if overlapTime is None:
424
- continue
425
- else:
426
- compareID.append(currID)
427
- newTimes = removeOverlap(currSegment,timeSegment)
428
- for i in range(len(newTimes)):
429
- newTimes[i] = (currID,newTimes[i])
430
- timesToProcess += newTimes
431
- resetCheck = True
432
- break
433
- if resetCheck:
434
- continue
435
- # Check in one voice
436
- for timeSlot in oneVoice:
437
- tID = timeSlot[0]
438
- tSegment = timeSlot[1]
439
- overlapTime = checkForOverlap(currSegment,tSegment)
440
- if overlapTime is None:
441
- continue
442
- else:
443
- oneVoice.remove(timeSlot)
444
- # Add back non overlap
445
- newTimes = removeOverlap(tSegment,currSegment)
446
- for i in range(len(newTimes)):
447
- newTimes[i] = (tID,newTimes[i])
448
- oneVoice += newTimes
449
- # Add overlap time to multivoice
450
- multiVoice.append(([tID,currID],overlapTime))
451
- # Add new times back to process
452
- newTimes = removeOverlap(currSegment,tSegment)
453
- for i in range(len(newTimes)):
454
- newTimes[i] = (currID,newTimes[i])
455
- timesToProcess += newTimes
456
- resetCheck = True
457
- break
458
- if resetCheck:
459
- continue
460
- # Add to one voice
461
- oneVoice.append((currID,currSegment))
462
  ovAnnotation = Annotation()
463
  mvAnnotation = Annotation()
464
- for currID,timeSlot in multiVoice:
465
- currIDString = '+'.join(currID)
466
- mvAnnotation[timeSlot] = currIDString
467
- copyOfNo = copy.deepcopy(noVoice)
468
- for emptySlot in noVoice:
469
- if checkForOverlap(timeSlot,emptySlot) is None:
470
- continue
471
- else:
472
- copyOfNo.remove(emptySlot)
473
- copyOfNo += removeOverlap(emptySlot,timeSlot)
474
- noVoice = copyOfNo
475
- for currID,timeSlot in oneVoice:
476
- ovAnnotation[timeSlot] = currID
477
- copyOfNo = copy.deepcopy(noVoice)
478
- for emptySlot in noVoice:
479
- if checkForOverlap(timeSlot,emptySlot) is None:
480
- continue
481
- else:
482
- copyOfNo.remove(emptySlot)
483
- copyOfNo += removeOverlap(emptySlot,timeSlot)
484
- noVoice = copyOfNo
485
- nvAnnotation = Annotation()
486
- for emptySlot in noVoice:
487
- nvAnnotation[emptySlot] = "None"
488
 
 
 
 
 
 
 
 
 
489
  return nvAnnotation, ovAnnotation, mvAnnotation
490
 
491
  def timeToString(timeInSeconds):
 
8
  import torchaudio
9
  import pandas as pd
10
  import datetime as dt
11
+ from sonogram import Sonogram
12
 
13
  def colors(n):
14
  '''
 
406
  cleanCategories.append(newCategory)
407
  return cleanCategories,extraCategories
408
 
409
+ def calcSpeakingTypes(pipeline,myAnnotation,maxTime):
410
+ nvAnnotation = Annotation()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  ovAnnotation = Annotation()
412
  mvAnnotation = Annotation()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
 
414
+ categorySegmentList, timeSteps = pipeline.annotationToNoiseList(myAnnotation)
415
+ # [group,individual,silence], each as (start,duration)
416
+ for seg in categorySegmentList[0]:
417
+ mvAnnotation[Segment(seg[0],seg[0]+seg[1])] = 'group'
418
+ for seg in categorySegmentList[1]:
419
+ ovAnnotation[Segment(seg[0],seg[0]+seg[1])] = 'individual'
420
+ for seg in categorySegmentList[2]:
421
+ nvAnnotation[Segment(seg[0],seg[0]+seg[1])] = 'silence'
422
  return nvAnnotation, ovAnnotation, mvAnnotation
423
 
424
  def timeToString(timeInSeconds):