asahi417 commited on
Commit
2dae5d5
1 Parent(s): d221d9f
Files changed (2) hide show
  1. download_audio.py +9 -11
  2. main.sh +3 -0
download_audio.py CHANGED
@@ -5,7 +5,7 @@ import zipfile
5
  import gzip
6
  import subprocess
7
  from os.path import join as p_join
8
-
9
  from tqdm import tqdm
10
  from multiprocessing import Pool
11
  from typing import Optional, Dict
@@ -126,16 +126,14 @@ def get_audio(dataframe: pd.DataFrame):
126
  print(f"wav shape:{wav.shape}")
127
  if wav.ndim > 1:
128
  wav = wav[:, 0]
129
- wav = wav[:int(end/sampling_rate * sr) + sr]
130
- if sr != sampling_rate:
131
- print(f"RESAMPLING: {wav.shape} length audio")
132
- wav = librosa.resample(wav, orig_sr=sr, target_sr=sr)
133
- if start < end <= len(wav):
134
- sf.write(features[f"{side}.path"], wav[start:end], sampling_rate)
135
- else:
136
- print(f"\n#### ERROR ####\n truncation error: {start}, {end}, {len(wav)}")
137
- cleanup(features, feature_file)
138
- return None
139
  except Exception as e:
140
  print(f"\n#### ERROR ####\n {e}")
141
  cleanup(features, feature_file)
 
5
  import gzip
6
  import subprocess
7
  from os.path import join as p_join
8
+ from math import ceil, floor
9
  from tqdm import tqdm
10
  from multiprocessing import Pool
11
  from typing import Optional, Dict
 
126
  print(f"wav shape:{wav.shape}")
127
  if wav.ndim > 1:
128
  wav = wav[:, 0]
129
+ wav = wav[floor(start / sr * sampling_rate):ceil(end / sr * sampling_rate)]
130
+ print(f"wav shape (after truncate):{wav.shape}")
131
+ # wav = wav[:int(end/sampling_rate * sr) + sr]
132
+ # if sr != sampling_rate:
133
+ # print(f"RESAMPLING: {wav.shape} length audio")
134
+ # wav = librosa.resample(wav, orig_sr=sr, target_sr=sr)
135
+ print(f"SAVING: {features[f'{side}.path']}")
136
+ sf.write(features[f"{side}.path"], wav[start:end], sr)
 
 
137
  except Exception as e:
138
  print(f"\n#### ERROR ####\n {e}")
139
  cleanup(features, feature_file)
main.sh CHANGED
@@ -5,6 +5,9 @@ rm -rf download/feature
5
  python -c 'n=41; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/feature/enA-jaA/*.json")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
6
  python -c 'n=41; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/enA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
7
  python -c 'n=41; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/jaA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
 
 
 
8
  python -c 'n=51; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/feature/enA-jaA/*.json")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
9
  python -c 'n=51; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/enA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
10
  python -c 'n=51; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/jaA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
 
5
  python -c 'n=41; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/feature/enA-jaA/*.json")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
6
  python -c 'n=41; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/enA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
7
  python -c 'n=41; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/jaA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
8
+ python -c 'n=42; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/feature/enA-jaA/*.json")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
9
+ python -c 'n=42; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/enA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
10
+ python -c 'n=42; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/jaA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
11
  python -c 'n=51; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/feature/enA-jaA/*.json")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
12
  python -c 'n=51; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/enA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'
13
  python -c 'n=51; import os; from glob import glob; tmp = [int(os.path.basename(i).split(".")[0]) for i in glob("download/audio/enA-jaA/jaA/*")]; print(len([x for x in tmp if (n-1) * 2500 <= x < n * 2500]))'