jimregan commited on
Commit
c1e9157
1 Parent(s): bea827e

normalise text, make original available as a config

Browse files
Files changed (1) hide show
  1. nst.py +19 -0
nst.py CHANGED
@@ -67,6 +67,7 @@ class NSTDataset(datasets.GeneratorBasedBuilder):
67
 
68
  BUILDER_CONFIGS = [
69
  datasets.BuilderConfig(name="speech", version=VERSION, description="Data for speech recognition"),
 
70
  # datasets.BuilderConfig(name="dialects", version=VERSION, description="Data for dialect classification"),
71
  ]
72
 
@@ -134,6 +135,8 @@ class NSTDataset(datasets.GeneratorBasedBuilder):
134
  for recording in data["val_recordings"]:
135
  bare_path = recording['file'].replace(".wav", "")
136
  text = recording["text"]
 
 
137
  lang_part = pid[0:2]
138
  for num in ["1", "2"]:
139
  tar_path = f"{lang_part}/{pid}/{pid}_{bare_path}-{num}.wav"
@@ -209,3 +212,19 @@ def _get_speaker_data(data):
209
 
210
  return out
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  BUILDER_CONFIGS = [
69
  datasets.BuilderConfig(name="speech", version=VERSION, description="Data for speech recognition"),
70
+ datasets.BuilderConfig(name="speech_no_norm", version=VERSION, description="Data with original text (no normalisation)"),
71
  # datasets.BuilderConfig(name="dialects", version=VERSION, description="Data for dialect classification"),
72
  ]
73
 
 
135
  for recording in data["val_recordings"]:
136
  bare_path = recording['file'].replace(".wav", "")
137
  text = recording["text"]
138
+ if self.config.name != "speech_no_norm":
139
+ text = normalise(text)
140
  lang_part = pid[0:2]
141
  for num in ["1", "2"]:
142
  tar_path = f"{lang_part}/{pid}/{pid}_{bare_path}-{num}.wav"
 
212
 
213
  return out
214
 
215
+
216
+ def normalise(text: str) -> str:
217
+ MARKERS = ["[fil]", "[int]", "[spk]", "[sta]"]
218
+ text = text.lower()
219
+ for mark in MARKERS:
220
+ text = text.replace(mark, "")
221
+ outtext = ""
222
+ last_char = ""
223
+ for char in text:
224
+ if char in "abcdefghijklmnopqrstuvwxyzåäö: ":
225
+ if char == " " and last_char == " ":
226
+ continue
227
+ else:
228
+ outtext = outtext + char
229
+ last_char = char
230
+ return outtext