update
Browse files
examples/make_idn_noise/run_batch.sh
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
: <<'END'
|
| 5 |
+
|
| 6 |
+
sh run.sh --save_date 2025-05-21
|
| 7 |
+
|
| 8 |
+
END
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
# params
|
| 12 |
+
system_version="centos";
|
| 13 |
+
verbose=true;
|
| 14 |
+
stage=0 # start from 0 if you need to start from data preparation
|
| 15 |
+
stop_stage=9
|
| 16 |
+
|
| 17 |
+
noise_dir=data/noise/id-ID
|
| 18 |
+
speech_dir=data/speech/id-ID
|
| 19 |
+
save_date=2025-05-21
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# parse options
|
| 23 |
+
while true; do
|
| 24 |
+
[ -z "${1:-}" ] && break; # break if there are no arguments
|
| 25 |
+
case "$1" in
|
| 26 |
+
--*) name=$(echo "$1" | sed s/^--// | sed s/-/_/g);
|
| 27 |
+
eval '[ -z "${'"$name"'+xxx}" ]' && echo "$0: invalid option $1" 1>&2 && exit 1;
|
| 28 |
+
old_value="(eval echo \\$$name)";
|
| 29 |
+
if [ "${old_value}" == "true" ] || [ "${old_value}" == "false" ]; then
|
| 30 |
+
was_bool=true;
|
| 31 |
+
else
|
| 32 |
+
was_bool=false;
|
| 33 |
+
fi
|
| 34 |
+
|
| 35 |
+
# Set the variable to the right value-- the escaped quotes make it work if
|
| 36 |
+
# the option had spaces, like --cmd "queue.pl -sync y"
|
| 37 |
+
eval "${name}=\"$2\"";
|
| 38 |
+
|
| 39 |
+
# Check that Boolean-valued arguments are really Boolean.
|
| 40 |
+
if $was_bool && [[ "$2" != "true" && "$2" != "false" ]]; then
|
| 41 |
+
echo "$0: expected \"true\" or \"false\": $1 $2" 1>&2
|
| 42 |
+
exit 1;
|
| 43 |
+
fi
|
| 44 |
+
shift 2;
|
| 45 |
+
;;
|
| 46 |
+
|
| 47 |
+
*) break;
|
| 48 |
+
esac
|
| 49 |
+
done
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
if [ $system_version == "windows" ]; then
|
| 53 |
+
alias python3='D:/Users/tianx/PycharmProjects/virtualenv/nx_noise/Scripts/python.exe'
|
| 54 |
+
elif [ $system_version == "centos" ] || [ $system_version == "ubuntu" ]; then
|
| 55 |
+
#source /data/local/bin/nx_noise/bin/activate
|
| 56 |
+
alias python3='/data/local/bin/nx_noise/bin/python3'
|
| 57 |
+
fi
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
python3 step_1_make_calling_noise.py --noise_dir "${noise_dir}/${save_date}"
|
| 61 |
+
|
| 62 |
+
python3 step_2_make_calling_speech.py --speech_dir "${speech_dir}/${save_date}"
|
examples/make_idn_noise/step_1_make_calling_noise.py
CHANGED
|
@@ -41,7 +41,7 @@ def get_args():
|
|
| 41 |
)
|
| 42 |
parser.add_argument(
|
| 43 |
"--noise_dir",
|
| 44 |
-
default=
|
| 45 |
type=str
|
| 46 |
)
|
| 47 |
|
|
@@ -176,17 +176,13 @@ def main():
|
|
| 176 |
)
|
| 177 |
|
| 178 |
raw_wav_zip_dir = Path(args.raw_wav_zip_dir)
|
| 179 |
-
noise_dir = Path(args.noise_dir)
|
|
|
|
| 180 |
|
| 181 |
for wav_zip_file in raw_wav_zip_dir.glob("*.zip"):
|
| 182 |
print(f"\n\nprocess zip: {wav_zip_file.as_posix()}")
|
| 183 |
-
# language = wav_zip_file.parts[-2]
|
| 184 |
-
language = "id-ID"
|
| 185 |
basename = wav_zip_file.stem
|
| 186 |
|
| 187 |
-
language_noise_dir = noise_dir / language / datetime.now().strftime("%Y-%m-%d")
|
| 188 |
-
language_noise_dir.mkdir(parents=True, exist_ok=True)
|
| 189 |
-
|
| 190 |
language_wav_dir = wav_zip_file.parent / wav_zip_file.stem
|
| 191 |
if not language_wav_dir.exists():
|
| 192 |
print(f"unzip: {wav_zip_file.as_posix()}")
|
|
@@ -202,7 +198,7 @@ def main():
|
|
| 202 |
|
| 203 |
remove_file_count = 0
|
| 204 |
noise_count = 0
|
| 205 |
-
process_bar = tqdm(desc=f"{
|
| 206 |
for filename in wav_list:
|
| 207 |
process_bar.update(n=1)
|
| 208 |
process_bar.set_postfix({
|
|
@@ -242,7 +238,7 @@ def main():
|
|
| 242 |
sub_signal_list = split_signal_by_labels(signal, labels)
|
| 243 |
|
| 244 |
for i, sub_signal_group in enumerate(sub_signal_list):
|
| 245 |
-
to_filename =
|
| 246 |
if to_filename.exists():
|
| 247 |
raise AssertionError
|
| 248 |
|
|
|
|
| 41 |
)
|
| 42 |
parser.add_argument(
|
| 43 |
"--noise_dir",
|
| 44 |
+
default="data/noise/id-ID/2025-05-21",
|
| 45 |
type=str
|
| 46 |
)
|
| 47 |
|
|
|
|
| 176 |
)
|
| 177 |
|
| 178 |
raw_wav_zip_dir = Path(args.raw_wav_zip_dir)
|
| 179 |
+
noise_dir = Path(project_path / args.noise_dir)
|
| 180 |
+
noise_dir.mkdir(parents=True, exist_ok=True)
|
| 181 |
|
| 182 |
for wav_zip_file in raw_wav_zip_dir.glob("*.zip"):
|
| 183 |
print(f"\n\nprocess zip: {wav_zip_file.as_posix()}")
|
|
|
|
|
|
|
| 184 |
basename = wav_zip_file.stem
|
| 185 |
|
|
|
|
|
|
|
|
|
|
| 186 |
language_wav_dir = wav_zip_file.parent / wav_zip_file.stem
|
| 187 |
if not language_wav_dir.exists():
|
| 188 |
print(f"unzip: {wav_zip_file.as_posix()}")
|
|
|
|
| 198 |
|
| 199 |
remove_file_count = 0
|
| 200 |
noise_count = 0
|
| 201 |
+
process_bar = tqdm(desc=f"{basename}", total=len(wav_list))
|
| 202 |
for filename in wav_list:
|
| 203 |
process_bar.update(n=1)
|
| 204 |
process_bar.set_postfix({
|
|
|
|
| 238 |
sub_signal_list = split_signal_by_labels(signal, labels)
|
| 239 |
|
| 240 |
for i, sub_signal_group in enumerate(sub_signal_list):
|
| 241 |
+
to_filename = noise_dir / "{}_{}.wav".format(filename.stem, i)
|
| 242 |
if to_filename.exists():
|
| 243 |
raise AssertionError
|
| 244 |
|
examples/make_idn_noise/step_2_make_calling_speech.py
CHANGED
|
@@ -44,7 +44,7 @@ def get_args():
|
|
| 44 |
)
|
| 45 |
parser.add_argument(
|
| 46 |
"--speech_dir",
|
| 47 |
-
default=
|
| 48 |
type=str
|
| 49 |
)
|
| 50 |
|
|
@@ -178,25 +178,20 @@ def main():
|
|
| 178 |
)
|
| 179 |
|
| 180 |
raw_wav_dir = Path(args.raw_wav_zip_dir)
|
| 181 |
-
speech_dir = Path(args.speech_dir)
|
|
|
|
| 182 |
|
| 183 |
for wav_dir in raw_wav_dir.glob("*"):
|
| 184 |
print(f"\n\nprocess wav_dir: {wav_dir.as_posix()}")
|
| 185 |
-
|
| 186 |
-
# language = wav_zip_file.parts[-2]
|
| 187 |
-
language = "id-ID"
|
| 188 |
basename = wav_dir.parts[-1]
|
| 189 |
|
| 190 |
language_wav_dir = wav_dir
|
| 191 |
-
language_speech_dir = speech_dir / language / datetime.now().strftime("%Y-%m-%d")
|
| 192 |
-
language_speech_dir.mkdir(parents=True, exist_ok=True)
|
| 193 |
-
|
| 194 |
wav_list = list(language_wav_dir.glob("**/*.wav"))
|
| 195 |
random.shuffle(wav_list)
|
| 196 |
|
| 197 |
remove_file_count = 0
|
| 198 |
speech_count = 0
|
| 199 |
-
process_bar = tqdm(desc=f"{
|
| 200 |
for filename in wav_list:
|
| 201 |
process_bar.update(n=1)
|
| 202 |
process_bar.set_postfix({
|
|
@@ -205,8 +200,6 @@ def main():
|
|
| 205 |
})
|
| 206 |
|
| 207 |
filename = Path(filename)
|
| 208 |
-
if filename.parts[-2] in ("bell", "music"):
|
| 209 |
-
continue
|
| 210 |
try:
|
| 211 |
sample_rate, signal = wavfile.read(filename)
|
| 212 |
except UnboundLocalError as e:
|
|
@@ -233,7 +226,7 @@ def main():
|
|
| 233 |
sub_signal_list = split_signal_by_labels(signal, labels)
|
| 234 |
|
| 235 |
for i, sub_signal_group in enumerate(sub_signal_list):
|
| 236 |
-
to_filename =
|
| 237 |
if to_filename.exists():
|
| 238 |
raise AssertionError
|
| 239 |
|
|
|
|
| 44 |
)
|
| 45 |
parser.add_argument(
|
| 46 |
"--speech_dir",
|
| 47 |
+
default="data/speech/id-ID/2025-05-21",
|
| 48 |
type=str
|
| 49 |
)
|
| 50 |
|
|
|
|
| 178 |
)
|
| 179 |
|
| 180 |
raw_wav_dir = Path(args.raw_wav_zip_dir)
|
| 181 |
+
speech_dir = Path(project_path / args.speech_dir)
|
| 182 |
+
speech_dir.mkdir(parents=True, exist_ok=True)
|
| 183 |
|
| 184 |
for wav_dir in raw_wav_dir.glob("*"):
|
| 185 |
print(f"\n\nprocess wav_dir: {wav_dir.as_posix()}")
|
|
|
|
|
|
|
|
|
|
| 186 |
basename = wav_dir.parts[-1]
|
| 187 |
|
| 188 |
language_wav_dir = wav_dir
|
|
|
|
|
|
|
|
|
|
| 189 |
wav_list = list(language_wav_dir.glob("**/*.wav"))
|
| 190 |
random.shuffle(wav_list)
|
| 191 |
|
| 192 |
remove_file_count = 0
|
| 193 |
speech_count = 0
|
| 194 |
+
process_bar = tqdm(desc=f"{basename}", total=len(wav_list))
|
| 195 |
for filename in wav_list:
|
| 196 |
process_bar.update(n=1)
|
| 197 |
process_bar.set_postfix({
|
|
|
|
| 200 |
})
|
| 201 |
|
| 202 |
filename = Path(filename)
|
|
|
|
|
|
|
| 203 |
try:
|
| 204 |
sample_rate, signal = wavfile.read(filename)
|
| 205 |
except UnboundLocalError as e:
|
|
|
|
| 226 |
sub_signal_list = split_signal_by_labels(signal, labels)
|
| 227 |
|
| 228 |
for i, sub_signal_group in enumerate(sub_signal_list):
|
| 229 |
+
to_filename = speech_dir / "{}_{}.wav".format(filename.stem, i)
|
| 230 |
if to_filename.exists():
|
| 231 |
raise AssertionError
|
| 232 |
|