asahi417 commited on
Commit
981a6f2
·
1 Parent(s): 5b6fcfd
Files changed (2) hide show
  1. download_audio.py +9 -5
  2. main.sh +40 -11
download_audio.py CHANGED
@@ -10,6 +10,7 @@ from multiprocessing import Pool
10
  from typing import Optional, Dict
11
  from glob import glob
12
 
 
13
  import pandas as pd
14
  import soundfile as sf
15
  from datasets import Dataset, Audio, DatasetDict
@@ -29,14 +30,15 @@ for s in sides:
29
  os.makedirs(p_join(cache_dir_audio, s), exist_ok=True)
30
  # processor config
31
  n_pool = int(os.getenv("N_POOL", 1))
32
- wget_max_retry = os.getenv("MAX_RETRY", "1")
33
- wget_timeout = os.getenv("TIMEOUT", "10")
34
  line_no_start = int(os.getenv("LINE_NO_START", 0))
35
  line_no_end = int(os.getenv("LINE_NO_END", 10000))
36
  dataset_id = os.getenv("DATASET_ID", 0)
37
  hf_org = os.getenv("HF_ORG", "asahi417")
38
  hf_dataset = f"seamless-align-{direction}"
39
- skip_wget = bool(int(os.getenv("SKIP_WGET", 0)))
 
40
 
41
 
42
  def wget(url: str, output_file: Optional[str] = None):
@@ -107,6 +109,9 @@ def get_audio(dataframe: pd.DataFrame):
107
  else:
108
  try:
109
  wav = audio_loader.decode_example({"path": features[f"{side}.path"], "bytes": None})
 
 
 
110
  if start < end < len(wav["array"]):
111
  sf.write(features[f"{side}.path"], wav["array"][start:end], wav["sampling_rate"])
112
  else:
@@ -126,7 +131,7 @@ def get_audio(dataframe: pd.DataFrame):
126
 
127
 
128
  if __name__ == '__main__':
129
- if not skip_wget:
130
  df_metadata = get_metadata()
131
  print(f"metadata: {len(df_metadata)}, {line_no_start} --> {line_no_end}")
132
  inputs = [
@@ -135,7 +140,6 @@ if __name__ == '__main__':
135
  p_join(cache_dir_feature, f'{int(line_no)}.json')
136
  )
137
  ]
138
- # inputs = [g for line_no, g in df_metadata.groupby("line_no") if line_no_start <= line_no < line_no_end]
139
  print(f"filtered unique lines: {len(inputs)}")
140
  if direction == "enA-jaA":
141
  inputs = [g for g in inputs if len(g["side"].unique()) == 2 and set(g["side"].unique()) == sides]
 
10
  from typing import Optional, Dict
11
  from glob import glob
12
 
13
+ import julius
14
  import pandas as pd
15
  import soundfile as sf
16
  from datasets import Dataset, Audio, DatasetDict
 
30
  os.makedirs(p_join(cache_dir_audio, s), exist_ok=True)
31
  # processor config
32
  n_pool = int(os.getenv("N_POOL", 1))
33
+ wget_max_retry = os.getenv("MAX_RETRY", "2")
34
+ wget_timeout = os.getenv("TIMEOUT", "20")
35
  line_no_start = int(os.getenv("LINE_NO_START", 0))
36
  line_no_end = int(os.getenv("LINE_NO_END", 10000))
37
  dataset_id = os.getenv("DATASET_ID", 0)
38
  hf_org = os.getenv("HF_ORG", "asahi417")
39
  hf_dataset = f"seamless-align-{direction}"
40
+ skip_download = bool(int(os.getenv("SKIP_DOWNLOAD", 0)))
41
+ sampling_rate = 16000 # seamless-align aligns audio in 16kHz
42
 
43
 
44
  def wget(url: str, output_file: Optional[str] = None):
 
109
  else:
110
  try:
111
  wav = audio_loader.decode_example({"path": features[f"{side}.path"], "bytes": None})
112
+ if wav["sampling_rate"] != sampling_rate:
113
+ wav["array"] = julius.resample_frac(wav["array"], wav["sampling_rate"], sampling_rate)
114
+ wav["sampling_rate"] = sampling_rate
115
  if start < end < len(wav["array"]):
116
  sf.write(features[f"{side}.path"], wav["array"][start:end], wav["sampling_rate"])
117
  else:
 
131
 
132
 
133
  if __name__ == '__main__':
134
+ if not skip_download:
135
  df_metadata = get_metadata()
136
  print(f"metadata: {len(df_metadata)}, {line_no_start} --> {line_no_end}")
137
  inputs = [
 
140
  p_join(cache_dir_feature, f'{int(line_no)}.json')
141
  )
142
  ]
 
143
  print(f"filtered unique lines: {len(inputs)}")
144
  if direction == "enA-jaA":
145
  inputs = [g for g in inputs if len(g["side"].unique()) == 2 and set(g["side"].unique()) == sides]
main.sh CHANGED
@@ -2,38 +2,33 @@
2
  # enA-jaA: 718_606 #
3
  ####################
4
  # TODO: 4, 6, 24, 25, 26
5
- export DATASET_ID=4
6
- export DIRECTION="enA-jaA"
7
- export LINE_NO_START=$(((DATASET_ID-1) * 5000))
8
- export LINE_NO_END=$((DATASET_ID * 5000))
9
- python download_audio.py
10
 
11
- export DATASET_ID=6
12
  export DIRECTION="enA-jaA"
13
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
14
  export LINE_NO_END=$((DATASET_ID * 5000))
15
  python download_audio.py
16
 
17
- export DATASET_ID=8
18
  export DIRECTION="enA-jaA"
19
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
20
  export LINE_NO_END=$((DATASET_ID * 5000))
21
  python download_audio.py
22
 
23
- export DATASET_ID=10
24
  export DIRECTION="enA-jaA"
25
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
26
  export LINE_NO_END=$((DATASET_ID * 5000))
27
  python download_audio.py
28
 
29
-
30
- export DATASET_ID=11
31
  export DIRECTION="enA-jaA"
32
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
33
  export LINE_NO_END=$((DATASET_ID * 5000))
34
  python download_audio.py
35
 
36
- export DATASET_ID=13
37
  export DIRECTION="enA-jaA"
38
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
39
  export LINE_NO_END=$((DATASET_ID * 5000))
@@ -71,12 +66,45 @@ export LINE_NO_START=$(((DATASET_ID-1) * 5000))
71
  export LINE_NO_END=$((DATASET_ID * 5000))
72
  python download_audio.py
73
 
 
 
 
 
 
 
74
  export DATASET_ID=25
75
  export DIRECTION="enA-jaA"
76
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
77
  export LINE_NO_END=$((DATASET_ID * 5000))
78
  python download_audio.py
79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  for i in $(seq 60 64);
82
  do
@@ -89,6 +117,7 @@ do
89
  done
90
 
91
 
 
92
  for i in $(seq 65 72);
93
  do
94
  export DATASET_ID=${i}
 
2
  # enA-jaA: 718_606 #
3
  ####################
4
  # TODO: 4, 6, 24, 25, 26
5
+ export N_POOL=1
 
 
 
 
6
 
7
+ export DATASET_ID=26
8
  export DIRECTION="enA-jaA"
9
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
10
  export LINE_NO_END=$((DATASET_ID * 5000))
11
  python download_audio.py
12
 
13
+ export DATASET_ID=6
14
  export DIRECTION="enA-jaA"
15
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
16
  export LINE_NO_END=$((DATASET_ID * 5000))
17
  python download_audio.py
18
 
19
+ export DATASET_ID=9
20
  export DIRECTION="enA-jaA"
21
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
22
  export LINE_NO_END=$((DATASET_ID * 5000))
23
  python download_audio.py
24
 
25
+ export DATASET_ID=12
 
26
  export DIRECTION="enA-jaA"
27
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
28
  export LINE_NO_END=$((DATASET_ID * 5000))
29
  python download_audio.py
30
 
31
+ export DATASET_ID=14
32
  export DIRECTION="enA-jaA"
33
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
34
  export LINE_NO_END=$((DATASET_ID * 5000))
 
66
  export LINE_NO_END=$((DATASET_ID * 5000))
67
  python download_audio.py
68
 
69
+ export DATASET_ID=24
70
+ export DIRECTION="enA-jaA"
71
+ export LINE_NO_START=$(((DATASET_ID-1) * 5000))
72
+ export LINE_NO_END=$((DATASET_ID * 5000))
73
+ python download_audio.py
74
+
75
  export DATASET_ID=25
76
  export DIRECTION="enA-jaA"
77
  export LINE_NO_START=$(((DATASET_ID-1) * 5000))
78
  export LINE_NO_END=$((DATASET_ID * 5000))
79
  python download_audio.py
80
 
81
+ export DATASET_ID=26
82
+ export DIRECTION="enA-jaA"
83
+ export LINE_NO_START=$(((DATASET_ID-1) * 5000))
84
+ export LINE_NO_END=$((DATASET_ID * 5000))
85
+ python download_audio.py
86
+
87
+
88
+ for i in $(seq 50 54);
89
+ do
90
+ export DATASET_ID=${i}
91
+ export DIRECTION="enA-jaA"
92
+ export LINE_NO_START=$(((DATASET_ID-1) * 5000))
93
+ export LINE_NO_END=$((DATASET_ID * 5000
94
+ echo ${LINE_NO_START}
95
+ python download_audio.py &
96
+ done
97
+
98
+ for i in $(seq 55 59);
99
+ do
100
+ export DATASET_ID=${i}
101
+ export DIRECTION="enA-jaA"
102
+ export LINE_NO_START=$(((DATASET_ID-1) * 5000))
103
+ export LINE_NO_END=$((DATASET_ID * 5000))
104
+ echo ${LINE_NO_START}
105
+ python download_audio.py &
106
+ done
107
+
108
 
109
  for i in $(seq 60 64);
110
  do
 
117
  done
118
 
119
 
120
+
121
  for i in $(seq 65 72);
122
  do
123
  export DATASET_ID=${i}