forked from OFAI/vienna4x22_rematched
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_audio.py
67 lines (51 loc) · 1.82 KB
/
setup_audio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Setup audio files for the Vienna4x22 dataset.
"""
import os
import glob
from shutil import copyfile
import argparse
# Download audio files from here!
# TODO: download files automatically
AUDIO_URL = (
"http://repo.mdw.ac.at/projects/IWK/the_vienna_4x22_piano_corpus/data/audio.zip"
)
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
MIDI_DIR = os.path.join(CURRENT_DIR, "midi")
MATCH_DIR = os.path.join(CURRENT_DIR, "match")
if __name__ == "__main__":
parser = argparse.ArgumentParser(
"Setup Audio recordings for the Vienna 4x22 dataset"
)
parser.add_argument(
"--audio-dir",
"-a",
default=None,
help="Path to the audio files",
)
args = parser.parse_args()
if args.audio_dir is None:
# download_file
raise ValueError("Path to the audio files is required!")
target_dir = os.path.join(CURRENT_DIR, "audio")
if not os.path.join(target_dir):
os.mkdir(target_dir)
audiofiles = glob.glob(os.path.join(args.audio_dir, "*", "*.wav"))
audiofiles.sort()
for i, audio_fn in enumerate(audiofiles):
piece = os.path.basename(audio_fn).replace(".wav", "")
match_fn = os.path.join(MATCH_DIR, f"{piece}.match")
target_audio_fn = os.path.join(target_dir, os.path.basename(audio_fn))
# Ignore files for which there is no corresponding
# match file (i.e., average, special takes...)
# Only copy file if it does not exist already
if os.path.exists(match_fn) and not os.path.exists(target_audio_fn):
print(f"copying {audio_fn} to {target_audio_fn}...")
copyfile(
src=audio_fn,
dst=target_audio_fn,
)
else:
print(f"No corresponding match file for {audio_fn}!")