Lennart Keller commited on
Commit
b5824c6
1 Parent(s): 715af7a

inital commit (for testing)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. README.md +15 -0
  2. SpeechTaxi.py +130 -0
  3. create_release.py +368 -0
  4. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__10.mp3 +3 -0
  5. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__21.mp3 +3 -0
  6. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__30.mp3 +3 -0
  7. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__5.mp3 +3 -0
  8. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__7.mp3 +3 -0
  9. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__9.mp3 +3 -0
  10. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/002/Verse_10.mp3 +3 -0
  11. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/002/Verse_12.mp3 +3 -0
  12. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/002/Verse_9.mp3 +3 -0
  13. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/003/Verse_11.mp3 +3 -0
  14. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/003/Verse_16.mp3 +3 -0
  15. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/003/Verse_6.mp3 +3 -0
  16. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/003/Verse_7.mp3 +3 -0
  17. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/004/Verse_1.mp3 +3 -0
  18. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/004/Verse_10.mp3 +3 -0
  19. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/004/Verse_16.mp3 +3 -0
  20. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/004/Verse_2.mp3 +3 -0
  21. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/005/Verse_1.mp3 +3 -0
  22. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/005/Verse_9.mp3 +3 -0
  23. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_11.mp3 +3 -0
  24. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_13.mp3 +3 -0
  25. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_14.mp3 +3 -0
  26. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_19.mp3 +3 -0
  27. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_9.mp3 +3 -0
  28. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_19.mp3 +3 -0
  29. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_21.mp3 +3 -0
  30. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_23.mp3 +3 -0
  31. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_26.mp3 +3 -0
  32. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_28.mp3 +3 -0
  33. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_36.mp3 +3 -0
  34. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_38.mp3 +3 -0
  35. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_39.mp3 +3 -0
  36. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_7.mp3 +3 -0
  37. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/008/Verse_3.mp3 +3 -0
  38. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/008/Verse_6.mp3 +3 -0
  39. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/008/Verse_7.mp3 +3 -0
  40. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/008/Verse_9.mp3 +3 -0
  41. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/009/Verse_14.mp3 +3 -0
  42. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_10.mp3 +3 -0
  43. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_12.mp3 +3 -0
  44. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_13.mp3 +3 -0
  45. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_14.mp3 +3 -0
  46. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_20.mp3 +3 -0
  47. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_21.mp3 +3 -0
  48. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_24.mp3 +3 -0
  49. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_31.mp3 +3 -0
  50. data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_6.mp3 +3 -0
README.md ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SpeechTaxi
2
+
3
+ TODO
4
+
5
+ ## Usage
6
+
7
+ ```python
8
+ # pip install datasets pandas
9
+ dataset = load_dataset(
10
+ "LennartKeller/SpeechTaxi",
11
+ name="fra",
12
+ split="train",
13
+ trust_remote_code=True
14
+ )
15
+ ```
SpeechTaxi.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import datasets
3
+ from datasets import (
4
+ Features,
5
+ SplitGenerator,
6
+ )
7
+ import pandas as pd
8
+
9
+ DATA_DIR = "data"
10
+ TABLE_DIR = "tables"
11
+
12
+ NAMES = [
13
+ "all",
14
+ "asm",
15
+ "bgc",
16
+ "bht",
17
+ "ckb",
18
+ "eng",
19
+ "ewe",
20
+ "fra",
21
+ "guj",
22
+ "ibo",
23
+ "kan",
24
+ "lin",
25
+ "luo",
26
+ "mal",
27
+ "mar",
28
+ "nag",
29
+ "nde",
30
+ "nlx",
31
+ "pan",
32
+ "peg",
33
+ "rus",
34
+ "tam",
35
+ "tel",
36
+ "tw-akuapem",
37
+ "tw-asante",
38
+ "ukr",
39
+ "urd",
40
+ "vie",
41
+ "yor",
42
+
43
+ ]
44
+
45
+ DESCRIPTION = ""
46
+ CITATION = "TODO"
47
+ HOMPAGE = "github.com/LennartKeller"
48
+
49
+ class SpeechTaxiConfig(datasets.BuilderConfig):
50
+ def __init__(
51
+ self, name, description, citation, homepage
52
+ ):
53
+ super().__init__(
54
+ name=name,
55
+ version=datasets.Version("0.0.1"),
56
+ description=description,
57
+ )
58
+ self.name = name
59
+ self.description = description
60
+ self.citation = citation
61
+ self.homepage = homepage
62
+
63
+ def get_config(name):
64
+ return SpeechTaxiConfig(name=name, description=DESCRIPTION, citation=CITATION, homepage=HOMPAGE)
65
+
66
+ class SpeechTaxi(datasets.GeneratorBasedBuilder):
67
+ BUILDER_CONFIGS = [get_config(name) for name in NAMES]
68
+ BUILDER_CONFIG_CLASS = SpeechTaxiConfig
69
+
70
+ def _info(self):
71
+ return datasets.DatasetInfo(
72
+ description=DESCRIPTION,
73
+ features=Features(
74
+ {
75
+ "verse_ref": datasets.features.Value("string"),
76
+ "text_en": datasets.features.Value("string"),
77
+ "transcription": datasets.features.Value("string"),
78
+ "transcription_romanized": datasets.features.Value("string"),
79
+ "label": datasets.features.ClassLabel(
80
+ names=[
81
+ "Recommendation",
82
+ "Faith",
83
+ "Description",
84
+ "Sin",
85
+ "Grace",
86
+ "Violence",
87
+ ]
88
+ ),
89
+ "transription_mms-zeroshot-300m": datasets.features.Value("string"),
90
+ "transription_mms": datasets.features.Value("string"),
91
+ "transription_whisper-large-v3": datasets.features.Value("string"),
92
+ "audio": datasets.features.Audio(sampling_rate=16_000)
93
+ }
94
+ ),
95
+ supervised_keys=None,
96
+ homepage=HOMPAGE,
97
+ citation=CITATION,
98
+ )
99
+ def _split_generators(self, dl_manager):
100
+ table_dir = dl_manager.download(TABLE_DIR)
101
+ # Make sure data is downloaded
102
+ data_dir = dl_manager.download(DATA_DIR)
103
+ return [
104
+ SplitGenerator(name="train", gen_kwargs={"split": "train", "table_dir": table_dir, "data_dir": data_dir}),
105
+ SplitGenerator(name="test", gen_kwargs={"split": "test", "table_dir": table_dir, "data_dir": data_dir}),
106
+ SplitGenerator(name="dev", gen_kwargs={"split": "dev", "table_dir": table_dir, "data_dir": data_dir}),
107
+ # Add more splits as necessary
108
+ ]
109
+
110
+ def _generate_examples(self, split, table_dir, data_dir):
111
+ table_dir = Path(table_dir)
112
+ data_dir = Path(data_dir)
113
+ idx = 0
114
+ if self.config.name != "all":
115
+ table_files = [table_dir / f"{self.config.name}.tsv"]
116
+ else:
117
+ table_files = sorted(table_dir.glob("*.tsv"))
118
+
119
+ for table_file in table_files:
120
+ # Load the table
121
+ df = pd.read_table(table_file)
122
+ df["language"] = table_file.stem
123
+ df = df.query("split == @split").reset_index(drop=True)
124
+
125
+ for _, row in df.iterrows():
126
+ row["audio"] = str(data_dir / row["audio"])
127
+ yield idx, row.to_dict()
128
+ idx += 1
129
+
130
+
create_release.py ADDED
@@ -0,0 +1,368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This scripts generates a self-contained dataset relase that can be uploaded to the HF-Hub or distributed as an archive file
2
+
3
+ # Apart from pip-installable packages this file should be self-contained for reproducibility
4
+ import json
5
+ import re
6
+ import shutil
7
+ from pathlib import Path
8
+ import jinja2
9
+ import pandas as pd
10
+ import uroman as ur
11
+ from unidecode import unidecode
12
+
13
+ # Define some variables
14
+ NAME = "SpeechTaxi"
15
+ VERSION = "0.0.1"
16
+ HOMEPAGE = "github.com/LennartKeller"
17
+ CITATION = "TODO"
18
+ DESCRIPTION = "TODO"
19
+ SAVE_DIR = Path("/hdd/lennart/datasets")
20
+
21
+ # Define some arguments and 'constants'
22
+ # TODO think about ways to avoid having to do this
23
+ REWRITE_PATHS = (
24
+ "/Volumes/SanDiskData/bible-audio-scraper-data/processed",
25
+ "/hdd/lennart/bible-audio-scraper-data/processed",
26
+ )
27
+ REWRITE_MASS_PATHS = ("/Volumes/SanDiskData/", "/hdd/lennart/")
28
+ ALIGNED_TABLES_DIR = Path("aligned_tables")
29
+ INCLUDE_MASS_LANGUAGES = True
30
+ MASS_LANGUAGES = ("eng", "rus", "spa", "ron", "eus", "fra")
31
+ SKIP_LANGUAGES = ("ron", "eus", "spa", "hau", "bdv", "nep", "ben")
32
+ SCRIPT_TEMPLATE = Path("SpeechTaxi.py.jinja")
33
+
34
+
35
+ def rewrite_path(p: str | Path) -> str | Path:
36
+ if REWRITE_PATHS:
37
+ if isinstance(p, str):
38
+ p = p.replace(*REWRITE_PATHS)
39
+ p = Path(str(p).replace(*REWRITE_PATHS))
40
+ return p
41
+
42
+
43
+ def rewrite_mass_path(p: str | Path) -> str | Path:
44
+ if REWRITE_MASS_PATHS:
45
+ if isinstance(p, str):
46
+ p = p.replace(*REWRITE_MASS_PATHS)
47
+ p = Path(str(p).replace(*REWRITE_MASS_PATHS))
48
+ return p
49
+
50
+
51
+ # Define a 'filter_instances' function that holds the selection logic
52
+ # for selecting instances that shold end up in the final dataset
53
+ def filter_instances(
54
+ df: pd.DataFrame, table_file_path: str | Path = None
55
+ ) -> pd.DataFrame:
56
+ df = df.copy() # Avoid warnings
57
+ # Some mass tables do not have them...
58
+ if "alignment_score" not in df.columns:
59
+ df["alignment_score"] = 1.0
60
+ df = df.query("score == 1.0 and alignment_score >= 0.8")
61
+ return df
62
+
63
+
64
+ def render_script_template(**kwargs):
65
+ templateLoader = jinja2.FileSystemLoader(
66
+ searchpath=SCRIPT_TEMPLATE.parent.as_posix()
67
+ )
68
+ templateEnv = jinja2.Environment(loader=templateLoader)
69
+ template = templateEnv.get_template(SCRIPT_TEMPLATE.name)
70
+ return template.render(**kwargs)
71
+
72
+
73
+ # BEGIN LIB:
74
+ # Define libs that are used to create the dataset.
75
+ # Do not change stuff here unless you really want to.
76
+
77
+ BOOK_ABBREVIATIONS = {
78
+ "Matthew": "MAT",
79
+ "Mark": "MRK",
80
+ "Luke": "LUK",
81
+ "John": "JHN",
82
+ "Acts": "ACT",
83
+ "Romans": "ROM",
84
+ "Corinthians": "COR", # Can be used as "1COR" or "2COR" based on context
85
+ "Galatians": "GAL",
86
+ "Ephesians": "EPH",
87
+ "Philippians": "PHP",
88
+ "Colossians": "COL",
89
+ "Thess": "THS", # Can be used as "1THS" or "2THS" based on context
90
+ "Timothy": "TIM", # Can be used as "1TIM" or "2TIM" based on context
91
+ "Titus": "TIT",
92
+ "Philemon": "PHM",
93
+ "Hebrews": "HEB",
94
+ "James": "JAS",
95
+ "Peter": "PET", # Can be used as "1PET" or "2PET" based on context
96
+ "Jude": "JUD",
97
+ "Revelation": "REV",
98
+ }
99
+ BOOK_ABBREVIATIONS_FR = {
100
+ "Matthieu": "MAT",
101
+ "Marc": "MRK",
102
+ "Luc": "LUC",
103
+ "Jean": "JHN",
104
+ "Actes": "ACT",
105
+ "Romains": "ROM",
106
+ "Corinthiens": "COR", # Can be used as "1COR" or "2COR" based on context
107
+ "Galates": "GAL",
108
+ "Éphésiens": "EPH",
109
+ "Philippiens": "PHP",
110
+ "Colossiens": "COL",
111
+ "Thessaloniciens": "THS", # Can be used as "1THS" or "2THS" based on context
112
+ "Timothée": "TIM", # Can be used as "1TIM" or "2TIM" based on context
113
+ "Tite": "TIT",
114
+ "Philémon": "PHM",
115
+ "Hébreux": "HEB",
116
+ "Jacques": "JAC",
117
+ "Pierre": "PIE", # Can be used as "1PIE" or "2PIE" based on context
118
+ "Jude": "JUD",
119
+ "Apocalypse": "APO",
120
+ }
121
+
122
+ BOOK_ABBREVIATIONS |= {
123
+ unidecode(k): unidecode(v) for k, v in BOOK_ABBREVIATIONS_FR.items()
124
+ }
125
+
126
+ MASS_LANGUAGE_IDS = [
127
+ "FRNTLSN2DA",
128
+ "ENGESVN1DA",
129
+ "RUSS76N2DA",
130
+ "SPNBDAN1DA",
131
+ "EUSEABN1DA",
132
+ "RONDCVN1DA",
133
+ ]
134
+
135
+
136
+ def parse_reference_from_mass_file(filename: str | Path, language_id: str = ""):
137
+ filename = Path(filename).name
138
+ book_num, rest = filename.split("___", 1)
139
+ book_num = int(book_num.replace("B", ""))
140
+ chapter_num, rest = rest.split("_", 1)
141
+ chapter_num = int(chapter_num)
142
+ if language_id:
143
+ rest = rest.replace(language_id, "")
144
+ else:
145
+ # rest = "_".join(p for p in rest.split("_") if not p.endswith("DA"))
146
+ for language_id in MASS_LANGUAGE_IDS:
147
+ rest = rest.replace(language_id, "")
148
+ rest = rest.replace("_one_channel.wav", "")
149
+ book_ref, verse_ref = re.split(r"_+", rest, 1)
150
+ book_num = ""
151
+ if book_ref[0].isdigit():
152
+ book_num = book_ref[0]
153
+ book_ref = book_ref[1:]
154
+ try:
155
+ book_ref = BOOK_ABBREVIATIONS[book_ref]
156
+ except KeyError as e:
157
+ print(book_ref)
158
+ print(filename)
159
+ raise e
160
+ if book_num:
161
+ book_ref = book_num + book_ref
162
+ verse_num = int(verse_ref.split("_")[-1])
163
+ complete_ref = f"{book_ref}.{chapter_num}.{verse_num}"
164
+ return complete_ref
165
+
166
+
167
+ def copy_self(dst: str | Path) -> None:
168
+ dst = Path(dst)
169
+ path_to_self = Path(__file__)
170
+ dst = dst / path_to_self.name
171
+ dst.write_text(path_to_self.read_text())
172
+
173
+
174
+ def copy_bible_scrape_audio(file: str | Path, root: str | Path) -> Path:
175
+ file, root = map(Path, (file, root))
176
+ copied_file = (
177
+ root / file.parts[-4] / file.parts[-3] / file.parts[-2] / file.parts[-1]
178
+ )
179
+ copied_file.parent.mkdir(exist_ok=True, parents=True)
180
+ shutil.copy(file, copied_file)
181
+ return copied_file
182
+
183
+
184
+ def copy_mass_audio(file: str | Path, root: str | Path) -> Path:
185
+ file, root = map(Path, (file, root))
186
+ copied_file = root / file.parts[-2] / file.parts[-1]
187
+ copied_file.parent.mkdir(exist_ok=True, parents=True)
188
+ shutil.copy(file, copied_file)
189
+ return copied_file
190
+
191
+
192
+ uroman = ur.Uroman()
193
+
194
+
195
+ def read_mass_instance(audio_file: str | Path) -> dict:
196
+ audio_file = Path(audio_file)
197
+ audio_file = rewrite_path(audio_file)
198
+ if not audio_file.exists():
199
+ raise ValueError(f"Audio file {audio_file} does not exist.")
200
+ verse_ref = parse_reference_from_mass_file(audio_file)
201
+ transcription_file = (
202
+ audio_file.parent / f"{audio_file.stem.removesuffix('_one_channel')}.txt"
203
+ )
204
+ transcription = transcription_file.read_text()
205
+ machine_generated_transcriptions = {}
206
+ machine_generated_transcription_files = audio_file.parent.glob(
207
+ f"{audio_file.stem}-*-transcript.txt"
208
+ )
209
+ for machine_generated_transcription_file in machine_generated_transcription_files:
210
+ # Get transcription key
211
+ key = machine_generated_transcription_file.stem.split("_one_channel-")[-1]
212
+ key = key.removesuffix("-transcript")
213
+ # print(audio_file, "|", machine_generated_transcription_file, "|", key)
214
+ machine_generated_transcriptions[f"transription_{key}"] = (
215
+ machine_generated_transcription_file.read_text()
216
+ )
217
+ data = {
218
+ "verse_ref": verse_ref,
219
+ "transcription": transcription,
220
+ "transcription_romanized": uroman.romanize_string(transcription),
221
+ } | machine_generated_transcriptions
222
+ return data
223
+
224
+
225
+ def read_bible_scrape_instance(audio_file: str | Path) -> dict:
226
+ """
227
+ Given the file to a verse this function loads all available metadata from disk.
228
+ And ensure that the audio files exists...
229
+ """
230
+ audio_file = Path(audio_file)
231
+ audio_file = rewrite_path(audio_file)
232
+
233
+ if not audio_file.exists():
234
+ raise ValueError(f"Audio file {audio_file} does not exist.")
235
+ # 1. Load all avaiable transcriptions
236
+ transcription_file = audio_file.with_suffix(".json")
237
+ transcriptions = json.loads(transcription_file.read_text())
238
+ # Filter to only texts
239
+ try:
240
+ verse_ref = transcriptions.pop("verse_ref")
241
+ transcriptions = {
242
+ bible_id: content["content"] for bible_id, content in transcriptions.items()
243
+ }
244
+ except Exception as e:
245
+ print(transcriptions)
246
+ print(e)
247
+ # 2. Look for audio alignement scores
248
+ alignment_file = audio_file.parent / f"{audio_file.stem}-alignment-scores.json"
249
+ alignment_scores = json.loads(alignment_file.read_text())
250
+
251
+ # 3. Select the transcription with best audio alignment score
252
+ best_bible_id = max(alignment_scores.items(), key=lambda x: x[-1])[0]
253
+ transcription = transcriptions[str(best_bible_id)]
254
+ # 4. Load all available machine generated transcriptions
255
+ machine_generated_transcriptions = {}
256
+ machine_generated_transcription_files = audio_file.parent.glob(
257
+ f"{audio_file.stem}-*.txt"
258
+ )
259
+ for machine_generated_transcription_file in machine_generated_transcription_files:
260
+ # Get transcription key
261
+
262
+ key = (
263
+ machine_generated_transcription_file.stem.removeprefix(audio_file.stem)
264
+ .removesuffix("-transcript")
265
+ .strip("-")
266
+ )
267
+ # print(audio_file, "|", machine_generated_transcription_file, "|", key)
268
+ machine_generated_transcriptions[f"transription_{key}"] = (
269
+ machine_generated_transcription_file.read_text()
270
+ )
271
+
272
+ data = {
273
+ "verse_ref": verse_ref,
274
+ "transcription": transcription,
275
+ "transcription_romanized": uroman.romanize_string(transcription),
276
+ } | machine_generated_transcriptions
277
+ return data
278
+
279
+
280
+ # Main logic
281
+ if __name__ == "__main__":
282
+ dataset_root = SAVE_DIR / NAME
283
+ # Setup the output directory (-ies)
284
+ if dataset_root.exists():
285
+ raise ValueError(
286
+ f"Dataset-Root-Directory {dataset_root} already exists, please remove manually to continue!"
287
+ )
288
+ print(f"Creating dataset release in {dataset_root}")
289
+ dataset_root.mkdir(parents=True)
290
+ data_dir = dataset_root / "data"
291
+ data_dir.mkdir(parents=True)
292
+ table_dir = dataset_root / "tables"
293
+ table_dir.mkdir(parents=True)
294
+
295
+ # Copy this script to dataset dir for reproducibility
296
+ copy_self(dataset_root)
297
+
298
+ # Create language datasets and copy the data to the dataset directory
299
+ # Load and filter alignment tables
300
+ language_tables = sorted(
301
+ [f for f in ALIGNED_TABLES_DIR.glob("*.tsv") if f.stem not in SKIP_LANGUAGES]
302
+ )
303
+
304
+ # Write code file
305
+ success_languages = []
306
+ for alignment_table in language_tables:
307
+ df = pd.read_table(alignment_table)
308
+ try:
309
+ df = filter_instances(df, alignment_table)
310
+ except Exception as e:
311
+ print(alignment_table)
312
+ raise e
313
+ if not len(df):
314
+ continue
315
+ success_languages.append(alignment_table)
316
+ final_table_data = []
317
+ for _, row in df.iterrows():
318
+ if alignment_table.stem not in MASS_LANGUAGES:
319
+ audio_file = rewrite_path(Path(row["audio_path"]))
320
+ copied_audio_file = copy_bible_scrape_audio(audio_file, root=data_dir)
321
+ english_text = row["en_text"]
322
+ data = read_bible_scrape_instance(audio_file)
323
+ # copied_audio = copy_file(audio_file, data_dir)
324
+ data = (
325
+ {"verse_ref": data.pop("verse_ref")}
326
+ | {"text_en": english_text}
327
+ | {"split": row["split"], "label": row["label"]}
328
+ | data
329
+ | {"audio": copied_audio_file.relative_to(data_dir).as_posix()}
330
+ )
331
+ final_table_data.append(data)
332
+ elif INCLUDE_MASS_LANGUAGES:
333
+ audio_file = rewrite_mass_path(Path(row["audio_path"]))
334
+ copied_audio_file = copy_mass_audio(audio_file, root=data_dir)
335
+ data = read_mass_instance(audio_file)
336
+ data = data | {
337
+ "split": row["split"],
338
+ "label": row["label"],
339
+ "text_en": row["en_text"],
340
+ "audio": copied_audio_file.relative_to(data_dir).as_posix(),
341
+ }
342
+ final_table_data.append(data)
343
+ fina_table = pd.DataFrame.from_records(final_table_data)
344
+ # Reorder columns
345
+ # cols = [
346
+ # "verse_ref",
347
+ # "text_en",
348
+ # "split",
349
+ # "label",
350
+ # "transcription",
351
+ # "transcription_romanized",
352
+ # "transription_mms-zeroshot-300m",
353
+ # "transription_whisper-large-v3",
354
+ # "transription_mms-1b-all",
355
+ # "audio",
356
+ # ]
357
+ # fina_table = fina_table[cols]
358
+ fina_table.to_csv(table_dir / alignment_table.name, index=False, sep="\t")
359
+
360
+ # Now render dataset loading script and write to dataset dir
361
+ code_file = dataset_root / f"{NAME}.py"
362
+ code_file_content = render_script_template(
363
+ languages=[f.stem for f in success_languages],
364
+ version=VERSION,
365
+ homepage=HOMEPAGE,
366
+ citation=CITATION,
367
+ )
368
+ code_file.write_text(code_file_content)
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__10.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5519125498548c818b4c6d6925c3abe7e13b2242a0179a8b9ab580f0010c898
3
+ size 135788
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__21.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a9b4099f4e3ace97f4852a15c20ccd2eba4347fef65f0e59a166a2b576e1a0c
3
+ size 121772
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__30.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40978602d854a4c200cb3a73e3fb7cc837abbbb1140ea06ffb1063e77ef3e03c
3
+ size 78572
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__5.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a8a7a618a469bc9912b01623c57ce403bb43e1bf8a03462fd37022faf31013a
3
+ size 61868
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__7.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da3e97502cd991c1cb07f132c4f4e4d7ffe65430980c66f1ba96a0b5d740d7a1
3
+ size 64556
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/001/Verse__9.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:888f3a6b97d1108867eaf6bb8b859870b980791c194107d4f6c06f747d58af6a
3
+ size 60524
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/002/Verse_10.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c6f077477b7c8540abb32c4b784d6fd76789c610457a9d79fb3c856426a5057
3
+ size 57644
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/002/Verse_12.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3053607b8c1cbed10026162259cf36f59ce9aefb074af5c815a3fdfb2775b3ec
3
+ size 63020
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/002/Verse_9.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ff32a70a2bc3bc9661d9a4a33be60154fa2d813378907f7b3b972249a5e4510
3
+ size 98348
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/003/Verse_11.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ab4be91e0ba4a94feab37cdc38c6e43016f7158198a4910dfaf0dad22c8d5564
3
+ size 80108
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/003/Verse_16.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:85441c714d59a2c434f61198b86247f7c4956e3273d58bff85567b283b2565d3
3
+ size 45548
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/003/Verse_6.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ef82bad8c063d9c2b37e78514f9a70e8471caeafead074bf1d3ecae02d58e6c
3
+ size 36908
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/003/Verse_7.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:15f1689f2467d830800ceb00bac7a2455b047797d120c08324f77a1a60230da0
3
+ size 60140
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/004/Verse_1.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b7be7d54077f08a7ff88cde72c9b1477cc973d9e74180a31c1638fe4b1df9577
3
+ size 50348
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/004/Verse_10.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac2aa0cc0f17da6fd5e1477035702025838891cb09af887838400bbda56d5f39
3
+ size 114476
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/004/Verse_16.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d0ed662509df22f0e4a02567a4d6cf0224730b37a4bad7574d9a9efb8222cebb
3
+ size 46700
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/004/Verse_2.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:717eecf1c5b1b9090dd9433e4669e27c8f36d2fd0e620a81c70424639e0ec415
3
+ size 38828
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/005/Verse_1.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0df048a711c64f118df2ab4b337be1c48f445a01dcbcfbc3c6e8ead573044fc8
3
+ size 105452
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/005/Verse_9.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b40e858d8fe6d672c9b5859c690ac47c217a8af8d07fbbfe47be23264fd7474a
3
+ size 50732
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_11.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f72036758d5c700fc246455bc9d38624981165f3389d0b929ab7a073d936400
3
+ size 107180
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_13.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73f2f69e45601acfef242c3977c747e71910f95a64845e5dc1fe0d4b33103f38
3
+ size 101804
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_14.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b67ce5fb319f735c025da70f177c2f1248cfd61b9ddaabf349111f80e3ba0424
3
+ size 44972
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_19.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbb547ded800bb22856bd7bca2997772237a5832238b31c8f869dd30a0a4a9ff
3
+ size 97772
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/006/Verse_9.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83beca4ba37420830114c0f89957855875ffbc071312ee81438c16886ad739ee
3
+ size 118892
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_19.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e12492cf887bc5917a1d033e0ab64381d86f54528333030f0af84518b47c922
3
+ size 86636
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_21.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a62641f28b34df33cca79838a665d25555fcd84c64f293cc847104dcbcbe3501
3
+ size 64748
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_23.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fbcceec4993836f45cc349e9fbdf79beb3b2389e712624fea010e69832c2ec0
3
+ size 42092
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_26.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be419aa422691c9daa2e2cb80836f7f2db753a6fb5da5502ae62606c0fcf1f17
3
+ size 65324
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_28.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e0f395beec8ad0c94ad8ebbb25d95a8b139f6dd30700057d8d1e89f9e086baf0
3
+ size 123884
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_36.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea098b11d2af0d73b1e171651f7276dfd70f825532806a7a155ccbfbd2aa4623
3
+ size 118892
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_38.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4762556faf6502c724912d5595a10671c5bacf395bc42ef7489f675aae8d3fd
3
+ size 89900
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_39.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c031b7ed80613da0e05b03a3f5f1bc9838ce2ba56acd32521e10e23ba8010cf
3
+ size 109100
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/007/Verse_7.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:17692b93ba6cc1a401756108d4a0d375216c1aaa4f1bee325c8f536fec9b910d
3
+ size 93548
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/008/Verse_3.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d9bd30de6892ad96838a185f59caf6c50eb7f4cd2da512ca0420120997aa024b
3
+ size 40364
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/008/Verse_6.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7b1cc7bd339a4b71db23080f71565b593ce53dcb5102f15fafcd545a8ff716fd
3
+ size 130028
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/008/Verse_7.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:effacf04b5dd756e5bd62ef7c67654b215c7f97581febc62ab59902fb6e1c176
3
+ size 130796
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/008/Verse_9.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3dd7126b45ec834e63ee73fd1d7bce1914a9d8cd09f63aac64e0378cd75f9b44
3
+ size 73388
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/009/Verse_14.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8196146e427fee225c20e448da16a4d6e972c5b67f08d3ef6f929779322ba4b2
3
+ size 60716
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_10.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20e8b3a5033e71e97827ca5e5b55663e07420d63f9c29594717aa9a75e65f223
3
+ size 53612
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_12.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:513886aa9a0a77b54bde3f08a6b4cec0d416c280c5e1418d5d6eaaee5bd332b9
3
+ size 48620
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_13.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:67536c2746b8d4cdd6402555f87637dddeb1378ab7126b5db0505c0418673a71
3
+ size 178028
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_14.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c27ca065b570c701214fdaf3e08884f204a7257d3906dd777ad7108c7a45e418
3
+ size 39596
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_20.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c9ce0dc5b3b5796b4e6a0b0511e0e076dee611389a7b8bcdd45df0b121328cf
3
+ size 95852
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_21.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2f23d7a7fb9ca1725723dde5b42a97fd9e553ad32e6212a9555b668eee2dff10
3
+ size 75692
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_24.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a3436e2191b7083dda119ce361e5903d6504f536cc7229e6dc7daaaab05cec3
3
+ size 42284
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_31.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d67219e4bc1da8c0174af0807822da95540afee35e9b3491f66ff5ef20796bb
3
+ size 67820
data/039316d8ba074002-rev4/039316d8ba074002-rev4-1CO/010/Verse_6.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b33e93bd900d2c228e2c065c4f5e7d89da2b1c0887ed21eb974b044871988827
3
+ size 79532