init
Browse files- download_audio.py +24 -12
- main.sh +2 -2
download_audio.py
CHANGED
@@ -92,6 +92,18 @@ def to_json_serializable(val):
|
|
92 |
return str(val)
|
93 |
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
def get_audio(dataframe: pd.DataFrame):
|
96 |
features = {"line_no": int(dataframe.pop('line_no').values[0])}
|
97 |
feature_file = p_join(cache_dir_feature, f'{features["line_no"]}.json')
|
@@ -106,10 +118,7 @@ def get_audio(dataframe: pd.DataFrame):
|
|
106 |
flag = wget(features[f"{side}.url"], output_file=features[f"{side}.path"])
|
107 |
if not flag:
|
108 |
print("\n#### ERROR: wget failure ####\n")
|
109 |
-
|
110 |
-
os.remove(feature_file)
|
111 |
-
if os.path.exists(features[f"{side}.path"]):
|
112 |
-
os.remove(features[f"{side}.path"])
|
113 |
return None
|
114 |
else:
|
115 |
try:
|
@@ -133,16 +142,13 @@ def get_audio(dataframe: pd.DataFrame):
|
|
133 |
sf.write(features[f"{side}.path"], wav["array"][start:end], wav["sampling_rate"])
|
134 |
else:
|
135 |
print(f"\n#### ERROR ####\n truncation error: {start}, {end}, {len(wav['array'])}")
|
136 |
-
|
137 |
-
if os.path.exists(feature_file):
|
138 |
-
os.remove(feature_file)
|
139 |
return None
|
140 |
except Exception as e:
|
141 |
print(f"\n#### ERROR ####\n {e}")
|
142 |
-
|
143 |
-
if os.path.exists(feature_file):
|
144 |
-
os.remove(feature_file)
|
145 |
return None
|
|
|
146 |
with open(feature_file, "w") as f:
|
147 |
json.dump(features, f)
|
148 |
return features["line_no"]
|
@@ -177,8 +183,14 @@ if __name__ == '__main__':
|
|
177 |
return json.load(f_reader)
|
178 |
|
179 |
|
180 |
-
|
181 |
-
features = [i for i in
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
print(f"push {len(features)} records to hub")
|
183 |
data_dict = {}
|
184 |
for side in sides:
|
|
|
92 |
return str(val)
|
93 |
|
94 |
|
95 |
+
def cleanup(features, feature_file):
|
96 |
+
os.remove(features[f"{side}.path"])
|
97 |
+
if os.path.exists(feature_file):
|
98 |
+
os.remove(feature_file)
|
99 |
+
for _side in sides:
|
100 |
+
if os.path.exists(features[f"{_side}.path"]):
|
101 |
+
os.remove(features[f"{_side}.path"])
|
102 |
+
# create a dummy so that we can skip from next run
|
103 |
+
with open(feature_file, "w") as f:
|
104 |
+
json.dump({"dummy": "dummy"})
|
105 |
+
|
106 |
+
|
107 |
def get_audio(dataframe: pd.DataFrame):
|
108 |
features = {"line_no": int(dataframe.pop('line_no').values[0])}
|
109 |
feature_file = p_join(cache_dir_feature, f'{features["line_no"]}.json')
|
|
|
118 |
flag = wget(features[f"{side}.url"], output_file=features[f"{side}.path"])
|
119 |
if not flag:
|
120 |
print("\n#### ERROR: wget failure ####\n")
|
121 |
+
cleanup(features, feature_file)
|
|
|
|
|
|
|
122 |
return None
|
123 |
else:
|
124 |
try:
|
|
|
142 |
sf.write(features[f"{side}.path"], wav["array"][start:end], wav["sampling_rate"])
|
143 |
else:
|
144 |
print(f"\n#### ERROR ####\n truncation error: {start}, {end}, {len(wav['array'])}")
|
145 |
+
cleanup(features, feature_file)
|
|
|
|
|
146 |
return None
|
147 |
except Exception as e:
|
148 |
print(f"\n#### ERROR ####\n {e}")
|
149 |
+
cleanup(features, feature_file)
|
|
|
|
|
150 |
return None
|
151 |
+
print(f"\n### SUCCESS! ###\n:{features['line_no']}")
|
152 |
with open(feature_file, "w") as f:
|
153 |
json.dump(features, f)
|
154 |
return features["line_no"]
|
|
|
183 |
return json.load(f_reader)
|
184 |
|
185 |
|
186 |
+
print("UPLOADING TO HF!!!")
|
187 |
+
features = [p_join(cache_dir_feature, f'{i}.json') for i in range(line_no_start, line_no_end)]
|
188 |
+
print(f"- raw feature: {len(features)}")
|
189 |
+
features = [i for i in features if os.path.exists(i)]
|
190 |
+
print(f"- path exists: {len(features)}")
|
191 |
+
features = [loader(i) for i in features]
|
192 |
+
features = [i for i in features if "dummy" not in i]
|
193 |
+
print(f"- dummy removed: {len(features)}")
|
194 |
print(f"push {len(features)} records to hub")
|
195 |
data_dict = {}
|
196 |
for side in sides:
|
main.sh
CHANGED
@@ -1,9 +1,9 @@
|
|
|
|
1 |
rm -rf download/audio
|
2 |
rm -rf download/feature
|
3 |
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]))'
|
4 |
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]))'
|
5 |
-
|
6 |
-
file_name='download/audio/enA-jaA/jaA/100020.mp3'; from datasets import Audio; a=Audio(); a.decode_example({"path": file_name, "bytes": None})
|
7 |
####################
|
8 |
# enA-jaA: 718_606 #
|
9 |
####################
|
|
|
1 |
+
export CUDA_VISIBLE_DEVICES=
|
2 |
rm -rf download/audio
|
3 |
rm -rf download/feature
|
4 |
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]))'
|
5 |
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]))'
|
6 |
+
python -c 'file_name="download/audio/enA-jaA/jaA/100020.mp3"; from datasets import Audio; a=Audio(); wav=a.decode_example({"path": file_name, "bytes": None}): print(wav)'
|
|
|
7 |
####################
|
8 |
# enA-jaA: 718_606 #
|
9 |
####################
|