laubonghaudoi commited on
Commit
32adf42
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 +214 -0
  4. align.py +81 -0
  5. cut.py +90 -0
  6. data/saamgwokjinji-00000-of-00005.parquet +3 -0
  7. data/saamgwokjinji-00001-of-00005.parquet +3 -0
  8. data/saamgwokjinji-00002-of-00005.parquet +3 -0
  9. data/saamgwokjinji-00003-of-00005.parquet +3 -0
  10. data/saamgwokjinji-00004-of-00005.parquet +3 -0
  11. data/seoiwuzyun-00000-of-00002.parquet +3 -0
  12. data/seoiwuzyun-00001-of-00002.parquet +3 -0
  13. opus/saamgwokjinji/001/001_001.opus +3 -0
  14. opus/saamgwokjinji/001/001_002.opus +3 -0
  15. opus/saamgwokjinji/001/001_003.opus +3 -0
  16. opus/saamgwokjinji/001/001_004.opus +3 -0
  17. opus/saamgwokjinji/001/001_005.opus +3 -0
  18. opus/saamgwokjinji/001/001_006.opus +3 -0
  19. opus/saamgwokjinji/001/001_007.opus +3 -0
  20. opus/saamgwokjinji/001/001_008.opus +3 -0
  21. opus/saamgwokjinji/001/001_009.opus +3 -0
  22. opus/saamgwokjinji/001/001_010.opus +3 -0
  23. opus/saamgwokjinji/001/001_011.opus +3 -0
  24. opus/saamgwokjinji/001/001_012.opus +3 -0
  25. opus/saamgwokjinji/001/001_013.opus +3 -0
  26. opus/saamgwokjinji/001/001_014.opus +3 -0
  27. opus/saamgwokjinji/001/001_015.opus +3 -0
  28. opus/saamgwokjinji/001/001_016.opus +3 -0
  29. opus/saamgwokjinji/001/001_017.opus +3 -0
  30. opus/saamgwokjinji/001/001_018.opus +3 -0
  31. opus/saamgwokjinji/001/001_019.opus +3 -0
  32. opus/saamgwokjinji/001/001_020.opus +3 -0
  33. opus/saamgwokjinji/001/001_021.opus +3 -0
  34. opus/saamgwokjinji/001/001_022.opus +3 -0
  35. opus/saamgwokjinji/001/001_023.opus +3 -0
  36. opus/saamgwokjinji/001/001_024.opus +3 -0
  37. opus/saamgwokjinji/001/001_025.opus +3 -0
  38. opus/saamgwokjinji/001/001_026.opus +3 -0
  39. opus/saamgwokjinji/001/001_027.opus +3 -0
  40. opus/saamgwokjinji/001/001_028.opus +3 -0
  41. opus/saamgwokjinji/001/001_029.opus +3 -0
  42. opus/saamgwokjinji/001/001_030.opus +3 -0
  43. opus/saamgwokjinji/001/001_031.opus +3 -0
  44. opus/saamgwokjinji/001/001_032.opus +3 -0
  45. opus/saamgwokjinji/001/001_033.opus +3 -0
  46. opus/saamgwokjinji/001/001_034.opus +3 -0
  47. opus/saamgwokjinji/001/001_035.opus +3 -0
  48. opus/saamgwokjinji/001/001_036.opus +3 -0
  49. opus/saamgwokjinji/001/001_037.opus +3 -0
  50. opus/saamgwokjinji/001/001_038.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,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ tags:
24
+ - cantonese
25
+ - audio
26
+ - art
27
+ dataset_info:
28
+ features:
29
+ - name: audio
30
+ dtype: audio
31
+ - name: id
32
+ dtype: string
33
+ - name: episode_id
34
+ dtype: int64
35
+ - name: audio_duration
36
+ dtype: float64
37
+ - name: transcription
38
+ dtype: string
39
+ splits:
40
+ - name: saamgwokjinji
41
+ num_bytes: 2398591354.589
42
+ num_examples: 39173
43
+ - name: seoiwuzyun
44
+ num_bytes: 871002777.5
45
+ num_examples: 13226
46
+ download_size: 3369027141
47
+ dataset_size: 3269594132.089
48
+ ---
49
+
50
+ # 張悦楷講《三國演義》《水滸傳》語音數據集
51
+
52
+ [English](#the-zoeng-jyut-gaai-story-telling-speech-dataset)
53
+
54
+ ## Dataset Description
55
+
56
+ - **Homepage:** [張悦楷講古語音數據集 The Zoeng Jyut Gaai Story-telling Speech Dataset](https://canclid.github.io/zoengjyutgaai/)
57
+
58
+ 呢個係張悦楷講《三國演義》同《水滸傳》語音數據集。[張悦楷](https://zh.wikipedia.org/wiki/%E5%BC%A0%E6%82%A6%E6%A5%B7)係廣州最出名嘅講古佬 / 粵語説書藝人。佢從上世紀七十年代開始就喺廣東各個收音電台度講古,佢把聲係好多廣州人嘅共同回憶。本數據集《三國演義》係佢最知名嘅作品一。
59
+
60
+ 數據集用途:
61
+
62
+ - TTS(語音合成)訓練集
63
+ - ASR(語音識別)訓練集或測試集
64
+ - 各種語言學、文學研究
65
+ - 直接聽嚟欣賞藝術!
66
+
67
+ TTS 效果演示:https://huggingface.co/spaces/laubonghaudoi/zoengjyutgaai_tts
68
+
69
+ ## 説明
70
+
71
+ - 所有文本都根據 https://jyutping.org/blog/typo/ 同 https://jyutping.org/blog/particles/ 規範用字。
72
+ - 所有文本都使用全角標點,冇半角標點。
73
+ - 所有文本都用漢字轉寫,無阿拉伯數字無英文字母
74
+ - 所有音頻源都存放喺`/source`,為方便直接用作訓練數據,切分後嘅音頻都放喺 `opus/`
75
+ - 所有源字幕 SRT 文件都存放喺 `srt/` 路經下,搭配 `source/` 下嘅音源可以直接作為帶字幕嘅錄音直接欣賞。
76
+ - `cut.py` 係切分腳本,將對應嘅音源根據 srt 切分成短句並生成一個文本轉寫 csv。
77
+ - `stats.py` 係統計腳本,運行佢就會顯示成個數據集嘅各項統計數據。
78
+
79
+ ## 下載使用
80
+
81
+ 要下載使用呢個數據集,可以喺 Python 入面直接跑:
82
+
83
+ ```python
84
+ from datasets import load_dataset
85
+
86
+ ds = load_dataset("CanCLID/zoengjyutgaai_saamgwokjinji")
87
+ ```
88
+
89
+ 如果想單純將 `opus/` 入面所有嘢下載落嚟,可以跑下面嘅 Python 代碼,注意要安裝 `pip install --upgrade huggingface_hub` 先:
90
+
91
+ ```python
92
+ from huggingface_hub import snapshot_download
93
+
94
+ # 如果你淨係想下載啲字幕或者源音頻,噉就將下面嘅 `wav/*` 改成 `srt/*` 或者 `webm/*`
95
+ snapshot_download(repo_id="CanCLID/zoengjyutgaai_saamgwokjinji",allow_patterns="opus/*",local_dir="./",repo_type="dataset")
96
+ ```
97
+
98
+ 如果唔想用 python,你亦都可以用命令行叫 git 針對克隆個`opus/`或者其他路經,避免將成個 repo 都克隆落嚟浪費空間同下載時間:
99
+
100
+ ```bash
101
+ mkdir zoengjyutgaai_saamgwokjinji
102
+ cd zoengjyutgaai_saamgwokjinji
103
+ git init
104
+
105
+ git remote add origin https://huggingface.co/datasets/CanCLID/zoengjyutgaai_saamgwokjinji
106
+ git sparse-checkout init --cone
107
+
108
+ # 指定凈係下載個別路徑
109
+ git sparse-checkout set opus
110
+
111
+ # 開始下載
112
+ git pull origin main
113
+ ```
114
+
115
+ ### 數據集構建流程
116
+
117
+ 本數據集嘅收集、構建過程係:
118
+
119
+ 1. 從 YouTube 或者國內評書網站度下載錄音源文件,一般都係每集半個鐘長嘅 `.webm` 或者 `.mp3`。
120
+ 1. 用加字幕工具幫呢啲錄音加字幕,得到對應嘅 `.srt` 文件。
121
+ 1. 將啲源錄音用下面嘅命令儘可能無壓縮噉轉換成 `.opus` 格式。
122
+ 1. 運行`cut.py`,將每一集 `.opus` 按照 `.srt` 入面嘅時間點切分成一句一個 `.opus`,然後對應嘅文本寫入本數據集嘅 `xxx.csv`。
123
+ 1. 然後打開一個 IPython,逐句跑下面嘅命令,將啲數據推上 HuggingFace。
124
+
125
+ ```python
126
+ from datasets import load_dataset, DatasetDict
127
+ from huggingface_hub import login
128
+
129
+ sg = load_dataset('audiofolder', data_dir='./opus/saamgwokjinji')
130
+ sw = load_dataset('audiofolder', data_dir='./opus/seoiwuzyun')
131
+ dataset = DatasetDict({
132
+ "saamgwokjinji": sg["train"],
133
+ "seoiwuzyun": sw["train"],
134
+ })
135
+
136
+ # 檢查下讀入嘅數據有冇問題
137
+ dataset['train'][0]
138
+ # 準備好個 token 嚟登入
139
+ login()
140
+ # 推上 HuggingFace datasets
141
+ dataset.push_to_hub("CanCLID/zoengjyutgaai_saamgwokjinji")
142
+ ```
143
+
144
+ ### 音頻格式轉換
145
+
146
+ 首先要安裝 [ffmpeg](https://www.ffmpeg.org/download.html),然後運行:
147
+
148
+ ```bash
149
+ # 將下載嘅音源由 webm 轉成 opus
150
+ ffmpeg -i webm/saamgwokjinji/001.webm -c:a copy source/saamgwokjinji/001.opus
151
+ # 將 opus 轉成無損 wav
152
+ ffmpeg -i source/saamgwokjinji/001.opus -c:a copy wav/saamgwokjinji/001.wav
153
+ ```
154
+
155
+ 本數據集所有 opus 音頻皆為 48000 Hz 採樣率。
156
+
157
+ # The Zoeng Jyut Gaai Story-telling Speech Dataset
158
+
159
+ This is a speech dataset of Zoeng Jyut Gaai story-telling _Romance of the Three Kingdoms_ and _Water Margin_. [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 one of his most well-known story-telling piece: _Romance of the Three Kingdoms_.
160
+
161
+ Use case of this dataset:
162
+
163
+ - TTS (Text-To-Speech) training set
164
+ - ASR (Automatic Speech Recognition) training or eval set
165
+ - Various linguistics / art analysis
166
+ - Just listen and enjoy the art piece!
167
+
168
+ TTS demo: https://huggingface.co/spaces/laubonghaudoi/zoengjyutgaai_tts
169
+
170
+ ## Introduction
171
+
172
+ - All transcriptions follow the prescribed orthography detailed in https://jyutping.org/blog/typo/ and https://jyutping.org/blog/particles/
173
+ - All transcriptions use full-width punctuations, no half-width punctuations is used.
174
+ - All transcriptions are in Chinese characters, no Arabic numbers or Latin letters.
175
+ - All source audio are stored in `source/`. For the convenice of training, segmented audios are stored in `opus/`.
176
+ - All source subtitle SRT files are stored in `srt/`. Use them with the webm files to enjoy subtitled storytelling pieces.
177
+ - `cut.py` is the script for cutting opus audios into senteneces based on the srt, and generates a csv file for transcriptions.
178
+ - `stats.py` is the script for getting stats of this dataset.
179
+
180
+ ## Usage
181
+
182
+ To use this dataset, simply run in Python:
183
+
184
+ ```python
185
+ from datasets import load_dataset
186
+
187
+ ds = load_dataset("CanCLID/zoengjyutgaai_saamgwokjinji")
188
+ ```
189
+
190
+ 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:
191
+
192
+ ```python
193
+ from huggingface_hub import snapshot_download
194
+
195
+ # If you only want to download the source audio or the subtitles, change the `wav/*` below into `srt/*` or `webm/*`
196
+ snapshot_download(repo_id="CanCLID/zoengjyutgaai_saamgwokjinji",allow_patterns="opus/*",local_dir="./",repo_type="dataset")
197
+ ```
198
+
199
+ 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:
200
+
201
+ ```bash
202
+ mkdir zoengjyutgaai_saamgwokjinji
203
+ cd zoengjyutgaai_saamgwokjinji
204
+ git init
205
+
206
+ git remote add origin https://huggingface.co/datasets/CanCLID/zoengjyutgaai_saamgwokjinji
207
+ git sparse-checkout init --cone
208
+
209
+ # Tell git which directory you want
210
+ git sparse-checkout set opus
211
+
212
+ # Pull the content
213
+ git pull origin main
214
+ ```
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(46, 51):
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,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"]):
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
+
37
+ for index, sub in enumerate(subs):
38
+ # Get start and end times in milliseconds
39
+ start_time = sub.start.ordinal
40
+ end_time = sub.end.ordinal
41
+
42
+ # Calculate duration in seconds
43
+ duration = (end_time - start_time) / 1000
44
+
45
+ # Extract the audio segment
46
+ segment = audio[start_time:end_time]
47
+
48
+ # Define output filenames (using .opus extension)
49
+ segment_filename = f"{episode}_{index + 1:03d}.opus"
50
+ segment_id = f"{prefix}_{episode}_{index + 1:03d}"
51
+ audio_filename = os.path.join(output_dir, segment_filename)
52
+
53
+ # Export the audio segment as Opus
54
+ try:
55
+ segment.export(audio_filename, format="opus", codec="libopus")
56
+ except Exception as e:
57
+ print(f"Error exporting segment: {audio_filename}")
58
+ print(f"Error message: {e}")
59
+ continue # Skip to the next segment
60
+
61
+ # Write to the metadata CSV file
62
+ csvwriter.writerow(
63
+ [segment_id, episode, f'{episode}/{segment_filename}', f'{duration:.3f}', sub.text])
64
+
65
+ print(f"Segmentation of {audio_file} complete. Files saved to: {output_dir}")
66
+ print(f"Metadata appended to: {metadata_file}")
67
+
68
+
69
+ if __name__ == "__main__":
70
+ # subset = "saamgwokjinji"
71
+ subset = "seoiwuzyun"
72
+
73
+ print(f"Processing subset: {subset}")
74
+ # If append to existing metadata file
75
+ metadata_file = os.path.join("opus", subset, "metadata.csv") # Define metadata file path here
76
+
77
+ for episode in range(46, 51):
78
+ # If creating new csv
79
+ # metadata_file = f"{episode}.csv"
80
+ episode_str = f'{episode:03d}' # Format episode as 3-digit string
81
+
82
+ srt_file = f'srt/{subset}/{episode_str}.srt'
83
+ audio_file = f'source/{subset}/{episode_str}.opus'
84
+ output_dir = f'opus/{subset}/{episode_str}'
85
+
86
+ # Only process if the audio file exists
87
+ if os.path.exists(audio_file):
88
+ srt_to_segments_with_metadata(srt_file, episode_str, audio_file, output_dir, metadata_file, subset)
89
+ else:
90
+ print(f"Audio file not found: {audio_file}. Skipping.")
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-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6654300fc26794e226993b104aef581ec9e33e6f762089e4b26b0a5d83c39d68
3
+ size 405167971
data/seoiwuzyun-00001-of-00002.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b255d3ad1f158fec9ae2091a6bdaef223bcc4d82e93a0c3196019d87670e86fc
3
+ size 368076190
opus/saamgwokjinji/001/001_001.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4798e072468e3b204f3937c1cb0ead4604ec026fce77fa2a9d246011d06b03c3
3
+ size 65449
opus/saamgwokjinji/001/001_002.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb00535a1c1e95d56d95cc015c47139ab88e82a20244bbe8c2b85721594a6711
3
+ size 67999
opus/saamgwokjinji/001/001_003.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1e904623e3b7c63a195bb46f67619f9c47e024b5891f7a5a5e69ae869bb7bf0
3
+ size 83804
opus/saamgwokjinji/001/001_004.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:30cbaad9d436c1ce3743e1307c39f8b6570e319374ad8ead1a82f410c3bf99ed
3
+ size 61748
opus/saamgwokjinji/001/001_005.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:86101cd6a4a0e42aeda2159f5f44b9d6de46fd490dddf7e395f96bb913c75fbe
3
+ size 95918
opus/saamgwokjinji/001/001_006.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d02d966f1314c1844ab83e286eee1d4b003258ee0dd317ce18a14c18a6df6c8
3
+ size 58115
opus/saamgwokjinji/001/001_007.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e2cde79a079fd8ef68a42303526e5a85b678c6cac11ad4742a3a77d6211ce70
3
+ size 48902
opus/saamgwokjinji/001/001_008.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b4d884771a24e5ec5388c3db719b96413019fd0c995d586949c880ccaf3813f7
3
+ size 78241
opus/saamgwokjinji/001/001_009.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9495503ed10164af3a9f21c1afd6eec6043b18ecf06f8f3247ad9a00aacff539
3
+ size 108835
opus/saamgwokjinji/001/001_010.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e61f6b9040f22b1de18ccb912c6fa407de8555feb08960b8e52499dd3a7f2478
3
+ size 37190
opus/saamgwokjinji/001/001_011.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ef6339e378eaf20079706fec71ade893d19b54f7a80e7c43d3f8497af2dbe08
3
+ size 42244
opus/saamgwokjinji/001/001_012.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:815ab9c76085f92b600108d284f679f7c44c9bbfeba248be0e99bf5eed2d3ff7
3
+ size 57232
opus/saamgwokjinji/001/001_013.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44d81204deb3eb12dcae928b45daf2bd5d7efb3703f0fe5bddc8d613760381a3
3
+ size 105204
opus/saamgwokjinji/001/001_014.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3475a25db07d2411910c8ffab85b5b61ddb43554faee8fa5717e6a743041eacf
3
+ size 65172
opus/saamgwokjinji/001/001_015.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:265b540be4848083e4e8601875a07d4faa94d3efc0d144309b855a27c820fff8
3
+ size 115372
opus/saamgwokjinji/001/001_016.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99a2afa8af94bfbbd8b59cdf6ef2a07473a7a3b4b7baf2734400c0b7cd357142
3
+ size 35823
opus/saamgwokjinji/001/001_017.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5bab152350ccbbcd75b498c3431f8af1693f06a8cf281c251c0c8092e859a9d3
3
+ size 55699
opus/saamgwokjinji/001/001_018.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ac9c9035269354eb18e07df8c42f0e87104ce4776116b7e03bb0d17ccc18231
3
+ size 44688
opus/saamgwokjinji/001/001_019.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b69b0a01f86e35eb5522ff8d35b1c0435aa340908bf9cafb9e99a40e93d25f03
3
+ size 29331
opus/saamgwokjinji/001/001_020.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61b240e6eda1ca4e0cfc7a122b77040fda98bc787dfc9eb1dade99fd5ec30ca3
3
+ size 36183
opus/saamgwokjinji/001/001_021.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be891a87a6d82b58b4fdddf9ba25b44a25dfadf090ed3e1e3d9e74299897f341
3
+ size 28515
opus/saamgwokjinji/001/001_022.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e3027b3fe8436f116bb9ec64c8510e8d7ad834438da096ec39534aac7ac66f0
3
+ size 65524
opus/saamgwokjinji/001/001_023.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2573e0c2b691129c6b92d37b76e9b5dde841ca26de583da47f23e5eb86cb4a3e
3
+ size 30416
opus/saamgwokjinji/001/001_024.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dcf5467ec466fb8482cc29c0babfd06d254f3a909c8ebec474121d8015d2ad30
3
+ size 62313
opus/saamgwokjinji/001/001_025.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e6c310ada194fb284719c0ca6b0c961ddf7d1d8b527aa8b40d402547121f9f7b
3
+ size 48591
opus/saamgwokjinji/001/001_026.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bb9d7b8160bfdbde750d31383b66b111009e5738b8869a45ceced4c37c95fed2
3
+ size 43641
opus/saamgwokjinji/001/001_027.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:adb19a1898a4af9679d00c02b1f2966dd7375e5539a1731b18f42c3d708ec4c3
3
+ size 60553
opus/saamgwokjinji/001/001_028.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:caf29f0a8277a35bbc6200d7c4575223a52962a7634fe12c4ccfbdc2af60e155
3
+ size 54045
opus/saamgwokjinji/001/001_029.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42c23719adf4898c0fdd011c4baf6507077ccfca9a28380bb513f49d1702fe95
3
+ size 63105
opus/saamgwokjinji/001/001_030.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:96f92fa8f91dd7dff1fcc4a020558d19c60b43ee7199ab6be14a21613ea857f5
3
+ size 35595
opus/saamgwokjinji/001/001_031.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:03912b69f456c934744425085ba6d76bd12559745b371cf7046eddfd0744c8ea
3
+ size 86316
opus/saamgwokjinji/001/001_032.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41d7722e86fe19213280391e5558f9417a19415df3cdbf61b5bbbd089514afe8
3
+ size 61512
opus/saamgwokjinji/001/001_033.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bbce2cfefafcef75ab8a1d35582c021c19c6d4780ebff7803964be04199240a5
3
+ size 33325
opus/saamgwokjinji/001/001_034.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:75e7089ea6a98865fa2d8f3a9a205a020e8c0b1d3f3fc6846ea247098599e5a2
3
+ size 101849
opus/saamgwokjinji/001/001_035.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:836fd47a00ec6815d70ac5287656a3b372b6d8fd6055a3baf8ad4d7d6dd7876f
3
+ size 39997
opus/saamgwokjinji/001/001_036.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02b0da4d821581ec93cc163bee631e1cbb53500f7b2490ab1eebe2bb52a9bd8e
3
+ size 37052
opus/saamgwokjinji/001/001_037.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d6fb3fb0f843a0b480a4ab33f72aab9e3b18ea998c95e254cb80f5cda605096
3
+ size 60397
opus/saamgwokjinji/001/001_038.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3afdeae41f08f827b9b651c03242f0d87944a99c6ba6d1782b7e0d6190e87fe1
3
+ size 39242