Spaces:
Runtime error
Runtime error
Update src/utils.py
Browse files- src/utils.py +7 -3
src/utils.py
CHANGED
@@ -7,7 +7,7 @@ from typing import Iterator, TextIO, Union
|
|
7 |
import tqdm
|
8 |
|
9 |
import urllib3
|
10 |
-
|
11 |
|
12 |
def exact_div(x, y):
|
13 |
assert x % y == 0
|
@@ -52,8 +52,10 @@ def format_timestamp(seconds: float, always_include_hours: bool = False, fractio
|
|
52 |
|
53 |
|
54 |
def write_txt(transcript: Iterator[dict], file: TextIO):
|
|
|
55 |
for segment in transcript:
|
56 |
-
|
|
|
57 |
|
58 |
|
59 |
def write_vtt(transcript: Iterator[dict], file: TextIO,
|
@@ -86,9 +88,11 @@ def write_srt(transcript: Iterator[dict], file: TextIO,
|
|
86 |
write_srt(result["segments"], file=srt)
|
87 |
"""
|
88 |
iterator = __subtitle_preprocessor_iterator(transcript, maxLineWidth, highlight_words)
|
|
|
89 |
|
90 |
for i, segment in enumerate(iterator, start=1):
|
91 |
-
|
|
|
92 |
|
93 |
# write srt lines
|
94 |
print(
|
|
|
7 |
import tqdm
|
8 |
|
9 |
import urllib3
|
10 |
+
import opencc
|
11 |
|
12 |
def exact_div(x, y):
|
13 |
assert x % y == 0
|
|
|
52 |
|
53 |
|
54 |
def write_txt(transcript: Iterator[dict], file: TextIO):
|
55 |
+
converter = opencc.OpenCC('s2twp') #s2twp.json - 簡體到繁體(臺灣正體標準)並轉換爲臺灣常用詞彙
|
56 |
for segment in transcript:
|
57 |
+
segment_text = converter.convert(segment['text'].strip())
|
58 |
+
print(segment_text, file=file, flush=True)
|
59 |
|
60 |
|
61 |
def write_vtt(transcript: Iterator[dict], file: TextIO,
|
|
|
88 |
write_srt(result["segments"], file=srt)
|
89 |
"""
|
90 |
iterator = __subtitle_preprocessor_iterator(transcript, maxLineWidth, highlight_words)
|
91 |
+
converter = opencc.OpenCC('s2twp') #s2twp.json - 簡體到繁體(臺灣正體標準)並轉換爲臺灣常用詞彙
|
92 |
|
93 |
for i, segment in enumerate(iterator, start=1):
|
94 |
+
segment_text = segment['text'].replace('-->', '->')
|
95 |
+
text = converter.convert(segment_text)
|
96 |
|
97 |
# write srt lines
|
98 |
print(
|