bjelkenhed commited on
Commit
677853f
1 Parent(s): f693a1b

ts support

Browse files
Files changed (1) hide show
  1. babelbox_voice.py +24 -4
babelbox_voice.py CHANGED
@@ -7,6 +7,8 @@ import datasets
7
  from typing import List
8
  from pathlib import Path
9
  from tqdm import tqdm
 
 
10
  logger = datasets.logging.get_logger(__name__)
11
 
12
  _CITATION = """\
@@ -68,7 +70,7 @@ class BabelboxVoice(datasets.GeneratorBasedBuilder):
68
  {
69
  "path": datasets.Value("string"),
70
  "audio": datasets.features.Audio(sampling_rate=16_000),
71
- "sentence": datasets.Value("string"),
72
  "speaker_id": datasets.Value("string"),
73
  "sex": datasets.Value("string"),
74
  "accent": datasets.Value("string"),
@@ -79,7 +81,7 @@ class BabelboxVoice(datasets.GeneratorBasedBuilder):
79
  {
80
  "path": datasets.Value("string"),
81
  "audio": datasets.features.Audio(sampling_rate=16_000),
82
- "sentence": datasets.Value("string"),
83
  "speaker_id": datasets.Value("string"),
84
  "sex": datasets.Value("string"),
85
  "accent": datasets.Value("string"),
@@ -150,6 +152,11 @@ class BabelboxVoice(datasets.GeneratorBasedBuilder):
150
  def filter_sentence(sentence):
151
  if "... tyst under denna inspelning ..." in sentence: return False
152
  return True
 
 
 
 
 
153
 
154
  for i, audio_archive in enumerate(archives):
155
  for path, file in audio_archive:
@@ -158,12 +165,25 @@ class BabelboxVoice(datasets.GeneratorBasedBuilder):
158
 
159
  metadata_item = metadata[path]
160
 
 
 
161
  if filter_sentence(metadata_item['sentence']) == False: continue
 
 
 
 
 
 
 
 
 
 
 
162
 
163
  result = {
164
  'path' : path,
165
- 'audio' : {"path": path, "bytes": file.read(), "sampling_rate": sampling_rate },
166
- 'sentence' : metadata_item['sentence'],
167
  'speaker_id' : metadata_item['speaker_id'],
168
  'sex' : metadata_item['sex'],
169
  'accent' : metadata_item['accent']
 
7
  from typing import List
8
  from pathlib import Path
9
  from tqdm import tqdm
10
+ import torchaudio
11
+ from io import BytesIO
12
  logger = datasets.logging.get_logger(__name__)
13
 
14
  _CITATION = """\
 
70
  {
71
  "path": datasets.Value("string"),
72
  "audio": datasets.features.Audio(sampling_rate=16_000),
73
+ "text": datasets.Value("binary"),
74
  "speaker_id": datasets.Value("string"),
75
  "sex": datasets.Value("string"),
76
  "accent": datasets.Value("string"),
 
81
  {
82
  "path": datasets.Value("string"),
83
  "audio": datasets.features.Audio(sampling_rate=16_000),
84
+ "text": datasets.Value("binary"),
85
  "speaker_id": datasets.Value("string"),
86
  "sex": datasets.Value("string"),
87
  "accent": datasets.Value("string"),
 
152
  def filter_sentence(sentence):
153
  if "... tyst under denna inspelning ..." in sentence: return False
154
  return True
155
+
156
+ def get_audio(file):
157
+ file_buf = BytesIO(file.read())
158
+ array, audio_sr = torchaudio.load(file_buf, format="wav")
159
+ return array[0], audio_sr
160
 
161
  for i, audio_archive in enumerate(archives):
162
  for path, file in audio_archive:
 
165
 
166
  metadata_item = metadata[path]
167
 
168
+ audio_array, audio_sr = get_audio(file)
169
+
170
  if filter_sentence(metadata_item['sentence']) == False: continue
171
+
172
+ audio_len = len(audio_array) / sampling_rate
173
+ audio_len = round(audio_len / 2, 2) * 2
174
+
175
+ text = {
176
+ "text": metadata_item['sentence'],
177
+ "offsets": [
178
+ {"text": metadata_item['sentence'], "timestamp": (0.0, audio_len) }
179
+ ]
180
+ }
181
+
182
 
183
  result = {
184
  'path' : path,
185
+ 'audio': {"path": path, "array": audio_array, "sampling_rate": sampling_rate},
186
+ 'text' : text,
187
  'speaker_id' : metadata_item['speaker_id'],
188
  'sex' : metadata_item['sex'],
189
  'accent' : metadata_item['accent']