agorlanov commited on
Commit
156571b
1 Parent(s): 98065bc

denoise_diar_app

Browse files
main_pipeline.py CHANGED
@@ -1,6 +1,6 @@
1
  import librosa
2
  import torch
3
-
4
  from utils.denoise_pipeline import denoise
5
  from utils.diarization_pipeline import diarization
6
  import numpy as np
@@ -11,20 +11,20 @@ import soundfile as sf
11
 
12
  def save_speaker_audios(segments, denoised_audio_path, out_folder='out', out_f=48000):
13
  signal, sr = librosa.load(denoised_audio_path, sr=out_f, mono=True)
14
-
15
  out_wav_paths = []
16
  segments = pd.DataFrame(segments)
17
 
18
  for label in set(segments.label):
19
  temp_df = segments[segments.label == label]
20
- output_signal = np.zeros(int(len(signal)))
21
  for _, r in temp_df.iterrows():
22
  start = int(r["start"] * out_f)
23
  end = int(r["end"] * out_f)
24
  output_signal[start:end] = signal[start:end]
25
 
26
- out_wav_path = f'{label}.wav'
27
- sf.write(out_wav_path, output_signal, out_f, 'PCM_24')
28
 
29
  out_wav_paths.append(out_wav_path)
30
 
 
1
  import librosa
2
  import torch
3
+ import os
4
  from utils.denoise_pipeline import denoise
5
  from utils.diarization_pipeline import diarization
6
  import numpy as np
 
11
 
12
  def save_speaker_audios(segments, denoised_audio_path, out_folder='out', out_f=48000):
13
  signal, sr = librosa.load(denoised_audio_path, sr=out_f, mono=True)
14
+ os.makedirs(out_folder, exist_ok=True)
15
  out_wav_paths = []
16
  segments = pd.DataFrame(segments)
17
 
18
  for label in set(segments.label):
19
  temp_df = segments[segments.label == label]
20
+ output_signal = []
21
  for _, r in temp_df.iterrows():
22
  start = int(r["start"] * out_f)
23
  end = int(r["end"] * out_f)
24
  output_signal[start:end] = signal[start:end]
25
 
26
+ out_wav_path = f'{out_folder}/{label}.wav'
27
+ sf.write(out_wav_path, np.concatenate(output_signal), out_f, 'PCM_24')
28
 
29
  out_wav_paths.append(out_wav_path)
30
 
utils/diarization_pipeline.py CHANGED
@@ -12,7 +12,7 @@ class DiarizationPipeline:
12
  embed_model='ecapa', # supported types: ['xvec', 'ecapa']
13
  cluster_method='ahc', # supported types: ['ahc', 'sc']
14
  window=1, # size of window to extract embeddings (in seconds)
15
- period=0.2 # hop of window (in seconds)
16
  )
17
 
18
  def __call__(self, wav_file):
 
12
  embed_model='ecapa', # supported types: ['xvec', 'ecapa']
13
  cluster_method='ahc', # supported types: ['ahc', 'sc']
14
  window=1, # size of window to extract embeddings (in seconds)
15
+ period=0.1 # hop of window (in seconds)
16
  )
17
 
18
  def __call__(self, wav_file):