|
import os |
|
import random |
|
import hashlib |
|
import datasets |
|
from datasets.tasks import AudioClassification |
|
|
|
|
|
_HOMEPAGE = f"https://www.modelscope.cn/datasets/ccmusic-database/{os.path.basename(__file__)[:-3]}" |
|
|
|
_DOMAIN = f"{_HOMEPAGE}/resolve/master/data" |
|
|
|
_NAMES = { |
|
"C0090": ["大笒", "da4_cen2"], |
|
"C0091": ["高音横笛", "Treble_heng2_di2"], |
|
"C0092": ["低音横笛", "Bass_heng2_di2"], |
|
"C0093": ["中音横笛", "Alto_heng2_di2"], |
|
"C0094": ["唢呐", "suo3_na"], |
|
"C0095": ["长唢呐", "chang2_suo3_na"], |
|
"C0096": ["小筚篥", "Treble_bi4_li"], |
|
"C0097": ["中音筚篥", "Alto_bi4_li"], |
|
"C0098": ["低音筚篥", "Bass_bi4_li"], |
|
"C0099": ["短箫", "duan3_xiao1"], |
|
"C0100": ["短箫(传统)", "duan3_xiao1_(traditional)"], |
|
"C0101": ["洞箫", "dong4_xiao1"], |
|
"C0113": ["尖子号", "jian1_zi3_hao4"], |
|
"C0114": ["尖子号2", "jian1_zi3_hao4_2"], |
|
"C0117": ["南音洞箫", "nan2_yin1_dong4_xiao1"], |
|
"C0123": ["南嗳仔", "nan2_ai1_zai3"], |
|
"C0124": ["大吹", "da4_chui1"], |
|
"C0182": ["长号", "chang2_hao4"], |
|
"C0183": ["老长号", "lao3_chang2_hao4"], |
|
"C0187": ["高音唢呐", "Treble_suo3_na"], |
|
"C0188": ["低音唢呐", "Bass_suo3_na"], |
|
"C0200": ["大芦笙", "da4_lu2_sheng1"], |
|
"C0201": ["小芦笙", "xiao3_lu2_sheng1"], |
|
"C0237": ["G调梆笛", "bang1_di2_in_G"], |
|
"C0243": ["高音键笙", "Treble_jian4_sheng1"], |
|
"C0244": ["传统笙", "traditional_sheng1"], |
|
"C0257": ["低音加键唢呐", "Bass_jia1_jian4_suo3_na"], |
|
"C0259": ["中音加键唢呐", "Alto_jia1_jian4_suo3_na"], |
|
"C0263": ["中音笙", "Alto_sheng1"], |
|
"C0264": ["低音笙", "Bass_sheng1"], |
|
"C0265": ["管子", "guan3_zi"], |
|
"C0280": ["A调曲笛", "qu3_di2_in_A"], |
|
"C0281": ["G调新笛", "xin1_di2_in_G"], |
|
"C0282": ["萧", "xiao1"], |
|
"C0283": ["埙", "xun1"], |
|
"C0296": ["唢呐2", "suo3_na_2"], |
|
"C0303": ["小闷笛", "xiao3_men1_di2"], |
|
"C0304": ["侗笛", "dong4_di2"], |
|
"C0305": ["德", "de2"], |
|
"C0306": ["拉祜族葫芦笙", "la1_hu2_zu2_hu2_lu2_sheng1"], |
|
"C0308": ["吐良", "tu3_liang2"], |
|
"C0309": ["葫芦丝", "hu2_lu2_si1"], |
|
"C0310": ["F调巴乌", "ba1_wu1_in_F"], |
|
"C0311": ["俄比", "e2_bi3"], |
|
"C0316": ["侗巴", "dong4_ba1"], |
|
"D0015": ["扬琴", "yang2_qin2"], |
|
"D0048": ["低音大锣", "Bass_da4_luo2"], |
|
"D0049": ["虎音锣", "hu3_yin1_luo2"], |
|
"D0050": ["小钹", "xiao3_bo1"], |
|
"D0051": ["钹", "bo1"], |
|
"D0058": ["提手(板)", "ti2_shou3_(ban3)"], |
|
"D0060": ["川小锣", "chuan1_xiao3_luo2"], |
|
"D0061": ["大铛铛", "da4_cheng1_cheng1"], |
|
"D0062": ["小铛铛", "xiao3_cheng1_cheng1"], |
|
"D0063": ["二馨", "er4_xin1"], |
|
"D0064": ["川大钵", "chuan1_da4_bo1"], |
|
"D0065": ["苏钵", "su1_bo1"], |
|
"D0066": ["川剧堂鼓", "chuan1_ju4_tang2_gu3"], |
|
"D0067": ["川铰", "chuan1_jiao3"], |
|
"D0068": ["川大锣", "chuan1_da4_luo2"], |
|
"D0069": ["蛮锣", "man2_luo2"], |
|
"D0070": ["包锣", "bao1_luo2"], |
|
"D0071": ["引鼓", "yin3_gu3"], |
|
"D0102": ["上杖鼓", "shang4_zhang4_gu3"], |
|
"D0103": ["小锣", "xiao3_luo2"], |
|
"D0104": ["圆锣", "yuan2_luo2"], |
|
"D0105": ["杖鼓", "zhang4_gu3"], |
|
"D0125": ["南鼓", "nan2_gu3"], |
|
"D0126": ["压脚鼓", "ya1_jiao3_gu3"], |
|
"D0127": ["钟", "zhong1"], |
|
"D0128": ["草锣", "cao3_luo2"], |
|
"D0129": ["锣仔", "luo2_zai3"], |
|
"D0130": ["响盏", "xiang3_zhan3"], |
|
"D0131": ["小叫", "xiao3_jiao4"], |
|
"D0132": ["拍", "pai1"], |
|
"D0137": ["渔鼓", "yu2_gu3"], |
|
"D0138": ["简板", "jian3_ban3"], |
|
"D0140": ["脚梆子", "jiao3_bang1_zi"], |
|
"D0143": ["双铃", "shuang1_ling2"], |
|
"D0144": ["小叫锣", "xiao3_jiao4_luo2"], |
|
"D0145": ["拍板", "pai1_ban3"], |
|
"D0146": ["四宝", "si4_bao3"], |
|
"D0147": ["响盏2", "xiang3_zhan3_2"], |
|
"D0172": ["碗碗", "wan3_wan3"], |
|
"D0173": ["代子", "dai4_zi"], |
|
"D0176": ["福(新)", "fu2_(reformed)"], |
|
"D0177": ["禄(新)", "lu4_(reformed)"], |
|
"D0178": ["寿(新)", "shou4_(reformed)"], |
|
"D0179": ["宜春三星鼓福鼓老鼓", "yi2_chun1_san1_xing1_gu3_fu2_gu3_lao3_gu3"], |
|
"D0180": ["宜春三星鼓禄鼓老鼓", "yi2_chun1_san1_xing1_gu3_lu4_gu3_lao3_gu3"], |
|
"D0181": ["宜春三星鼓寿鼓老鼓", "yi2_chun1_san1_xing1_gu3_shou4_gu3_lao3_gu3"], |
|
"D0184": ["宜春三星鼓双铛", "yi2_chun1_san1_xing1_gu3_shuang1_ding1"], |
|
"D0185": ["宜春三星鼓单铛", "yi2_chun1_san1_xing1_gu3_dan1_ding1"], |
|
"D0186": ["宜春三星鼓镲", "yi2_chun1_san1_xing1_gu3_chao3"], |
|
"D0241": ["编钟", "bian1_zhong1"], |
|
"D0242": ["编磬", "bian1_qing4"], |
|
"D0245": ["南梆子", "nan2_bang1_zi"], |
|
"D0246": ["北梆子", "bei3_bang1_zi"], |
|
"D0247": ["碰铃", "peng4_ling2"], |
|
"D0248": ["中国大鼓", "Chinese_da4_gu3"], |
|
"D0249": ["花盆鼓", "hua1_pen2_gu3"], |
|
"D0250": ["小堂鼓", "xiao3_tang2_gu3"], |
|
"D0251": ["扁鼓", "bian3_gu3"], |
|
"D0252": ["五音排鼓", "wu3_yin1_pai2_gu3"], |
|
"D0268": ["草帽镲", "cao3_mao4_chao3"], |
|
"D0269": ["铙", "nao2"], |
|
"D0270": ["铙钹", "nao2_bo1"], |
|
"D0271": ["小镲", "xiao3_chao3"], |
|
"D0272": ["抄锣", "chao1_luo2"], |
|
"D0273": ["中虎", "zhong1_hu3"], |
|
"D0274": ["武锣", "wu3_luo2"], |
|
"D0275": ["小锣2", "xiao3_luo2_2"], |
|
"D0276": ["马锣", "ma3_luo2"], |
|
"D0277": ["木鱼", "mu4_yu2"], |
|
"D0278": ["板鼓", "ban3_gu3"], |
|
"D0279": ["云锣", "yun2_luo2"], |
|
"D0284": ["斗锣", "dou3_luo2"], |
|
"D0286": ["曲锣", "qu3_luo2"], |
|
"D0287": ["深波", "shen1_bo1"], |
|
"D0290": ["大镲", "da4_chao3"], |
|
"D0298": ["编铓", "bian1_zhang1"], |
|
"D0299": ["牛铃", "niu2_ling2"], |
|
"D0315": ["竹排琴", "zhu2_pai2_qin2"], |
|
"D0325": ["那格拉", "na4_ge2_la1"], |
|
"D0326": ["库休克", "ku4_xiu1_ke4"], |
|
"D0327": ["萨巴依", "sa4_ba1_yi1"], |
|
"D0328": ["手鼓", "shou3_gu3"], |
|
"L0044": ["锡剧主胡", "xi1_ju4_zhu3_hu2"], |
|
"L0045": ["扬剧主胡", "yang2_ju4_zhu3_hu2"], |
|
"L0046": ["扬剧主胡F调", "yang2_ju4_zhu3_hu2_in_F"], |
|
"L0047": ["扬剧主胡(小西皮)", "yang2_ju4_zhu3_hu2_(xiao3_xi1_pi2)"], |
|
"L0053": ["广西彩调主胡", "guang3_xi1_cai3_diao4_zhu3_hu2"], |
|
"L0055": ["牛腿琴", "niu2_tui3_qin2"], |
|
"L0056": ["壮剧马骨胡D调", "zhuang4_ju4_ma3_gu3_hu2_in_D"], |
|
"L0072": ["盖板(新)D调", "gai4_ban3_(reformed)_in_D"], |
|
"L0073": ["盖板(传统)", "gai4_ban3_(traditional)"], |
|
"L0074": ["壮剧土胡", "zhuang4_ju4_tu3_hu2"], |
|
"L0075": ["晋剧晋胡", "jin4_ju4_jin4_hu2"], |
|
"L0076": ["壮剧土胡2", "zhuang4_ju4_tu3_hu2_2"], |
|
"L0077": ["晋剧二股弦", "jin4_ju4_er4_gu3_xian2"], |
|
"L0080": ["吕剧坠琴", "lv3_ju4_zhui4_qin2"], |
|
"L0084": ["奚琴(传统)", "xi1_qin2_(traditional)"], |
|
"L0085": ["奚琴(改良)", "xi1_qin2_(reformed)"], |
|
"L0086": ["中音奚琴(改良)", "Alto_xi1_qin2_(reformed)"], |
|
"L0115": ["莱芜梆子-梆胡", "lai2_wu2_bang1_zi-bang1_hu2"], |
|
"L0121": ["六角弦", "liu4_jiao3_xian2"], |
|
"L0122": ["壳仔弦", "ke2_zai3_xian2"], |
|
"L0133": ["陇剧陇胡(传统)", "long3_ju4_long3_hu2_(traditional)"], |
|
"L0134": ["陇剧陇胡(改良)D调", "long3_ju4_long3_hu2_(reformed)_in_D"], |
|
"L0135": ["齐琴", "qi2_qin2"], |
|
"L0136": ["渔胡", "yu2_hu2"], |
|
"L0139": ["坠胡", "zhui4_hu2"], |
|
"L0141": ["越胡", "yue4_hu2"], |
|
"L0148": ["板胡", "ban3_hu2"], |
|
"L0149": ["绍剧板胡", "shao4_ju4_ban3_hu2"], |
|
"L0150": ["宛梆子梆胡", "yuan1_bang1_zi_bang1_hu2"], |
|
"L0151": ["四弦", "si4_xian2"], |
|
"L0152": ["滇葫(小二胡)", "dian1_hu2_(xiao3_er4_hu2)"], |
|
"L0153": ["云南花灯丝弦", "yun2_nan2_hua1_deng1_si1_xian2"], |
|
"L0154": ["仕胡", "shi4_hu2"], |
|
"L0155": ["伬胡", "chi4_hu2"], |
|
"L0156": ["工胡", "gong1_hu2"], |
|
"L0157": ["大胡", "da4_hu2"], |
|
"L0158": ["低音伬胡", "Bass_chi4_hu2"], |
|
"L0160": ["丝弦", "si1_xian2"], |
|
"L0161": ["滇胡", "dian1_hu2"], |
|
"L0162": ["襄阳专用胡琴", "xiang1_yang2_zhuan1_yong4_hu2_qin2"], |
|
"L0163": ["雷胡", "lei2_hu2"], |
|
"L0164": ["赣胡", "gan4_hu2"], |
|
"L0165": ["高腔赣胡", "gao1_qiang1_gan4_hu2"], |
|
"L0166": ["高腔赣胡第2代", "gao1_qiang1_gan4_hu2_2nd_generation"], |
|
"L0167": ["黔胡", "qian2_hu2"], |
|
"L0168": ["花胡", "hua1_hu2"], |
|
"L0169": ["花胡2", "hua1_hu2_2"], |
|
"L0170": ["二股弦", "er4_gu3_xian2"], |
|
"L0239": ["高音板胡", "Treble_ban3_hu2"], |
|
"L0240": ["中音板胡", "Alto_ban3_hu2"], |
|
"L0256": ["雷琴", "lei2_qin2"], |
|
"L0266": ["二胡", "er4_hu2"], |
|
"L0285": ["二弦", "er4_xian2"], |
|
"L0288": ["椰胡", "ye1_hu2"], |
|
"L0291": ["扁八角高胡", "bian3_ba1_jiao3_gao1_hu2"], |
|
"L0292": ["六角高胡", "liu4_jiao3_gao1_hu2"], |
|
"L0297": ["中胡", "zhong1_hu2"], |
|
"L0307": ["芦笙", "lu2_sheng1"], |
|
"L0312": ["牛角胡", "niu2_jiao3_hu2"], |
|
"L0313": ["佤族独弦琴", "wa3_zu2_du2_xian2_qin2"], |
|
"L0314": ["葫芦琴", "hu2_lu2_qin2"], |
|
"T0006": ["陶布舒尔", "tao2_bu4_shu1_er3"], |
|
"T0007": ["雅托嘎", "ya3_tuo1_ga2"], |
|
"T0078": ["四股弦", "si4_gu3_xian2"], |
|
"T0081": ["玄琴", "xuan2_qin2"], |
|
"T0082": ["伽倻琴(改良)", "jia1_ye2_qin2_(reformed)"], |
|
"T0083": ["伽倻琴", "jia1_ye2_qin2"], |
|
"T0087": ["雅筝", "ya3_zheng1"], |
|
"T0088": ["扬琴2", "yang2_qin2_2"], |
|
"T0089": ["扬琴3", "yang2_qin2_3"], |
|
"T0111": ["三弦", "san1_xian2"], |
|
"T0116": ["八角月琴", "ba1_jiao3_yue4_qin2"], |
|
"T0159": ["双清", "shuang1_qing1"], |
|
"T0171": ["月琴", "yue4_qin2"], |
|
"T0238": ["大阮", "da4_ruan3"], |
|
"T0254": ["箜篌", "kong1_hou2"], |
|
"T0255": ["古筝", "gu3_zheng1"], |
|
"T0260": ["中阮", "zhong1_ruan3"], |
|
"T0261": ["柳琴", "liu3_qin2"], |
|
"T0262": ["琵琶", "pi2_pa2"], |
|
"T0267": ["扬琴4", "yang2_qin2_4"], |
|
"T0289": ["三弦2", "san1_xian2_2"], |
|
"T0294": ["南音琵琶", "nan2_yin1_pi2_pa2"], |
|
"T0295": ["南音三弦", "nan2_yin1_san1_xian2"], |
|
"T0300": ["澜沧小三弦", "lan2_cang1_xiao3_san1_xian2"], |
|
"T0301": ["玎", "ding1"], |
|
"T0302": ["傈傈族奇奔", "li4_li4_zu2_qi2_ben1"], |
|
"T0317": ["独弦琴", "du2_xian2_qin2"], |
|
"T0318": ["弹拨尔", "dan4_bo1_er3"], |
|
"T0319": ["低音热瓦普", "Bass_re4_wa3_pu3"], |
|
"T0320": ["民间热瓦普", "folk_re4_wa3_pu3"], |
|
"T0323": ["都它尔", "du1_ta1_er3"], |
|
} |
|
|
|
_URLS = { |
|
"audio": f"{_DOMAIN}/audio.zip", |
|
"mel": f"{_DOMAIN}/mel.zip", |
|
} |
|
|
|
|
|
class CTIS(datasets.GeneratorBasedBuilder): |
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
features=datasets.Features( |
|
{ |
|
"audio": datasets.Audio(sampling_rate=44100), |
|
"mel": datasets.Image(), |
|
"label": datasets.features.ClassLabel(names=list(_NAMES.keys())), |
|
"cname": datasets.Value("string"), |
|
"pinyin": datasets.Value("string"), |
|
} |
|
), |
|
supervised_keys=("audio", "label"), |
|
homepage=_HOMEPAGE, |
|
license="CC-BY-NC-ND", |
|
version="1.2.0", |
|
task_templates=[ |
|
AudioClassification( |
|
task="audio-classification", |
|
audio_column="audio", |
|
label_column="label", |
|
) |
|
], |
|
) |
|
|
|
def _str2md5(self, original_string: str): |
|
md5_obj = hashlib.md5() |
|
md5_obj.update(original_string.encode("utf-8")) |
|
return md5_obj.hexdigest() |
|
|
|
def _split_generators(self, dl_manager): |
|
audio_files = dl_manager.download_and_extract(_URLS["audio"]) |
|
mel_files = dl_manager.download_and_extract(_URLS["mel"]) |
|
files = {} |
|
for fpath in dl_manager.iter_files([audio_files]): |
|
fname: str = os.path.basename(fpath) |
|
label = os.path.basename(os.path.dirname(fpath)) |
|
if fname.endswith(".wav") and label in _NAMES and not "采访" in fname: |
|
cls = os.path.basename(os.path.dirname(fpath)) + "/" |
|
item_id = self._str2md5(cls + fname.split(".wa")[0]) |
|
files[item_id] = {"audio": fpath, "label": label} |
|
|
|
for fpath in dl_manager.iter_files([mel_files]): |
|
fname = os.path.basename(fpath) |
|
label = os.path.basename(os.path.dirname(fpath)) |
|
if fname.endswith(".jpg") and label in _NAMES: |
|
cls = os.path.basename(os.path.dirname(fpath)) + "/" |
|
item_id = self._str2md5(cls + fname.split(".jp")[0]) |
|
files[item_id]["mel"] = fpath |
|
|
|
dataset = list(files.values()) |
|
random.shuffle(dataset) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"files": dataset}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, files): |
|
for i, item in enumerate(files): |
|
yield i, { |
|
"audio": item["audio"], |
|
"mel": item["mel"], |
|
"label": item["label"], |
|
"cname": _NAMES[item["label"]][0], |
|
"pinyin": _NAMES[item["label"]][1], |
|
} |
|
|