MuGeminorum commited on
Commit
281da04
1 Parent(s): 9435c8f
Files changed (2) hide show
  1. chest_falsetto.py +57 -13
  2. data/raw_data.zip +2 -2
chest_falsetto.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import random
3
  import datasets
4
  from datasets.tasks import AudioClassification
@@ -9,7 +10,9 @@ _NAMES = {
9
  'singing_method': ['falsetto', 'chest']
10
  }
11
 
12
- _HOMEPAGE = f"https://huggingface.co/datasets/ccmusic-database/{os.path.basename(__file__).split('.')[0]}"
 
 
13
 
14
  _CITATION = """\
15
  @dataset{zhaorui_liu_2021_5676893,
@@ -31,8 +34,6 @@ the Mel-spectrogram, MFCC, and spectral characteristics of each audio segment ar
31
  for a total of 5120 CSV files.
32
  """
33
 
34
- _URL = f"{_HOMEPAGE}/resolve/main/data/client_data.zip"
35
-
36
 
37
  class chest_falsetto(datasets.GeneratorBasedBuilder):
38
  def _info(self):
@@ -40,7 +41,9 @@ class chest_falsetto(datasets.GeneratorBasedBuilder):
40
  features=datasets.Features(
41
  {
42
  "audio": datasets.Audio(sampling_rate=44_100),
43
- "image": datasets.Image(),
 
 
44
  "label": datasets.features.ClassLabel(names=_NAMES['all']),
45
  "gender": datasets.features.ClassLabel(names=_NAMES['gender']),
46
  "singing_method": datasets.features.ClassLabel(names=_NAMES['singing_method']),
@@ -60,15 +63,54 @@ class chest_falsetto(datasets.GeneratorBasedBuilder):
60
  ],
61
  )
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  def _split_generators(self, dl_manager):
64
- data_files = dl_manager.download_and_extract(_URL)
65
- files = dl_manager.iter_files([data_files])
66
- dataset = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- for path in files:
69
- if os.path.basename(path).endswith(".wav"):
70
- dataset.append(path)
71
 
 
72
  random.shuffle(dataset)
73
  data_count = len(dataset)
74
  p80 = int(data_count * 0.8)
@@ -97,12 +139,14 @@ class chest_falsetto(datasets.GeneratorBasedBuilder):
97
 
98
  def _generate_examples(self, files):
99
  for i, path in enumerate(files):
100
- file_name = os.path.basename(path)
101
  sex = file_name.split('_')[1]
102
  method = file_name.split('_')[2][:-4]
103
  yield i, {
104
- "audio": path,
105
- "image": path.replace('.wav', '.jpg').replace('/audio/', '/image/').replace('\\audio\\', '\\image\\'),
 
 
106
  "label": f'{sex}_{method}',
107
  "gender": 'male' if sex == 'm' else 'female',
108
  "singing_method": method,
 
1
  import os
2
+ import socket
3
  import random
4
  import datasets
5
  from datasets.tasks import AudioClassification
 
10
  'singing_method': ['falsetto', 'chest']
11
  }
12
 
13
+ _NAME = os.path.basename(__file__).split('.')[0]
14
+
15
+ _HOMEPAGE = f"https://huggingface.co/datasets/ccmusic-database/{_NAME}"
16
 
17
  _CITATION = """\
18
  @dataset{zhaorui_liu_2021_5676893,
 
34
  for a total of 5120 CSV files.
35
  """
36
 
 
 
37
 
38
  class chest_falsetto(datasets.GeneratorBasedBuilder):
39
  def _info(self):
 
41
  features=datasets.Features(
42
  {
43
  "audio": datasets.Audio(sampling_rate=44_100),
44
+ "mel": datasets.Image(),
45
+ "cqt": datasets.Image(),
46
+ "chroma": datasets.Image(),
47
  "label": datasets.features.ClassLabel(names=_NAMES['all']),
48
  "gender": datasets.features.ClassLabel(names=_NAMES['gender']),
49
  "singing_method": datasets.features.ClassLabel(names=_NAMES['singing_method']),
 
63
  ],
64
  )
65
 
66
+ def _cdn_url(self, ip='127.0.0.1', port=80):
67
+ try:
68
+ # easy for local test
69
+ with socket.create_connection((ip, port), timeout=5):
70
+ return {
71
+ 'image': f'http://{ip}/{_NAME}/data/data.zip',
72
+ 'audio': f'http://{ip}/{_NAME}/data/raw_data.zip'
73
+ }
74
+
75
+ except (socket.timeout, socket.error):
76
+ return {
77
+ 'image': f"{_HOMEPAGE}/resolve/main/data/data.zip",
78
+ 'audio': f"{_HOMEPAGE}/resolve/main/data/raw_data.zip"
79
+ }
80
+
81
  def _split_generators(self, dl_manager):
82
+ audio_files = dl_manager.download_and_extract(self._cdn_url()['audio'])
83
+ wav_files = dl_manager.iter_files([audio_files])
84
+ data = {}
85
+
86
+ for wav_file in wav_files:
87
+ fname = os.path.basename(wav_file)
88
+ if fname.endswith(".wav"):
89
+ fname = fname[:-4]
90
+ data[fname] = {
91
+ 'audio': wav_file,
92
+ 'mel': '',
93
+ 'cqt': '',
94
+ 'chroma': ''
95
+ }
96
+
97
+ img_files = dl_manager.download_and_extract(self._cdn_url()['image'])
98
+ jpg_files = dl_manager.iter_files([img_files])
99
+ for jpg_file in jpg_files:
100
+ fname = os.path.basename(jpg_file)
101
+ if fname.endswith(".jpg"):
102
+ fname = fname[:-4]
103
+ dirname = os.path.dirname(jpg_file)
104
+ if 'mel' in dirname:
105
+ data[fname]['mel'] = jpg_file
106
+
107
+ elif 'cqt' in dirname:
108
+ data[fname]['cqt'] = jpg_file
109
 
110
+ elif 'chroma' in dirname:
111
+ data[fname]['chroma'] = jpg_file
 
112
 
113
+ dataset = list(data.values())
114
  random.shuffle(dataset)
115
  data_count = len(dataset)
116
  p80 = int(data_count * 0.8)
 
139
 
140
  def _generate_examples(self, files):
141
  for i, path in enumerate(files):
142
+ file_name = os.path.basename(path['audio'])
143
  sex = file_name.split('_')[1]
144
  method = file_name.split('_')[2][:-4]
145
  yield i, {
146
+ "audio": path['audio'],
147
+ "mel": path['mel'],
148
+ "cqt": path['cqt'],
149
+ "chroma": path['chroma'],
150
  "label": f'{sex}_{method}',
151
  "gender": 'male' if sex == 'm' else 'female',
152
  "singing_method": method,
data/raw_data.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2c64f8880652961823f722255393ebe6bced54f2f88480a0001c12235d925118
3
- size 62675969
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f14eb75b7270d022bab15bd164ac20cb84a607d1bbf6e74d78e81882d509e33
3
+ size 39263817