duongthienz commited on
Commit
8af7ee8
·
verified ·
1 Parent(s): 53bd91c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -38
app.py CHANGED
@@ -22,8 +22,7 @@ from pyannote.audio import Pipeline
22
  from pyannote.core import Annotation, Segment, Timeline
23
  import datetime as dt
24
 
25
- enableDenoise = False
26
- earlyCleanup = True
27
 
28
  # [None,Low,Medium,High,Debug]
29
  # [0,1,2,3,4]
@@ -82,37 +81,14 @@ def save_data(
82
  scheduler.append(data)
83
 
84
  def processFile(filePath):
85
- global attenLimDb
86
- global gainWindow
87
- global minimumGain
88
- global maximumGain
89
  print("Loading file")
90
- waveformList, sampleRate = su.splitIntoTimeSegments(filePath,600)
91
  print("File loaded")
92
- enhancedWaveformList = []
93
- if (enableDenoise):
94
- print("Denoising")
95
- for w in waveformList:
96
- if (enableDenoise):
97
- newW = enhance(dfModel,dfState,w,atten_lim_db=attenLimDB).detach().cpu()
98
- enhancedWaveformList.append(newW)
99
- else:
100
- enhancedWaveformList.append(w)
101
- if (enableDenoise):
102
- print("Audio denoised")
103
- waveformEnhanced = su.combineWaveforms(enhancedWaveformList)
104
- if (earlyCleanup):
105
- del enhancedWaveformList
106
- print("Equalizing Audio")
107
- waveform_gain_adjusted = su.equalizeVolume()(waveformEnhanced,sampleRate,gainWindow,minimumGain,maximumGain)
108
- if (earlyCleanup):
109
- del waveformEnhanced
110
- print("Audio Equalized")
111
  print("Detecting speakers")
112
- diarization_output = pipeline({"waveform": waveform_gain_adjusted, "sample_rate": sampleRate})
113
  annotations = diarization_output.speaker_diarization
114
  print("Speakers Detected")
115
- totalTimeInSeconds = int(waveform_gain_adjusted.shape[-1]/sampleRate)
116
  print("Time in seconds calculated")
117
  return annotations, totalTimeInSeconds
118
 
@@ -335,12 +311,6 @@ sample_data = [f"CHEM1402_gt/24F_CHEM1402_Night_Class_Week_{i}_gt.rttm" for i in
335
 
336
  scheduler = ps.ParquetScheduler(repo_id="Sonogram/SampleDataset")
337
 
338
- secondDifference = 5
339
- gainWindow = 4
340
- minimumGain = -45
341
- maximumGain = -5
342
- attenLimDB = 3
343
-
344
  isGPU = False
345
 
346
  try:
@@ -356,10 +326,6 @@ except RuntimeError as e:
356
  print(f"Using {device} instead.")
357
  #device = xm.xla_device()
358
 
359
- if (enableDenoise):
360
- # Instantiate and prepare model for training.
361
- dfModel, dfState, _ = init_df(model_base_dir="DeepFilterNet3")
362
- dfModel.to(device)#torch.device("cuda"))
363
  pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1")
364
  pipeline.to(device)#torch.device("cuda"))
365
 
 
22
  from pyannote.core import Annotation, Segment, Timeline
23
  import datetime as dt
24
 
25
+
 
26
 
27
  # [None,Low,Medium,High,Debug]
28
  # [0,1,2,3,4]
 
81
  scheduler.append(data)
82
 
83
  def processFile(filePath):
 
 
 
 
84
  print("Loading file")
85
+ waveform, sampleRate = torchaudio.load(filePath)
86
  print("File loaded")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  print("Detecting speakers")
88
+ diarization_output = pipeline({"waveform": waveform, "sample_rate": sampleRate})
89
  annotations = diarization_output.speaker_diarization
90
  print("Speakers Detected")
91
+ totalTimeInSeconds = int(waveform.shape[-1] / sampleRate)
92
  print("Time in seconds calculated")
93
  return annotations, totalTimeInSeconds
94
 
 
311
 
312
  scheduler = ps.ParquetScheduler(repo_id="Sonogram/SampleDataset")
313
 
 
 
 
 
 
 
314
  isGPU = False
315
 
316
  try:
 
326
  print(f"Using {device} instead.")
327
  #device = xm.xla_device()
328
 
 
 
 
 
329
  pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1")
330
  pipeline.to(device)#torch.device("cuda"))
331