George commited on
Commit
07529c3
1 Parent(s): e346195
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ rename.sh
2
+ test.py
README.md CHANGED
@@ -1,3 +1,42 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+
5
+ # Dataset Card for "george-chou/pianos_wav"
6
+ ## Requirements
7
+ ```
8
+ python 3.8-3.10
9
+ soundfile
10
+ librosa
11
+ ```
12
+
13
+ ## Usage
14
+ ```
15
+ from datasets import load_dataset
16
+
17
+ data = load_dataset("george-chou/pianos_wav", split="train")
18
+ labels = data.features['label'].names
19
+
20
+ for item in data:
21
+ print('audio info: ', item['audio'])
22
+ print('label name: ' + labels[item['label']])
23
+ ```
24
+
25
+ ## Maintenance
26
+ ```
27
+ git clone git@hf.co:datasets/george-chou/pianos_wav
28
+ ```
29
+
30
+ ## Cite
31
+ ```
32
+ @dataset{zhaorui_liu_2021_5676893,
33
+ author = {Zhaorui Liu and Zijin Li},
34
+ title = {{Music Data Sharing Platform for Computational Musicology Research (CCMUSIC DATASET)}},
35
+ month = nov,
36
+ year = 2021,
37
+ publisher = {Zenodo},
38
+ version = {1.1},
39
+ doi = {10.5281/zenodo.5676893},
40
+ url = {https://doi.org/10.5281/zenodo.5676893}
41
+ }
42
+ ```
data/1_PearlRiver.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec84513e69aa983dd60665d6e355ab3417802c4968de03a59bc5fd4f9edffea2
3
+ size 16001626
data/2_YoungChang.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91b180cc693177597cc3515e4956a22ab671bc3dd5de43df1bba588b725ebc30
3
+ size 99240728
data/3_Steinway-T.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c5b66552d1ec1f98b5580f7eb93fac0850bea9c740279c778a0a7f4a24e830e
3
+ size 61769871
data/4_Hsinghai.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ef4acb8695fe80fbf9910059da3352c0818c63b761f1c44ffe1fba3a2198227
3
+ size 35421121
data/5_Kawai.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:af45d21ce74a607a769fc8edeca82175415a42f70df19fbd0a14731e5efbbe6a
3
+ size 38260629
data/6_Steinway.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5b83de1f95d94b5f23b2636cdda1c5feb78fa576cf1e5f12827e48487c4b205
3
+ size 35046320
data/7_Kawai-G.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a51c08b58868d57a2aef708580507a63d16302133afa314472d72470fc25139
3
+ size 19742382
data/8_Yamaha.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a2ff74144de97c169edcacc77288fdc77fed2dc75a509899bb7b744be734332
3
+ size 46875645
piano_sound_quality.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import os
3
+ import wave
4
+ import zipfile
5
+ import datasets
6
+ import requests
7
+ from datasets.tasks import AudioClassification
8
+
9
+
10
+ # Once upload a new piano brand, please register its name here
11
+ _NAMES = [
12
+ "1_PearlRiver",
13
+ "2_YoungChang",
14
+ "3_Steinway-T",
15
+ "4_Hsinghai",
16
+ "5_Kawai",
17
+ "6_Steinway",
18
+ "7_Kawai-G",
19
+ "8_Yamaha",
20
+ ]
21
+
22
+ _DBNAME = os.path.basename(__file__).split('.')[0]
23
+
24
+ _HOMEPAGE = "https://huggingface.co/datasets/ccmusic-database/" + _DBNAME
25
+
26
+ _CITATION = """\
27
+ @dataset{zhaorui_liu_2021_5676893,
28
+ author = {Zhaorui Liu and Zijin Li},
29
+ title = {{Music Data Sharing Platform for Computational Musicology Research (CCMUSIC DATASET)}},
30
+ month = nov,
31
+ year = 2021,
32
+ publisher = {Zenodo},
33
+ version = {1.1},
34
+ doi = {10.5281/zenodo.5676893},
35
+ url = {https://doi.org/10.5281/zenodo.5676893}
36
+ }
37
+ """
38
+
39
+ _DESCRIPTION = """\
40
+ Piano-Sound-Quality-Database is a dataset of piano sound.
41
+ It consists of 8 kinds of pianos including
42
+ PearlRiver, YoungChang, Steinway-T, Hsinghai, Kawai, Steinway, Kawai-G, Yamaha.
43
+ Data was annotated by students from the China Conservatory of Music (CCMUSIC) in Beijing
44
+ and collected by George Chou.
45
+ """
46
+
47
+ _URLS = {piano: _HOMEPAGE + "/resolve/main/data/" +
48
+ piano + ".zip" for piano in _NAMES}
49
+
50
+
51
+ _PITCHES = {"009": "A2", "010": "A2#/B2b", "011": "B2", "100": "C1", "101": "C1#/D1b", "102": "D1", "103": "D1#/E1b",
52
+ "104": "E1", "105": "F1", "106": "F1#/G1b", "107": "G1", "108": "G1#/A1b", "109": "A1", "110": "A1#/B1b",
53
+ "111": "B1", "200": "C", "201": "C#/Db", "202": "D", "203": "D#/Eb", "204": "E", "205": "F", "206": "F#/Gb",
54
+ "207": "G", "208": "G#/Ab", "209": "A", "210": "A#/Bb", "211": "B", "300": "c", "301": "c#/db", "302": "d",
55
+ "303": "d#/eb", "304": "e", "305": "f", "306": "f#/gb", "307": "g", "308": "g#/ab", "309": "a", "310": "a#/bb",
56
+ "311": "b", "400": "c1", "401": "c1#/d1b", "402": "d1", "403": "d1#/e1b", "404": "e1", "405": "f1",
57
+ "406": "f1#/g1b", "407": "g1", "408": "g1#/a1b", "409": "a1", "410": "a1#/b1b", "411": "b1", "500": "c2",
58
+ "501": "c2#/d2b", "502": "d2", "503": "d2#/e2b", "504": "e2", "505": "f2", "506": "f2#/g2b", "507": "g2",
59
+ "508": "g2#/a2b", "509": "a2", "510": "a2#/b2b", "511": "b2", "600": "c3", "601": "c3#/d3b", "602": "d3",
60
+ "603": "d3#/e3b", "604": "e3", "605": "f3", "606": "f3#/g3b", "607": "g3", "608": "g3#/a3b", "609": "a3",
61
+ "610": "a3#/b3b", "611": "b3", "700": "c4", "701": "c4#/d4b", "702": "d4", "703": "d4#/e4b", "704": "e4",
62
+ "705": "f4", "706": "f4#/g4b", "707": "g4", "708": "g4#/a4b", "709": "a4", "710": "a4#/b4b", "711": "b4",
63
+ "800": "c5"}
64
+
65
+
66
+ class piano_sound_quality(datasets.GeneratorBasedBuilder):
67
+
68
+ def _info(self):
69
+ return datasets.DatasetInfo(
70
+ description=_DESCRIPTION,
71
+ features=datasets.Features(
72
+ {
73
+ "audio": datasets.Audio(sampling_rate=44_100),
74
+ "label": datasets.features.ClassLabel(names=_NAMES),
75
+ "pitch": datasets.Value("string"),
76
+ "duration": datasets.Value("float64"),
77
+ }
78
+ ),
79
+ supervised_keys=("audio", "label"),
80
+ homepage=_HOMEPAGE,
81
+ license="mit",
82
+ citation=_CITATION,
83
+ task_templates=[
84
+ AudioClassification(
85
+ task="audio-classification",
86
+ audio_column="audio",
87
+ label_column="label",
88
+ )
89
+ ],
90
+ )
91
+
92
+ def _get_wav_duration(self, file_bytes):
93
+ with wave.open(io.BytesIO(file_bytes), 'r') as wav_file:
94
+ frames = wav_file.getnframes()
95
+ rate = wav_file.getframerate()
96
+ duration = frames / float(rate)
97
+ return round(duration, 3)
98
+
99
+ def _read_zip(self, zip_url, wav_file_path):
100
+ resp = requests.get(zip_url)
101
+ with zipfile.ZipFile(io.BytesIO(resp.content)) as zip_file:
102
+ with zip_file.open(wav_file_path) as file:
103
+ file_data = file.read()
104
+ return self._get_wav_duration(file_data)
105
+
106
+ def _split_generators(self, dl_manager):
107
+ data_files = dl_manager.download_and_extract(_URLS)
108
+ split_generator = []
109
+
110
+ for index in _URLS.keys():
111
+ split_generator.append(
112
+ datasets.SplitGenerator(
113
+ name=index.replace('-', '_'),
114
+ gen_kwargs={
115
+ "files": dl_manager.iter_files([data_files[index]]),
116
+ },
117
+ )
118
+ )
119
+
120
+ return split_generator
121
+
122
+ def _generate_examples(self, files):
123
+ for i, path in enumerate(files):
124
+ file_name = os.path.basename(path)
125
+ if file_name.endswith(".wav"):
126
+ yield i, {
127
+ "audio": path,
128
+ "label": os.path.basename(os.path.dirname(path)),
129
+ "pitch": _PITCHES[file_name[1:4]],
130
+ "duration": self._read_zip(path.split('::')[1], path.split('::')[0].split('//')[1]),
131
+ }