laubonghaudoi commited on
Commit
e5552aa
·
0 Parent(s):

Initial commit

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +57 -0
  2. .gitignore +5 -0
  3. README.md +265 -0
  4. align.py +81 -0
  5. cut.py +93 -0
  6. data/mouzaakdung-00000-of-00001.parquet +3 -0
  7. data/saamgwokjinji-00000-of-00005.parquet +3 -0
  8. data/saamgwokjinji-00001-of-00005.parquet +3 -0
  9. data/saamgwokjinji-00002-of-00005.parquet +3 -0
  10. data/saamgwokjinji-00003-of-00005.parquet +3 -0
  11. data/saamgwokjinji-00004-of-00005.parquet +3 -0
  12. data/seoiwuzyun-00000-of-00004.parquet +3 -0
  13. data/seoiwuzyun-00001-of-00004.parquet +3 -0
  14. data/seoiwuzyun-00002-of-00004.parquet +3 -0
  15. data/seoiwuzyun-00003-of-00004.parquet +3 -0
  16. opus/mouzaakdung/001/001_001.opus +3 -0
  17. opus/mouzaakdung/001/001_002.opus +3 -0
  18. opus/mouzaakdung/001/001_003.opus +3 -0
  19. opus/mouzaakdung/001/001_004.opus +3 -0
  20. opus/mouzaakdung/001/001_005.opus +3 -0
  21. opus/mouzaakdung/001/001_006.opus +3 -0
  22. opus/mouzaakdung/001/001_007.opus +3 -0
  23. opus/mouzaakdung/001/001_008.opus +3 -0
  24. opus/mouzaakdung/001/001_009.opus +3 -0
  25. opus/mouzaakdung/001/001_010.opus +3 -0
  26. opus/mouzaakdung/001/001_011.opus +3 -0
  27. opus/mouzaakdung/001/001_012.opus +3 -0
  28. opus/mouzaakdung/001/001_013.opus +3 -0
  29. opus/mouzaakdung/001/001_014.opus +3 -0
  30. opus/mouzaakdung/001/001_015.opus +3 -0
  31. opus/mouzaakdung/001/001_016.opus +3 -0
  32. opus/mouzaakdung/001/001_017.opus +3 -0
  33. opus/mouzaakdung/001/001_018.opus +3 -0
  34. opus/mouzaakdung/001/001_019.opus +3 -0
  35. opus/mouzaakdung/001/001_020.opus +3 -0
  36. opus/mouzaakdung/001/001_021.opus +3 -0
  37. opus/mouzaakdung/001/001_022.opus +3 -0
  38. opus/mouzaakdung/001/001_023.opus +3 -0
  39. opus/mouzaakdung/001/001_024.opus +3 -0
  40. opus/mouzaakdung/001/001_025.opus +3 -0
  41. opus/mouzaakdung/001/001_026.opus +3 -0
  42. opus/mouzaakdung/001/001_027.opus +3 -0
  43. opus/mouzaakdung/001/001_028.opus +3 -0
  44. opus/mouzaakdung/001/001_029.opus +3 -0
  45. opus/mouzaakdung/001/001_030.opus +3 -0
  46. opus/mouzaakdung/001/001_031.opus +3 -0
  47. opus/mouzaakdung/001/001_032.opus +3 -0
  48. opus/mouzaakdung/001/001_033.opus +3 -0
  49. opus/mouzaakdung/001/001_034.opus +3 -0
  50. opus/mouzaakdung/001/001_035.opus +3 -0
.gitattributes ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.lz4 filter=lfs diff=lfs merge=lfs -text
12
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
13
+ *.model filter=lfs diff=lfs merge=lfs -text
14
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
15
+ *.npy filter=lfs diff=lfs merge=lfs -text
16
+ *.npz filter=lfs diff=lfs merge=lfs -text
17
+ *.onnx filter=lfs diff=lfs merge=lfs -text
18
+ *.ot filter=lfs diff=lfs merge=lfs -text
19
+ *.parquet filter=lfs diff=lfs merge=lfs -text
20
+ *.pb filter=lfs diff=lfs merge=lfs -text
21
+ *.pickle filter=lfs diff=lfs merge=lfs -text
22
+ *.pkl filter=lfs diff=lfs merge=lfs -text
23
+ *.pt filter=lfs diff=lfs merge=lfs -text
24
+ *.pth filter=lfs diff=lfs merge=lfs -text
25
+ *.rar filter=lfs diff=lfs merge=lfs -text
26
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
27
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
29
+ *.tar filter=lfs diff=lfs merge=lfs -text
30
+ *.tflite filter=lfs diff=lfs merge=lfs -text
31
+ *.tgz filter=lfs diff=lfs merge=lfs -text
32
+ *.wasm filter=lfs diff=lfs merge=lfs -text
33
+ *.xz filter=lfs diff=lfs merge=lfs -text
34
+ *.zip filter=lfs diff=lfs merge=lfs -text
35
+ *.zst filter=lfs diff=lfs merge=lfs -text
36
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
37
+ # Audio files - uncompressed
38
+ *.pcm filter=lfs diff=lfs merge=lfs -text
39
+ *.sam filter=lfs diff=lfs merge=lfs -text
40
+ *.raw filter=lfs diff=lfs merge=lfs -text
41
+ # Audio files - compressed
42
+ *.aac filter=lfs diff=lfs merge=lfs -text
43
+ *.flac filter=lfs diff=lfs merge=lfs -text
44
+ *.mp3 filter=lfs diff=lfs merge=lfs -text
45
+ *.ogg filter=lfs diff=lfs merge=lfs -text
46
+ *.wav filter=lfs diff=lfs merge=lfs -text
47
+ *.opus filter=lfs diff=lfs merge=lfs -text
48
+ *.webm filter=lfs diff=lfs merge=lfs -text
49
+ # Image files - uncompressed
50
+ *.bmp filter=lfs diff=lfs merge=lfs -text
51
+ *.gif filter=lfs diff=lfs merge=lfs -text
52
+ *.png filter=lfs diff=lfs merge=lfs -text
53
+ *.tiff filter=lfs diff=lfs merge=lfs -text
54
+ # Image files - compressed
55
+ *.jpg filter=lfs diff=lfs merge=lfs -text
56
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
57
+ *.webp filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ .venv*
2
+ .aider*
3
+ *.ipynb
4
+ *.html
5
+ .DS_Store
README.md ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - yue
4
+ license: cc0-1.0
5
+ size_categories:
6
+ - 10K<n<100K
7
+ task_categories:
8
+ - automatic-speech-recognition
9
+ - text-to-speech
10
+ - text-generation
11
+ - feature-extraction
12
+ - audio-to-audio
13
+ - audio-classification
14
+ - text-to-audio
15
+ pretty_name: c
16
+ configs:
17
+ - config_name: default
18
+ data_files:
19
+ - split: saamgwokjinji
20
+ path: data/saamgwokjinji-*
21
+ - split: seoiwuzyun
22
+ path: data/seoiwuzyun-*
23
+ - split: mouzaakdung
24
+ path: data/mouzaakdung-*
25
+ tags:
26
+ - cantonese
27
+ - audio
28
+ - art
29
+ dataset_info:
30
+ features:
31
+ - name: audio
32
+ dtype: audio
33
+ - name: id
34
+ dtype: string
35
+ - name: episode_id
36
+ dtype: int64
37
+ - name: audio_duration
38
+ dtype: float64
39
+ - name: transcription
40
+ dtype: string
41
+ splits:
42
+ - name: saamgwokjinji
43
+ num_bytes: 2398591354.589
44
+ num_examples: 39173
45
+ - name: seoiwuzyun
46
+ num_bytes: 1629539808.0
47
+ num_examples: 24744
48
+ - name: mouzaakdung
49
+ num_bytes: 257168872.246
50
+ num_examples: 4742
51
+ download_size: 4304923024
52
+ dataset_size: 4285300034.835
53
+ ---
54
+
55
+ # 張悦楷講《三國演義》《水滸傳》語音數據集
56
+
57
+ [English](#the-zoeng-jyut-gaai-story-telling-speech-dataset)
58
+
59
+ ## Dataset Description
60
+
61
+ - **Homepage:** [張悦楷講古語音數據集 The Zoeng Jyut Gaai Story-telling Speech Dataset](https://canclid.github.io/zoengjyutgaai/)
62
+ - **License:** [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/)
63
+ - **Language:** Cantonese
64
+ - **Total Duration:** 112.54 hours
65
+ - **Average Clip Duration:** 5.901 seconds
66
+ - **Median Clip Duration:** 5.443 seconds
67
+ - **Total number of characters:** 1679097
68
+ - **Average characters per clip:** 24.36
69
+ - **Median characters per clip:** 23
70
+ - **Average speech speed:** 4.14 characters per second
71
+ - **Voice Actor:** [張悦楷](https://zh.wikipedia.org/wiki/%E5%BC%A0%E6%82%A6%E6%A5%B7)
72
+
73
+ 呢個係張悦楷講《三國演義》、《水滸傳》、《走進毛澤東的最後歲月》語音數據集。[張悦楷](https://zh.wikipedia.org/wiki/%E5%BC%A0%E6%82%A6%E6%A5%B7)係廣州最出名嘅講古佬 / 粵語説書藝人。佢從上世紀七十年代開始就喺廣東各個收音電台度講古,佢把聲係好多廣州人嘅共同回憶。本數據集收集嘅係佢最知名嘅三部作品。
74
+
75
+ 數據集用途:
76
+
77
+ - TTS(語音合成)訓練集
78
+ - ASR(語音識別)訓練集或測試集
79
+ - 各種語言學、文學研究
80
+ - 直接聽嚟欣賞藝術!
81
+
82
+ TTS 效果演示:https://huggingface.co/spaces/laubonghaudoi/zoengjyutgaai_tts
83
+
84
+ ## 説明
85
+
86
+ - 所有文本都根據 https://jyutping.org/blog/typo/ 同 https://jyutping.org/blog/particles/ 規範用字。
87
+ - 所有文本都使用全角標點,冇半角標點。
88
+ - 所有文本都用漢字轉寫,無阿拉伯數字無英文字母
89
+ - 所有音頻源都存放喺`/source`,為方便直接用作訓練數據,切分後嘅音頻都放喺 `opus/`
90
+ - 所有 opus 音頻皆為 48000 Hz 採樣率。
91
+ - 所有源字幕 SRT 文件都存放喺 `srt/` 路經下,搭配 `source/` 下嘅音源可以直接作為帶字幕嘅錄音直接欣賞。
92
+ - `cut.py` 係切分腳本,將對應嘅音源根據 srt 切分成短句並生成一個文本轉寫 csv。
93
+ - `stats.py` 係統計腳本,運行佢就會顯示成個數據集嘅各項統計數據。
94
+
95
+ ## 下載使用
96
+
97
+ 要下載使用呢個數據集,可以喺 Python 入面直接跑:
98
+
99
+ ```python
100
+ from datasets import load_dataset
101
+
102
+ ds = load_dataset("CanCLID/zoengjyutgaai")
103
+ ```
104
+
105
+ 如果想單純將 `opus/` 入面所有嘢下載落嚟,可以跑下面嘅 Python 代碼,注意要安裝 `pip install --upgrade huggingface_hub` 先:
106
+
107
+ ```python
108
+ from huggingface_hub import snapshot_download
109
+
110
+ # 如果淨係想下載啲字幕或者源音頻,就將 `opus/*` 改成 `srt/*` 或者 `source/*`
111
+ # If you only want to download subtitles or source audio, change `opus/*` to `srt/*` or `source/*`
112
+ snapshot_download(repo_id="CanCLID/zoengjyutgaai",allow_patterns="opus/*",local_dir="./",repo_type="dataset")
113
+ ```
114
+
115
+ 如果唔想用 python,你亦都可以用命令行叫 git 針對克隆個`opus/`或者其他路經,避免將成個 repo 都克隆落嚟浪費空間同下載時間:
116
+
117
+ ```bash
118
+ mkdir zoengjyutgaai
119
+ cd zoengjyutgaai
120
+ git init
121
+
122
+ git remote add origin https://huggingface.co/datasets/CanCLID/zoengjyutgaai
123
+ git sparse-checkout init --cone
124
+
125
+ # 指定凈係下載個別路徑
126
+ git sparse-checkout set opus
127
+
128
+ # 開始下載
129
+ git pull origin main
130
+ ```
131
+
132
+ ### 數據集構建流程
133
+
134
+ 本數據集嘅收集、構建過程係:
135
+
136
+ 1. 從 YouTube 或者國內評書網站度下載錄音源文件,一般都係每集半個鐘長嘅 `.webm` 或者 `.mp3`。
137
+ 1. 用加字幕工具幫呢啲錄音加字幕,得到對應嘅 `.srt` 文件。
138
+ 1. 將啲源錄音用下面嘅命令儘可能無壓縮噉轉換成 `.opus` 格式。
139
+ 1. 運行`cut.py`,將每一集 `.opus` 按照 `.srt` 入面嘅時間點切分成一句一個 `.opus`,然後對應嘅文本寫入本數據集嘅 `xxx.csv`。
140
+ 1. 然後打開一個 IPython,逐句跑下面嘅命令,將啲數據推上 HuggingFace。
141
+
142
+ ```python
143
+ from datasets import load_dataset, DatasetDict
144
+ from huggingface_hub import login
145
+
146
+ sg = load_dataset('audiofolder', data_dir='./opus/saamgwokjinji')
147
+ sw = load_dataset('audiofolder', data_dir='./opus/seoiwuzyun')
148
+ mzd = load_dataset('audiofolder', data_dir='./opus/mouzaakdung')
149
+ dataset = DatasetDict({
150
+ "saamgwokjinji": sg["train"],
151
+ "seoiwuzyun": sw["train"],
152
+ "mouzaakdung": mzd["train"],
153
+ })
154
+
155
+ # 檢查下讀入嘅數據有冇問題
156
+ dataset['mouzaakdung'][0]
157
+ # 準備好個 token 嚟登入
158
+ login()
159
+ # 推上 HuggingFace datasets
160
+ dataset.push_to_hub("CanCLID/zoengjyutgaai")
161
+ ```
162
+
163
+ ### 音頻格式轉換
164
+
165
+ 首先要安裝 [ffmpeg](https://www.ffmpeg.org/download.html),然後運行:
166
+
167
+ ```bash
168
+ # 將下載嘅音源由 webm 轉成 opus
169
+ ffmpeg -i webm/saamgwokjinji/001.webm -c:a copy source/saamgwokjinji/001.opus
170
+ # 或者轉 mp3
171
+ ffmpeg -i mp3/mouzaakdung/001.mp3 -c:a libopus -map_metadata -1 -b:a 48k -vbr on source/mouzaakdung/001.opus
172
+ # 將 opus 轉成無損 wav
173
+ ffmpeg -i source/saamgwokjinji/001.opus wav/saamgwokjinji/001.wav
174
+ ```
175
+
176
+ 如果想將所有 opus 文件全部轉換成 wav,可以直接運行`to_wav.sh`:
177
+
178
+ ```
179
+ chmod +x to_wav.sh
180
+ ./to_wav.sh
181
+ ```
182
+
183
+ 跟住就會生成一個 `wav/` 路經,入面都係 `opus/` 對應嘅音頻。注意 wav 格式非常掗埞,成個 `opus/` 轉晒後會佔用至少 500GB 儲存空間,所以轉換之前記得確保有足夠空間。如果你想對音頻重採樣,亦都可以修改 `to_wav.sh` 入面嘅命令順便做重採樣。
184
+
185
+ # The Zoeng Jyut Gaai Story-telling Speech Dataset
186
+
187
+ This is a speech dataset of Zoeng Jyut Gaai story-telling _Romance of the Three Kingdoms_, _Water Margin_ and _The Final Days of Mao Zedong_. [Zoeng Jyut Gaai](https://zh.wikipedia.org/wiki/%E5%BC%A0%E6%82%A6%E6%A5%B7) is a famous actor, stand-up commedian and story-teller (講古佬) in 20th centry Canton. His voice remains in the memories of thousands of Cantonese people. This dataset is built from three of his most well-known story-telling pieces.
188
+
189
+ Use case of this dataset:
190
+
191
+ - TTS (Text-To-Speech) training set
192
+ - ASR (Automatic Speech Recognition) training or eval set
193
+ - Various linguistics / art analysis
194
+ - Just listen and enjoy the art piece!
195
+
196
+ TTS demo: https://huggingface.co/spaces/laubonghaudoi/zoengjyutgaai_tts
197
+
198
+ ## Introduction
199
+
200
+ - All transcriptions follow the prescribed orthography detailed in https://jyutping.org/blog/typo/ and https://jyutping.org/blog/particles/
201
+ - All transcriptions use full-width punctuations, no half-width punctuations is used.
202
+ - All transcriptions are in Chinese characters, no Arabic numbers or Latin letters.
203
+ - All source audio are stored in `source/`. For the convenice of training, segmented audios are stored in `opus/`.
204
+ - All opus audio are in 48000 Hz sampling rate.
205
+ - All source subtitle SRT files are stored in `srt/`. Use them with the webm files to enjoy subtitled storytelling pieces.
206
+ - `cut.py` is the script for cutting opus audios into senteneces based on the srt, and generates a csv file for transcriptions.
207
+ - `stats.py` is the script for getting stats of this dataset.
208
+
209
+ ## Usage
210
+
211
+ To use this dataset, simply run in Python:
212
+
213
+ ```python
214
+ from datasets import load_dataset
215
+
216
+ ds = load_dataset("CanCLID/zoengjyutgaai")
217
+ ```
218
+
219
+ If you only want to download a certain directory to save time and space from cloning the entire repo, run the Python codes below. Make sure you have `pip install --upgrade huggingface_hub` first:
220
+
221
+ ```python
222
+ from huggingface_hub import snapshot_download
223
+
224
+ # If you only want to download subtitles or source audio, change `opus/*` to `srt/*` or `source/*`
225
+ snapshot_download(repo_id="CanCLID/zoengjyutgaai",allow_patterns="opus/*",local_dir="./",repo_type="dataset")
226
+ ```
227
+
228
+ If you don't want to run python codes and want to do this via command lines, you can selectively clone only a directory of the repo:
229
+
230
+ ```bash
231
+ mkdir zoengjyutgaai
232
+ cd zoengjyutgaai
233
+ git init
234
+
235
+ git remote add origin https://huggingface.co/datasets/CanCLID/zoengjyutgaai
236
+ git sparse-checkout init --cone
237
+
238
+ # Tell git which directory you want
239
+ git sparse-checkout set opus
240
+
241
+ # Pull the content
242
+ git pull origin main
243
+ ```
244
+
245
+ ### Audio format conversion
246
+
247
+ Install [ffmpeg](https://www.ffmpeg.org/download.html) first, then run:
248
+
249
+ ```bash
250
+ # convert all webm into opus
251
+ ffmpeg -i webm/saamgwokjinji/001.webm -c:a copy source/saamgwokjinji/001.opus
252
+ # or into mp3
253
+ ffmpeg -i mp3/mouzaakdung/001.mp3 -c:a libopus -map_metadata -1 -b:a 48k -vbr on source/mouzaakdung/001.opus
254
+ # convert all opus into loseless wav
255
+ ffmpeg -i source/saamgwokjinji/001.opus wav/saamgwokjinji/001.wav
256
+ ```
257
+
258
+ If you want to convert all opus to wav, run `to_wav.sh`:
259
+
260
+ ```
261
+ chmod +x to_wav.sh
262
+ ./to_wav.sh
263
+ ```
264
+
265
+ It will generate a `wav/` path which contains all audios converted from `opus/`. Be aware the wav format is very space-consuming. A full conversion will take up at least 500GB space so make sure you have enough storage. If you want to resample the audio, modify the line within `to_wav.sh` to resample the audio while doing the conversion.
align.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import audioread
3
+
4
+
5
+ def fix_srt_delay(input_file, output_file, delay_start_ms, delay_end_ms, audio_file):
6
+ """
7
+ Fixes a progressive delay in an SRT file by linearly adjusting timestamps.
8
+ Gets video duration from an associated audio file.
9
+
10
+ Args:
11
+ input_file: Path to the input SRT file.
12
+ output_file: Path to the output SRT file with corrected timestamps.
13
+ delay_start_ms: Delay at the beginning of the video (in milliseconds).
14
+ delay_end_ms: Delay at the end of the video (in milliseconds).
15
+ audio_file: Path to the audio file to get duration from.
16
+ """
17
+
18
+ try:
19
+ with audioread.audio_open(audio_file) as f:
20
+ total_duration_ms = int(f.duration * 1000) # Get duration in milliseconds
21
+ except audioread.NoBackendError:
22
+ print("Error: No suitable audio backend found. Please install ffmpeg or another supported library.")
23
+ return
24
+ except Exception as e:
25
+ print(f"Error reading audio file: {e}")
26
+ return
27
+
28
+ with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8') as outfile:
29
+ for line in infile:
30
+ if '-->' in line:
31
+ # Extract start and end timestamps
32
+ start_time_str, end_time_str = line.strip().split(' --> ')
33
+ start_time_ms = srt_time_to_milliseconds(start_time_str)
34
+ end_time_ms = srt_time_to_milliseconds(end_time_str)
35
+
36
+ # Calculate the adjusted delay for this subtitle
37
+ progress = start_time_ms / total_duration_ms
38
+ current_delay_ms = delay_start_ms + progress * (delay_end_ms - delay_start_ms)
39
+
40
+ # Adjust the timestamps
41
+ adjusted_start_time_ms = start_time_ms - current_delay_ms
42
+ adjusted_end_time_ms = end_time_ms - current_delay_ms
43
+
44
+ # Convert back to SRT time format
45
+ adjusted_start_time_str = milliseconds_to_srt_time(adjusted_start_time_ms)
46
+ adjusted_end_time_str = milliseconds_to_srt_time(adjusted_end_time_ms)
47
+
48
+ # Write the corrected line to the output file
49
+ outfile.write(f"{adjusted_start_time_str} --> {adjusted_end_time_str}\n")
50
+ else:
51
+ # Write non-timestamp lines as they are
52
+ outfile.write(line)
53
+
54
+
55
+ def srt_time_to_milliseconds(time_str):
56
+ """Converts an SRT timestamp string to milliseconds."""
57
+ hours, minutes, seconds_milliseconds = time_str.split(':')
58
+ seconds, milliseconds = seconds_milliseconds.split(',')
59
+ total_milliseconds = (int(hours) * 3600 + int(minutes) * 60 + int(seconds)) * 1000 + int(milliseconds)
60
+ return total_milliseconds
61
+
62
+
63
+ def milliseconds_to_srt_time(milliseconds):
64
+ """Converts milliseconds to an SRT timestamp string."""
65
+ milliseconds = int(milliseconds)
66
+ seconds, milliseconds = divmod(milliseconds, 1000)
67
+ minutes, seconds = divmod(seconds, 60)
68
+ hours, minutes = divmod(minutes, 60)
69
+ return f"{hours:02d}:{minutes:02d}:{seconds:02d},{milliseconds:03d}"
70
+
71
+
72
+ delay_at_start_ms = 10 # Delay at the beginning (you think it starts from 0)
73
+ delay_at_end_ms = 2200 # Delay at the end in milliseconds
74
+
75
+ for i in range(81, 93):
76
+ input_srt_file = f'srt/seoiwuzyun/{i:03d}.srt' # Your input SRT file
77
+ output_srt_file = f'{i:03d}.srt' # Output file name
78
+ audio_file_path = f'source/seoiwuzyun/{i:03d}.opus' # Your Opus audio file
79
+
80
+ fix_srt_delay(input_srt_file, output_srt_file, delay_at_start_ms, delay_at_end_ms, audio_file_path)
81
+ print(f"SRT file fixed and saved to {output_srt_file}")
cut.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import os
3
+ from typing import Literal
4
+
5
+ import pysrt
6
+ from pydub import AudioSegment
7
+
8
+
9
+ def srt_to_segments_with_metadata(srt_file, episode, audio_file, output_dir, metadata_file, subset: Literal["saamgwokjinji", "seoiwuzyun", "mouzaakdung"]):
10
+ # Load the SRT file
11
+ subs = pysrt.open(srt_file)
12
+
13
+ # Load the audio file (handling Opus)
14
+ try:
15
+ audio = AudioSegment.from_file(audio_file, codec="opus")
16
+ except Exception as e:
17
+ print(f"Error loading audio file: {audio_file}")
18
+ print(f"Error message: {e}")
19
+ return # Skip this file and move to the next
20
+
21
+ # Ensure the output directory exists
22
+ os.makedirs(output_dir, exist_ok=True)
23
+
24
+ # Prepare the metadata file (appending to a single file)
25
+ with open(metadata_file, mode='a', newline='', encoding='utf-8') as csvfile:
26
+ csvwriter = csv.writer(csvfile)
27
+
28
+ # Write header row if the file is empty
29
+ if os.stat(metadata_file).st_size == 0:
30
+ csvwriter.writerow(['id', 'episode_id', 'file_name', 'audio_duration', 'transcription'])
31
+
32
+ if subset == "saamgwokjinji":
33
+ prefix = "sg"
34
+ elif subset == "seoiwuzyun":
35
+ prefix = "sw"
36
+ elif subset == "mouzaakdung":
37
+ prefix = "mzd"
38
+
39
+ for index, sub in enumerate(subs):
40
+ # Get start and end times in milliseconds
41
+ start_time = sub.start.ordinal
42
+ end_time = sub.end.ordinal
43
+
44
+ # Calculate duration in seconds
45
+ duration = (end_time - start_time) / 1000
46
+
47
+ # Extract the audio segment
48
+ segment = audio[start_time:end_time]
49
+
50
+ # Define output filenames (using .opus extension)
51
+ segment_filename = f"{episode}_{index + 1:03d}.opus"
52
+ segment_id = f"{prefix}_{episode}_{index + 1:03d}"
53
+ audio_filename = os.path.join(output_dir, segment_filename)
54
+
55
+ # Export the audio segment as Opus
56
+ try:
57
+ segment.export(audio_filename, format="opus", codec="libopus")
58
+ except Exception as e:
59
+ print(f"Error exporting segment: {audio_filename}")
60
+ print(f"Error message: {e}")
61
+ continue # Skip to the next segment
62
+
63
+ # Write to the metadata CSV file
64
+ csvwriter.writerow(
65
+ [segment_id, episode, f'{episode}/{segment_filename}', f'{duration:.3f}', sub.text])
66
+
67
+ print(f"Segmentation of {audio_file} complete. Files saved to: {output_dir}")
68
+ print(f"Metadata appended to: {metadata_file}")
69
+
70
+
71
+ if __name__ == "__main__":
72
+ # subset = "saamgwokjinji"
73
+ # subset = "seoiwuzyun"
74
+ subset = "mouzaakdung"
75
+
76
+ print(f"Processing subset: {subset}")
77
+ # If append to existing metadata file
78
+ metadata_file = os.path.join("opus", subset, "metadata.csv") # Define metadata file path here
79
+
80
+ for episode in range(1, 11):
81
+ # If creating new csv
82
+ # metadata_file = f"{episode}.csv"
83
+ episode_str = f'{episode:03d}' # Format episode as 3-digit string
84
+
85
+ srt_file = f'srt/{subset}/{episode_str}.srt'
86
+ audio_file = f'source/{subset}/{episode_str}.opus'
87
+ output_dir = f'opus/{subset}/{episode_str}'
88
+
89
+ # Only process if the audio file exists
90
+ if os.path.exists(audio_file):
91
+ srt_to_segments_with_metadata(srt_file, episode_str, audio_file, output_dir, metadata_file, subset)
92
+ else:
93
+ print(f"Audio file not found: {audio_file}. Skipping.")
data/mouzaakdung-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1606f35073a1c239de9ec62b4aec31e8a1ecef4b11ae57e6ea2cd3b8070d703
3
+ size 258018039
data/saamgwokjinji-00000-of-00005.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20eca243c963ed547fc009e8fbc0f104ee242f51923ed57794c3dee84ebb533e
3
+ size 506328526
data/saamgwokjinji-00001-of-00005.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef5d77a349af8431985b22d7cf14d3b381282a319bfb66f2b6492f729d1aa013
3
+ size 490324223
data/saamgwokjinji-00002-of-00005.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d0720b693303668c7cc097434c3ef5956bea602a6497b8df8b1ce25a4830215
3
+ size 506386657
data/saamgwokjinji-00003-of-00005.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ec77147df6bc3509b01b94655d55717f2d547a61f782b795738af17dea752f8
3
+ size 537882717
data/saamgwokjinji-00004-of-00005.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:215bc6feed66a0a43e5abdadf3fddf43799a065f70cc20bf6f209a4f2a7034f3
3
+ size 554860857
data/seoiwuzyun-00000-of-00004.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:054437036a391f6c9342d05da7176cd57568579aae70a7a0441e6340d848d3a2
3
+ size 378457543
data/seoiwuzyun-00001-of-00004.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0fa346ce72e3a8aed97a0f60d335c91d1d696f2e0140d12698c0ece7bb5f3d8f
3
+ size 354053582
data/seoiwuzyun-00002-of-00004.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:50b0c5c44c8be71265d21087d554f25211ba5c9f3107ad7728c47f8f5b8c5067
3
+ size 343200042
data/seoiwuzyun-00003-of-00004.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa60eb7a1b98ef2c87482d631b246687522a088932537f4a5229b85d0ded357f
3
+ size 375410838
opus/mouzaakdung/001/001_001.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:852706fa117ef569fd3c901ce83fdd4c6bffa5d568f448f8fbc7429e034f0880
3
+ size 89509
opus/mouzaakdung/001/001_002.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ed2a2b0c8214973d90b90fafe2a0b6d7c20da44e305f2a15872ce41c43417120
3
+ size 167069
opus/mouzaakdung/001/001_003.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:510419a6f7900ccaa072da576bbc67ae669005fe300bba44b50ac2e9aa2e5a11
3
+ size 80161
opus/mouzaakdung/001/001_004.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:60c3aa4571e4c71f05a0612a06f82138a529d7831529a526d0d8cd64922ac6cd
3
+ size 76177
opus/mouzaakdung/001/001_005.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9789c0105c1f81b78a1de6a0a21927b25a94b9776468865bde81791becafba04
3
+ size 85765
opus/mouzaakdung/001/001_006.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cca482e922c86916bf8296e85b5f5ae7d89054ff9e2576879f524d80fb7959c9
3
+ size 68110
opus/mouzaakdung/001/001_007.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f90f4ba2a8fe4bd7383aa6de9211cfb442faf9d64b3e3454430d9dabaf7e40a
3
+ size 35533
opus/mouzaakdung/001/001_008.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6062f163cde6e0d6b90e845aa92197e03ea932b8d5fd93a2e3d6b442eabd06f5
3
+ size 26623
opus/mouzaakdung/001/001_009.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea4f11afc4216e81ddbc4fb17fe095e5772b3859a919584e60e5680116ae7862
3
+ size 33222
opus/mouzaakdung/001/001_010.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec791f372b144275d3fa406e5788c4665a385b4b6263dd4488b538a16cf0efd4
3
+ size 72207
opus/mouzaakdung/001/001_011.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4870575087f1e2243619b7560cbe2be604ec994738cac429e23617fd31c483d2
3
+ size 68688
opus/mouzaakdung/001/001_012.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fc5b8896763ecfcb1ea7ea2beb6729f09b54f6cc246948833aa0802483771d02
3
+ size 48739
opus/mouzaakdung/001/001_013.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:351b6d4570af160c448ff61c36757a0f676b5acb1669e4088fd13f85c024aeb2
3
+ size 54473
opus/mouzaakdung/001/001_014.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c10d2683bb760adf947bedbaf5f9610152b284b93cd8c2e8e68b9c6891d60fc
3
+ size 64699
opus/mouzaakdung/001/001_015.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73de7ac6694716ac3d2b37055277a55246a1eb3e09d19cdeabe4fee3e3fbff72
3
+ size 47876
opus/mouzaakdung/001/001_016.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1dd443555e314dc088b2d5d747629b81587a21f915b4bae888b955a625cf0bf
3
+ size 44710
opus/mouzaakdung/001/001_017.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2cc7d0619a94650df3ed79f8c1ddc582d38d640aad341aed71ffef114f456d1
3
+ size 107544
opus/mouzaakdung/001/001_018.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a001826f759d2708d14b3e574b8699edc8af87dc9f5bba5769bb207ee6c8624
3
+ size 73568
opus/mouzaakdung/001/001_019.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:27618e7601b5b3aa5444603192882ee9ea2bd83664cb024d7c908bff14b82d22
3
+ size 23742
opus/mouzaakdung/001/001_020.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:986a7b78990cf98234c99e17e24be8bd6823a0917b75ff61210ea5c8649aa83a
3
+ size 35386
opus/mouzaakdung/001/001_021.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:237ccc6d38145ab4e4762be3b95c31b57652bddb3b6856af62cef6f84bb724e9
3
+ size 161842
opus/mouzaakdung/001/001_022.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3bd1e7af08738b5860393368137dd45f9b14b9cf185b0560d14ccfdc57ae09b
3
+ size 45131
opus/mouzaakdung/001/001_023.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cfef31e6310293c5e7b09de7d06d667048ab268f1d41ae52608af93c2d5f4448
3
+ size 64060
opus/mouzaakdung/001/001_024.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ed054ad87d3a1dbf8c9b1a7065e01e0bc89ff171c4c9511cf684b2f3d16c34f
3
+ size 99336
opus/mouzaakdung/001/001_025.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbe98a12b4b46034491ce07d46ad96f7468995f9aaf3ebabc6ddf6151739e6ec
3
+ size 42280
opus/mouzaakdung/001/001_026.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dec17b30b11e94349a9e764984c645f75468c795c6eaa35f51532ad4424a0a96
3
+ size 36802
opus/mouzaakdung/001/001_027.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3dd6ebedbe515da43c82bcfd4719b6f53b279c3d4f00da85c71c3a1122eb6959
3
+ size 44993
opus/mouzaakdung/001/001_028.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a935c3bfe5ba09a9c7b3bc237141e78a8e6d3a5c6a981733cb224dd5fd3de15e
3
+ size 38810
opus/mouzaakdung/001/001_029.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:184219b51ff2c9df583b8269dec9cb31467e943d439bc76bd6fbe8d337dea34f
3
+ size 112358
opus/mouzaakdung/001/001_030.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d3f0c73c1627888bb120d477e031945cb50d53befc6eb3a54c16d408de13944
3
+ size 43633
opus/mouzaakdung/001/001_031.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd4302f47b4e7f021421309b0cde42e4092f3bf4242a485453e5574ea256cb68
3
+ size 31991
opus/mouzaakdung/001/001_032.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:465b7afcfc8c78bf8260803372038c3f631b0b48d5978ad1cd72c51c4ee904c4
3
+ size 40376
opus/mouzaakdung/001/001_033.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aeaff11051948157010faa5a4b6bc9787d7f9be94415f997cef56a4e95e06c93
3
+ size 96140
opus/mouzaakdung/001/001_034.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ff34796da947db8c770b4c8460382b888f1d7ad55d75f4317917858dfb19433
3
+ size 35846
opus/mouzaakdung/001/001_035.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9805b47efe2ee1d046f1acf5d88d68d15b24a5b94a2ae9749ca8e8d1965ffebe
3
+ size 44020