monetjoe commited on
Commit
5c46e76
1 Parent(s): 9fa2677

Upload instrument_timbre.py

Browse files
Files changed (1) hide show
  1. instrument_timbre.py +212 -212
instrument_timbre.py CHANGED
@@ -1,212 +1,212 @@
1
- import os
2
- import datasets
3
- import pandas as pd
4
- from datasets.tasks import AudioClassification
5
-
6
-
7
- _NAMES = [
8
- # Chinese
9
- "gao_hu",
10
- "er_hu",
11
- "zhong_hu",
12
- "ge_hu",
13
- "di_yin_ge_hu",
14
- "jing_hu",
15
- "ban_hu",
16
- "bang_di",
17
- "qu_di",
18
- "xin_di",
19
- "da_di",
20
- "gao_yin_sheng",
21
- "zhong_yin_sheng",
22
- "di_yin_sheng",
23
- "gao_yin_suo_na",
24
- "zhong_yin_suo_na",
25
- "ci_zhong_yin_suo_na",
26
- "di_yin_suo_na",
27
- "gao_yin_guan",
28
- "zhong_yin_guan",
29
- "di_yin_guan",
30
- "bei_di_yin_guan",
31
- "ba_wu",
32
- "xun",
33
- "xiao",
34
- "liu_qin",
35
- "xiao_ruan",
36
- "pi_pa",
37
- "yang_qin",
38
- "zhong_ruan",
39
- "da_ruan",
40
- "gu_zheng",
41
- "gu_qin",
42
- "kong_hou",
43
- "san_xian",
44
- "yun_luo",
45
- "bian_zhong",
46
- # Non-Chinese
47
- "violin",
48
- "viola",
49
- "cello",
50
- "double_bass",
51
- "piccolo",
52
- "flute",
53
- "oboe",
54
- "clarinet",
55
- "bassoon",
56
- "saxophone",
57
- "trumpet",
58
- "trombone",
59
- "horn",
60
- "tuba",
61
- "harp",
62
- "tubular_bells",
63
- "bells",
64
- "xylophone",
65
- "vibraphone",
66
- "marimba",
67
- "piano",
68
- "clavichord",
69
- "accordion",
70
- "organ",
71
- ]
72
-
73
- _DBNAME = os.path.basename(__file__).split(".")[0]
74
-
75
- _DOMAIN = f"https://www.modelscope.cn/api/v1/datasets/ccmusic/{_DBNAME}/repo?Revision=master&FilePath=data"
76
-
77
- _HOMEPAGE = f"https://www.modelscope.cn/datasets/ccmusic/{_DBNAME}"
78
-
79
- _CITATION = """\
80
- @dataset{zhaorui_liu_2021_5676893,
81
- author = {Monan Zhou, Shenyang Xu, Zhaorui Liu, Zhaowen Wang, Feng Yu, Wei Li and Baoqiang Han},
82
- title = {CCMusic: an Open and Diverse Database for Chinese and General Music Information Retrieval Research},
83
- month = {mar},
84
- year = {2024},
85
- publisher = {HuggingFace},
86
- version = {1.2},
87
- url = {https://huggingface.co/ccmusic-database}
88
- }
89
- """
90
-
91
- _DESCRIPTION = """\
92
- The raw dataset encompasses subjective timbre evaluation scores comprising 16 terms, such as bright, dark, raspy, etc, evaluated across 37 Chinese instruments and 24 Western instruments by 14 participants with musical backgrounds in a subjective evaluation experiment. Additionally, it includes 10 reports on spectrogram analysis of 10 instruments.
93
-
94
- During the integration, we have crafted the Chinese part and the Non-Chinese part into two splits. Each split is composed of multiple data entries, with each entry structured across 18 columns. The Chinese split encompasses 37 entries, while the Non-Chinese split includes 24 entries. The premier column of each data entry presents the instrument recordings in the .wav format, sampled at a rate of 44,100 Hz. The second column provides the Chinese pinyin or English name of the instrument. The subsequent 16 columns correspond to the 10-point score of the 16 terms. This dataset is suitable for conducting timber analysis of musical instruments and can also be utilized for various single or multiple regression tasks related to term scoring.
95
- """
96
-
97
- _URLS = {
98
- "audio": f"{_DOMAIN}/audio.zip",
99
- "mel": f"{_DOMAIN}/mel.zip",
100
- "csv": f"{_DOMAIN}/Chinese.csv",
101
- "label": f"{_DOMAIN}/Non-Chinese.csv",
102
- }
103
-
104
-
105
- class instrument_timbre(datasets.GeneratorBasedBuilder):
106
- def _info(self):
107
- return datasets.DatasetInfo(
108
- description=_DESCRIPTION,
109
- features=datasets.Features(
110
- {
111
- "audio": datasets.Audio(sampling_rate=22050),
112
- "mel": datasets.Image(),
113
- "instrument_name": datasets.features.ClassLabel(names=_NAMES),
114
- "slim": datasets.Value("float64"),
115
- "bright": datasets.Value("float64"),
116
- "dim": datasets.Value("float64"),
117
- "sharp": datasets.Value("float64"),
118
- "thick": datasets.Value("float64"),
119
- "thin": datasets.Value("float64"),
120
- "solid": datasets.Value("float64"),
121
- "clear": datasets.Value("float64"),
122
- "dry": datasets.Value("float64"),
123
- "plump": datasets.Value("float64"),
124
- "rough": datasets.Value("float64"),
125
- "pure": datasets.Value("float64"),
126
- "hoarse": datasets.Value("float64"),
127
- "harmonious": datasets.Value("float64"),
128
- "soft": datasets.Value("float64"),
129
- "turbid": datasets.Value("float64"),
130
- }
131
- ),
132
- supervised_keys=("audio", "instrument_name"),
133
- homepage=_HOMEPAGE,
134
- license="mit",
135
- citation=_CITATION,
136
- task_templates=[
137
- AudioClassification(
138
- task="audio-classification",
139
- audio_column="audio",
140
- label_column="instrument_name",
141
- )
142
- ],
143
- )
144
-
145
- def _split_generators(self, dl_manager):
146
- audio_files = dl_manager.download_and_extract(_URLS["audio"])
147
- mel_files = dl_manager.download_and_extract(_URLS["mel"])
148
- cn_ins_eval = dl_manager.download(_URLS["csv"])
149
- ins_eval = dl_manager.download(_URLS["label"])
150
-
151
- cn_labels = pd.read_csv(cn_ins_eval, index_col="instrument_id")
152
- labels = pd.read_csv(ins_eval, index_col="instrument_id")
153
- cn_dataset, dataset = {}, {}
154
-
155
- for path in dl_manager.iter_files([audio_files]):
156
- fname = os.path.basename(path)
157
- ins_id = int(fname.split(".wa")[0]) - 1
158
- if fname.endswith(".wav"):
159
- if os.path.basename(os.path.dirname(path)) == "Chinese":
160
- cn_dataset[ins_id] = {"audio": path}
161
- else:
162
- dataset[ins_id] = {"audio": path}
163
-
164
- for path in dl_manager.iter_files([mel_files]):
165
- fname = os.path.basename(path)
166
- ins_id = int(fname.split(".jp")[0]) - 1
167
- if fname.endswith(".jpg"):
168
- if os.path.basename(os.path.dirname(path)) == "Chinese":
169
- cn_dataset[ins_id]["mel"] = path
170
- else:
171
- dataset[ins_id]["mel"] = path
172
-
173
- return [
174
- datasets.SplitGenerator(
175
- name="Chinese",
176
- gen_kwargs={
177
- "files": [cn_dataset[k] for k in sorted(cn_dataset)],
178
- "labels": cn_labels,
179
- },
180
- ),
181
- datasets.SplitGenerator(
182
- name="Non_Chinese",
183
- gen_kwargs={
184
- "files": [dataset[k] for k in sorted(dataset)],
185
- "labels": labels,
186
- },
187
- ),
188
- ]
189
-
190
- def _generate_examples(self, files, labels: pd.DataFrame):
191
- for i, path in enumerate(files):
192
- yield i, {
193
- "audio": path["audio"],
194
- "mel": path["mel"],
195
- "instrument_name": labels.iloc[i]["instrument_name"],
196
- "slim": labels.iloc[i]["slim"],
197
- "bright": labels.iloc[i]["bright"],
198
- "dim": labels.iloc[i]["dim"],
199
- "sharp": labels.iloc[i]["sharp"],
200
- "thick": labels.iloc[i]["thick"],
201
- "thin": labels.iloc[i]["thin"],
202
- "solid": labels.iloc[i]["solid"],
203
- "clear": labels.iloc[i]["clear"],
204
- "dry": labels.iloc[i]["dry"],
205
- "plump": labels.iloc[i]["plump"],
206
- "rough": labels.iloc[i]["rough"],
207
- "pure": labels.iloc[i]["pure"],
208
- "hoarse": labels.iloc[i]["hoarse"],
209
- "harmonious": labels.iloc[i]["harmonious"],
210
- "soft": labels.iloc[i]["soft"],
211
- "turbid": labels.iloc[i]["turbid"],
212
- }
 
1
+ import os
2
+ import datasets
3
+ import pandas as pd
4
+ from datasets.tasks import AudioClassification
5
+
6
+
7
+ _NAMES = [
8
+ # Chinese 0-36
9
+ "gao_hu",
10
+ "er_hu",
11
+ "zhong_hu",
12
+ "ge_hu",
13
+ "di_yin_ge_hu",
14
+ "jing_hu",
15
+ "ban_hu",
16
+ "bang_di",
17
+ "qu_di",
18
+ "xin_di",
19
+ "da_di",
20
+ "gao_yin_sheng",
21
+ "zhong_yin_sheng",
22
+ "di_yin_sheng",
23
+ "gao_yin_suo_na",
24
+ "zhong_yin_suo_na",
25
+ "ci_zhong_yin_suo_na",
26
+ "di_yin_suo_na",
27
+ "gao_yin_guan",
28
+ "zhong_yin_guan",
29
+ "di_yin_guan",
30
+ "bei_di_yin_guan",
31
+ "ba_wu",
32
+ "xun",
33
+ "xiao",
34
+ "liu_qin",
35
+ "xiao_ruan",
36
+ "pi_pa",
37
+ "yang_qin",
38
+ "zhong_ruan",
39
+ "da_ruan",
40
+ "gu_zheng",
41
+ "gu_qin",
42
+ "kong_hou",
43
+ "san_xian",
44
+ "yun_luo",
45
+ "bian_zhong",
46
+ # Western 37-60
47
+ "violin",
48
+ "viola",
49
+ "cello",
50
+ "double_bass",
51
+ "piccolo",
52
+ "flute",
53
+ "oboe",
54
+ "clarinet",
55
+ "bassoon",
56
+ "saxophone",
57
+ "trumpet",
58
+ "trombone",
59
+ "horn",
60
+ "tuba",
61
+ "harp",
62
+ "tubular_bells",
63
+ "bells",
64
+ "xylophone",
65
+ "vibraphone",
66
+ "marimba",
67
+ "piano",
68
+ "clavichord",
69
+ "accordion",
70
+ "organ",
71
+ ]
72
+
73
+ _DBNAME = os.path.basename(__file__).split(".")[0]
74
+
75
+ _DOMAIN = f"https://www.modelscope.cn/api/v1/datasets/ccmusic-database/{_DBNAME}/repo?Revision=master&FilePath=data"
76
+
77
+ _HOMEPAGE = f"https://www.modelscope.cn/datasets/ccmusic-database/{_DBNAME}"
78
+
79
+ _CITATION = """\
80
+ @dataset{zhaorui_liu_2021_5676893,
81
+ author = {Monan Zhou, Shenyang Xu, Zhaorui Liu, Zhaowen Wang, Feng Yu, Wei Li and Baoqiang Han},
82
+ title = {CCMusic: an Open and Diverse Database for Chinese and General Music Information Retrieval Research},
83
+ month = {mar},
84
+ year = {2024},
85
+ publisher = {HuggingFace},
86
+ version = {1.2},
87
+ url = {https://huggingface.co/ccmusic-database}
88
+ }
89
+ """
90
+
91
+ _DESCRIPTION = """\
92
+ The raw dataset encompasses subjective timbre evaluation scores comprising 16 terms, such as bright, dark, raspy, etc, evaluated across 37 Chinese instruments and 24 Western instruments by 14 participants with musical backgrounds in a subjective evaluation experiment. Additionally, it includes 10 reports on spectrogram analysis of 10 instruments.
93
+
94
+ During the integration, we have crafted the Chinese part and the Non-Chinese part into two splits. Each split is composed of multiple data entries, with each entry structured across 18 columns. The Chinese split encompasses 37 entries, while the Non-Chinese split includes 24 entries. The premier column of each data entry presents the instrument recordings in the .wav format, sampled at a rate of 22,050 Hz. The second column provides the Chinese pinyin or English name of the instrument. The subsequent 16 columns correspond to the 10-point score of the 16 terms. This dataset is suitable for conducting timber analysis of musical instruments and can also be utilized for various single or multiple regression tasks related to term scoring.
95
+ """
96
+
97
+ _URLS = {
98
+ "audio": f"{_DOMAIN}/audio.zip",
99
+ "mel": f"{_DOMAIN}/mel.zip",
100
+ "Chinese": f"{_DOMAIN}/Chinese.csv",
101
+ "Western": f"{_DOMAIN}/Western.csv",
102
+ }
103
+
104
+
105
+ class instrument_timbre(datasets.GeneratorBasedBuilder):
106
+ def _info(self):
107
+ return datasets.DatasetInfo(
108
+ description=_DESCRIPTION,
109
+ features=datasets.Features(
110
+ {
111
+ "audio": datasets.Audio(sampling_rate=22050),
112
+ "mel": datasets.Image(),
113
+ "instrument": datasets.features.ClassLabel(names=_NAMES),
114
+ "slim": datasets.Value("float32"),
115
+ "bright": datasets.Value("float32"),
116
+ "dim": datasets.Value("float32"),
117
+ "sharp": datasets.Value("float32"),
118
+ "thick": datasets.Value("float32"),
119
+ "thin": datasets.Value("float32"),
120
+ "solid": datasets.Value("float32"),
121
+ "clear": datasets.Value("float32"),
122
+ "dry": datasets.Value("float32"),
123
+ "plump": datasets.Value("float32"),
124
+ "rough": datasets.Value("float32"),
125
+ "pure": datasets.Value("float32"),
126
+ "hoarse": datasets.Value("float32"),
127
+ "harmonious": datasets.Value("float32"),
128
+ "soft": datasets.Value("float32"),
129
+ "turbid": datasets.Value("float32"),
130
+ }
131
+ ),
132
+ supervised_keys=("audio", "instrument"),
133
+ homepage=_HOMEPAGE,
134
+ license="CC-BY-NC-ND",
135
+ version="1.2.0",
136
+ citation=_CITATION,
137
+ task_templates=[
138
+ AudioClassification(
139
+ task="audio-classification",
140
+ audio_column="audio",
141
+ label_column="instrument",
142
+ )
143
+ ],
144
+ )
145
+
146
+ def _split_generators(self, dl_manager):
147
+ audio_files = dl_manager.download_and_extract(_URLS["audio"])
148
+ mel_files = dl_manager.download_and_extract(_URLS["mel"])
149
+ cn_ins_eval = dl_manager.download(_URLS["Chinese"])
150
+ en_ins_eval = dl_manager.download(_URLS["Western"])
151
+ cn_labels = pd.read_csv(cn_ins_eval, index_col="instrument_id")
152
+ en_labels = pd.read_csv(en_ins_eval, index_col="instrument_id")
153
+ cn_dataset, en_dataset = {}, {}
154
+ for path in dl_manager.iter_files([audio_files]):
155
+ fname: str = os.path.basename(path)
156
+ i = int(fname.split(".wa")[0]) - 1
157
+ if fname.endswith(".wav"):
158
+ region = os.path.basename(os.path.dirname(path))
159
+ labels = cn_labels if region == "Chinese" else en_labels
160
+ data = {
161
+ "audio": path,
162
+ "mel": "",
163
+ "instrument": labels.iloc[i]["instrument_name"],
164
+ "slim": labels.iloc[i]["slim"],
165
+ "bright": labels.iloc[i]["bright"],
166
+ "dim": labels.iloc[i]["dim"],
167
+ "sharp": labels.iloc[i]["sharp"],
168
+ "thick": labels.iloc[i]["thick"],
169
+ "thin": labels.iloc[i]["thin"],
170
+ "solid": labels.iloc[i]["solid"],
171
+ "clear": labels.iloc[i]["clear"],
172
+ "dry": labels.iloc[i]["dry"],
173
+ "plump": labels.iloc[i]["plump"],
174
+ "rough": labels.iloc[i]["rough"],
175
+ "pure": labels.iloc[i]["pure"],
176
+ "hoarse": labels.iloc[i]["hoarse"],
177
+ "harmonious": labels.iloc[i]["harmonious"],
178
+ "soft": labels.iloc[i]["soft"],
179
+ "turbid": labels.iloc[i]["turbid"],
180
+ }
181
+ if region == "Chinese":
182
+ cn_dataset[i] = data
183
+ else:
184
+ en_dataset[i] = data
185
+
186
+ for path in dl_manager.iter_files([mel_files]):
187
+ fname = os.path.basename(path)
188
+ i = int(fname.split(".jp")[0]) - 1
189
+ if fname.endswith(".jpg"):
190
+ if os.path.basename(os.path.dirname(path)) == "Chinese":
191
+ cn_dataset[i]["mel"] = path
192
+ else:
193
+ en_dataset[i]["mel"] = path
194
+
195
+ return [
196
+ datasets.SplitGenerator(
197
+ name="Chinese",
198
+ gen_kwargs={
199
+ "files": [cn_dataset[k] for k in sorted(cn_dataset)],
200
+ },
201
+ ),
202
+ datasets.SplitGenerator(
203
+ name="Western",
204
+ gen_kwargs={
205
+ "files": [en_dataset[k] for k in sorted(en_dataset)],
206
+ },
207
+ ),
208
+ ]
209
+
210
+ def _generate_examples(self, files):
211
+ for i, path in enumerate(files):
212
+ yield i, path