My commit
Browse files
NSynth.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import json
|
2 |
import datasets
|
3 |
import os
|
4 |
-
import
|
5 |
|
6 |
_CITATION = """\
|
7 |
@misc{nsynth2017,
|
@@ -16,18 +16,18 @@ _CITATION = """\
|
|
16 |
|
17 |
_DESCRIPTION = """\
|
18 |
The NSynth dataset is an audio dataset containing over 300,000 musical notes across over 1000 commercially-sampled instruments, distinguished by pitch, timbre, and envelope. Each recording was made by playing and holding a musical note for three seconds and letting it decay for one second. The collection of four-second recordings ranges over every pitch on a standard MIDI piano (or as many as possible for the given instrument), played at five different velocities.
|
19 |
-
|
20 |
This dataset was created as an attempt to establish a high-quality entry point into audio machine learning, in response to the surge of breakthroughs in generative modeling of images due to the abundance of approachable image datasets (MNIST, CIFAR, ImageNet). NSynth is meant to be both a benchmark for audio ML and a foundation to be expanded on with future datasets.
|
21 |
-
|
22 |
"""
|
23 |
|
24 |
_HOMEPAGE = "https://magenta.tensorflow.org/datasets/nsynth#note-qualities"
|
25 |
|
26 |
_LICENSE = "Creative Commons Attribution 4.0 International (CC BY 4.0)"
|
27 |
|
|
|
28 |
class NSynth(datasets.GeneratorBasedBuilder):
|
29 |
def _info(self):
|
30 |
features = datasets.Features({
|
|
|
31 |
"note": datasets.Value("int64"),
|
32 |
"note_str": datasets.Value("string"),
|
33 |
"instrument": datasets.Value("int64"),
|
@@ -41,68 +41,60 @@ class NSynth(datasets.GeneratorBasedBuilder):
|
|
41 |
"instrument_family_str": datasets.Value("string"),
|
42 |
"instrument_source": datasets.Value("int64"),
|
43 |
"instrument_source_str": datasets.Value("string"),
|
44 |
-
"audio": datasets.features.Audio(
|
45 |
-
|
46 |
return datasets.DatasetInfo(
|
47 |
description=_DESCRIPTION,
|
48 |
features=features,
|
49 |
homepage=_HOMEPAGE,
|
50 |
license=_LICENSE,
|
51 |
citation=_CITATION,
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
"qualities": key["qualities"],
|
102 |
-
"qualities_str": key["qualities_str"],
|
103 |
-
"instrument_family": key["instrument_family"],
|
104 |
-
"instrument_family_str": key["instrument_family_str"],
|
105 |
-
"instrument_source": key["instrument_source"],
|
106 |
-
"instrument_source_str": key["instrument_source_str"],
|
107 |
-
"audio": wav_dict[key]
|
108 |
-
}
|
|
|
1 |
import json
|
2 |
import datasets
|
3 |
import os
|
4 |
+
from scipy.io import wavfile
|
5 |
|
6 |
_CITATION = """\
|
7 |
@misc{nsynth2017,
|
|
|
16 |
|
17 |
_DESCRIPTION = """\
|
18 |
The NSynth dataset is an audio dataset containing over 300,000 musical notes across over 1000 commercially-sampled instruments, distinguished by pitch, timbre, and envelope. Each recording was made by playing and holding a musical note for three seconds and letting it decay for one second. The collection of four-second recordings ranges over every pitch on a standard MIDI piano (or as many as possible for the given instrument), played at five different velocities.
|
|
|
19 |
This dataset was created as an attempt to establish a high-quality entry point into audio machine learning, in response to the surge of breakthroughs in generative modeling of images due to the abundance of approachable image datasets (MNIST, CIFAR, ImageNet). NSynth is meant to be both a benchmark for audio ML and a foundation to be expanded on with future datasets.
|
|
|
20 |
"""
|
21 |
|
22 |
_HOMEPAGE = "https://magenta.tensorflow.org/datasets/nsynth#note-qualities"
|
23 |
|
24 |
_LICENSE = "Creative Commons Attribution 4.0 International (CC BY 4.0)"
|
25 |
|
26 |
+
|
27 |
class NSynth(datasets.GeneratorBasedBuilder):
|
28 |
def _info(self):
|
29 |
features = datasets.Features({
|
30 |
+
"id": datasets.Value("string"),
|
31 |
"note": datasets.Value("int64"),
|
32 |
"note_str": datasets.Value("string"),
|
33 |
"instrument": datasets.Value("int64"),
|
|
|
41 |
"instrument_family_str": datasets.Value("string"),
|
42 |
"instrument_source": datasets.Value("int64"),
|
43 |
"instrument_source_str": datasets.Value("string"),
|
44 |
+
"audio": datasets.features.Audio()
|
45 |
+
})
|
46 |
return datasets.DatasetInfo(
|
47 |
description=_DESCRIPTION,
|
48 |
features=features,
|
49 |
homepage=_HOMEPAGE,
|
50 |
license=_LICENSE,
|
51 |
citation=_CITATION,
|
52 |
+
)
|
53 |
+
def _split_generators(self, dl_manager):
|
54 |
+
dl_paths = dl_manager.download_and_extract({
|
55 |
+
'train': 'http://download.magenta.tensorflow.org/datasets/nsynth/nsynth-train.jsonwav.tar.gz',
|
56 |
+
'validation': 'http://download.magenta.tensorflow.org/datasets/nsynth/nsynth-valid.jsonwav.tar.gz',
|
57 |
+
'test': 'http://download.magenta.tensorflow.org/datasets/nsynth/nsynth-test.jsonwav.tar.gz',
|
58 |
+
})
|
59 |
+
return[
|
60 |
+
datasets.SplitGenerator(
|
61 |
+
name=datasets.Split.TRAIN,
|
62 |
+
gen_kwargs={"filepath": dl_paths['train']}
|
63 |
+
),
|
64 |
+
datasets.SplitGenerator(
|
65 |
+
name=datasets.Split.VALIDATION,
|
66 |
+
gen_kwargs={"filepath": dl_paths['validation']}
|
67 |
+
),
|
68 |
+
datasets.SplitGenerator(
|
69 |
+
name=datasets.Split.TEST,
|
70 |
+
gen_kwargs={"filepath": dl_paths['test']}
|
71 |
+
),
|
72 |
+
]
|
73 |
+
def _generate_examples(self, filepath):
|
74 |
+
dir_list = os.listdir(filepath)
|
75 |
+
folder_path = os.path.join(filepath, dir_list[0])
|
76 |
+
examples_path = os.path.join(folder_path, 'examples.json')
|
77 |
+
with open(examples_path) as examples_file:
|
78 |
+
examples = json.load(examples_file)
|
79 |
+
wav_dict = {}
|
80 |
+
audio_path = os.path.join(folder_path, "audio")
|
81 |
+
for filename in os.listdir(audio_path):
|
82 |
+
audio_filename = os.path.join(audio_path, filename)
|
83 |
+
key = filename.replace('.wav', '')
|
84 |
+
yield key, {
|
85 |
+
"id": key,
|
86 |
+
"note": examples[key]["note"],
|
87 |
+
"note_str": examples[key]["note_str"],
|
88 |
+
"instrument": examples[key]["instrument"],
|
89 |
+
"instrument_str": examples[key]["instrument_str"],
|
90 |
+
"pitch": examples[key]["pitch"],
|
91 |
+
"velocity": examples[key]["velocity"],
|
92 |
+
"sample_rate": examples[key]["sample_rate"],
|
93 |
+
"qualities": examples[key]["qualities"],
|
94 |
+
"qualities_str": examples[key]["qualities_str"],
|
95 |
+
"instrument_family": examples[key]["instrument_family"],
|
96 |
+
"instrument_family_str": examples[key]["instrument_family_str"],
|
97 |
+
"instrument_source": examples[key]["instrument_source"],
|
98 |
+
"instrument_source_str": examples[key]["instrument_source_str"],
|
99 |
+
"audio": {'path': audio_filename, 'bytes': wavfile.read(audio_filename)[1]}
|
100 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|