Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,8 @@ from pyannote.core import Annotation, Segment, Timeline
|
|
| 23 |
from df.enhance import enhance, init_df
|
| 24 |
import datetime as dt
|
| 25 |
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def save_data(
|
| 28 |
config_dict: Dict[str,str], audio_paths: List[str], userid: str,
|
|
@@ -56,19 +58,28 @@ def processFile(filePath):
|
|
| 56 |
waveformList, sampleRate = su.splitIntoTimeSegments(filePath,600)
|
| 57 |
print("File loaded")
|
| 58 |
enhancedWaveformList = []
|
| 59 |
-
|
|
|
|
| 60 |
for w in waveformList:
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
print("Equalizing Audio")
|
| 66 |
waveform_gain_adjusted = su.equalizeVolume()(waveformEnhanced,sampleRate,gainWindow,minimumGain,maximumGain)
|
|
|
|
|
|
|
| 67 |
print("Audio Equalized")
|
| 68 |
print("Detecting speakers")
|
| 69 |
-
annotations = pipeline({"waveform":
|
| 70 |
print("Speakers Detected")
|
| 71 |
-
totalTimeInSeconds = int(
|
| 72 |
print("Time in seconds calculated")
|
| 73 |
return annotations, totalTimeInSeconds
|
| 74 |
|
|
@@ -265,10 +276,10 @@ except RuntimeError as e:
|
|
| 265 |
print(f"Using {device} instead.")
|
| 266 |
#device = xm.xla_device()
|
| 267 |
|
| 268 |
-
|
| 269 |
-
# Instantiate and prepare model for training.
|
| 270 |
-
dfModel, dfState, _ = init_df(model_base_dir="DeepFilterNet3")
|
| 271 |
-
dfModel.to(device)#torch.device("cuda"))
|
| 272 |
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1")
|
| 273 |
pipeline.to(device)#torch.device("cuda"))
|
| 274 |
|
|
|
|
| 23 |
from df.enhance import enhance, init_df
|
| 24 |
import datetime as dt
|
| 25 |
|
| 26 |
+
enableDenoise = False
|
| 27 |
+
earlyCleanup = True
|
| 28 |
|
| 29 |
def save_data(
|
| 30 |
config_dict: Dict[str,str], audio_paths: List[str], userid: str,
|
|
|
|
| 58 |
waveformList, sampleRate = su.splitIntoTimeSegments(filePath,600)
|
| 59 |
print("File loaded")
|
| 60 |
enhancedWaveformList = []
|
| 61 |
+
if (enableDenoise):
|
| 62 |
+
print("Denoising")
|
| 63 |
for w in waveformList:
|
| 64 |
+
if (enableDenoise):
|
| 65 |
+
newW = enhance(dfModel,dfState,w,atten_lim_db=attenLimDB).detach().cpu()
|
| 66 |
+
enhancedWaveformList.append(newW)
|
| 67 |
+
else:
|
| 68 |
+
enhancedWaveformList.append(w)
|
| 69 |
+
if (enableDenoise):
|
| 70 |
+
print("Audio denoised")
|
| 71 |
+
waveformEnhanced = su.combineWaveforms(enhancedWaveformList)
|
| 72 |
+
if (earlyCleanup):
|
| 73 |
+
del enhancedWaveformList
|
| 74 |
print("Equalizing Audio")
|
| 75 |
waveform_gain_adjusted = su.equalizeVolume()(waveformEnhanced,sampleRate,gainWindow,minimumGain,maximumGain)
|
| 76 |
+
if (earlyCleanup):
|
| 77 |
+
del waveformEnhanced
|
| 78 |
print("Audio Equalized")
|
| 79 |
print("Detecting speakers")
|
| 80 |
+
annotations = pipeline({"waveform": waveform_gain_adjusted, "sample_rate": sampleRate})
|
| 81 |
print("Speakers Detected")
|
| 82 |
+
totalTimeInSeconds = int(waveform_gain_adjusted.shape[-1]/sampleRate)
|
| 83 |
print("Time in seconds calculated")
|
| 84 |
return annotations, totalTimeInSeconds
|
| 85 |
|
|
|
|
| 276 |
print(f"Using {device} instead.")
|
| 277 |
#device = xm.xla_device()
|
| 278 |
|
| 279 |
+
if (enableDenoise):
|
| 280 |
+
# Instantiate and prepare model for training.
|
| 281 |
+
dfModel, dfState, _ = init_df(model_base_dir="DeepFilterNet3")
|
| 282 |
+
dfModel.to(device)#torch.device("cuda"))
|
| 283 |
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1")
|
| 284 |
pipeline.to(device)#torch.device("cuda"))
|
| 285 |
|