davesalvi commited on
Commit
d50110e
·
1 Parent(s): 2878726

LCNN fs 22050

Browse files
Files changed (2) hide show
  1. preprocess.py +5 -4
  2. script.py +3 -2
preprocess.py CHANGED
@@ -15,7 +15,7 @@ def pad_audio(x, max_len=48000):
15
  return padded_x
16
 
17
 
18
- def preprocess(audio_file):
19
  print(f'Preprocessing {audio_file}')
20
  # Load the audio file
21
  # y, sr = librosa.load(audio_file, sr=16000)
@@ -26,12 +26,13 @@ def preprocess(audio_file):
26
  if y.ndim > 1:
27
  y = np.mean(y, axis=1)
28
 
29
- y = librosa.resample(y, orig_sr=sr_orig, target_sr=16000)
30
- sr = 16000
 
31
 
32
  # Evaluate N windows of the audio file
33
  num_eval = 5
34
- win_len = int(4*sr)
35
  last_sample = len(y) - win_len
36
  # start_sample_list = np.linspace(0, max(0, last_sample), num=num_eval)
37
  start_sample_list = [random.randint(0, max(0, last_sample)) for _ in range(num_eval)]
 
15
  return padded_x
16
 
17
 
18
+ def preprocess(audio_file, target_sr=16000, win_dur=4):
19
  print(f'Preprocessing {audio_file}')
20
  # Load the audio file
21
  # y, sr = librosa.load(audio_file, sr=16000)
 
26
  if y.ndim > 1:
27
  y = np.mean(y, axis=1)
28
 
29
+ if not sr_orig == target_sr:
30
+ y = librosa.resample(y, orig_sr=sr_orig, target_sr=target_sr)
31
+ sr = target_sr
32
 
33
  # Evaluate N windows of the audio file
34
  num_eval = 5
35
+ win_len = int(win_dur*sr)
36
  last_sample = len(y) - win_len
37
  # start_sample_list = np.linspace(0, max(0, last_sample), num=num_eval)
38
  start_sample_list = [random.randint(0, max(0, last_sample)) for _ in range(num_eval)]
script.py CHANGED
@@ -57,7 +57,8 @@ model = LCNN(return_emb=False).to(device)
57
  # model_path = './checkpoints/LCNN_ALL_DATA.pth'
58
  # model_path = './checkpoints/LCNN_ALL_DATA_AUG.pth'
59
  # model_path = './checkpoints/LCNN_ALL_DATA_TTS_AUG.pth'
60
- model_path = './checkpoints/LCNN_ALL_DATA_TTS_MOD.pth'
 
61
  model.load_state_dict(torch.load(model_path, map_location=device))
62
 
63
  # # MOE MODEL
@@ -127,7 +128,7 @@ for el in tqdm.tqdm(dataset_remote):
127
 
128
  # RUNNING ON HUGGINGFACE
129
  file_like = io.BytesIO(el["audio"]["bytes"])
130
- tensor, sr = preprocess(file_like)
131
  # # RUNNING LOCALLY
132
  # tensor = preprocess(el)
133
 
 
57
  # model_path = './checkpoints/LCNN_ALL_DATA.pth'
58
  # model_path = './checkpoints/LCNN_ALL_DATA_AUG.pth'
59
  # model_path = './checkpoints/LCNN_ALL_DATA_TTS_AUG.pth'
60
+ # model_path = './checkpoints/LCNN_ALL_DATA_TTS_MOD.pth'
61
+ model_path = './checkpoints/LCNN_ALL_DATA_HI_FREQ_22050.pth'
62
  model.load_state_dict(torch.load(model_path, map_location=device))
63
 
64
  # # MOE MODEL
 
128
 
129
  # RUNNING ON HUGGINGFACE
130
  file_like = io.BytesIO(el["audio"]["bytes"])
131
+ tensor, sr = preprocess(file_like, target_sr=22050)
132
  # # RUNNING LOCALLY
133
  # tensor = preprocess(el)
134