Spaces:
Running
Running
Merge pull request #360 from jhj0517/fix/vtt
Browse files
modules/utils/subtitle_manager.py
CHANGED
@@ -36,7 +36,6 @@ def get_srt(segments):
|
|
36 |
def get_vtt(segments):
|
37 |
output = "WebVTT\n\n"
|
38 |
for i, segment in enumerate(segments):
|
39 |
-
output += f"{i + 1}\n"
|
40 |
output += f"{timeformat_vtt(segment['start'])} --> {timeformat_vtt(segment['end'])}\n"
|
41 |
if segment['text'].startswith(' '):
|
42 |
segment['text'] = segment['text'][1:]
|
@@ -87,12 +86,10 @@ def parse_vtt(file_path):
|
|
87 |
for block in blocks:
|
88 |
if block.strip() != '' and not block.strip().startswith("WebVTT"):
|
89 |
lines = block.strip().split('\n')
|
90 |
-
|
91 |
-
|
92 |
-
sentence = ' '.join(lines[2:])
|
93 |
|
94 |
data.append({
|
95 |
-
"index": index,
|
96 |
"timestamp": timestamp,
|
97 |
"sentence": sentence
|
98 |
})
|
@@ -112,7 +109,6 @@ def get_serialized_srt(dicts):
|
|
112 |
def get_serialized_vtt(dicts):
|
113 |
output = "WebVTT\n\n"
|
114 |
for dic in dicts:
|
115 |
-
output += f'{dic["index"]}\n'
|
116 |
output += f'{dic["timestamp"]}\n'
|
117 |
output += f'{dic["sentence"]}\n\n'
|
118 |
return output
|
|
|
36 |
def get_vtt(segments):
|
37 |
output = "WebVTT\n\n"
|
38 |
for i, segment in enumerate(segments):
|
|
|
39 |
output += f"{timeformat_vtt(segment['start'])} --> {timeformat_vtt(segment['end'])}\n"
|
40 |
if segment['text'].startswith(' '):
|
41 |
segment['text'] = segment['text'][1:]
|
|
|
86 |
for block in blocks:
|
87 |
if block.strip() != '' and not block.strip().startswith("WebVTT"):
|
88 |
lines = block.strip().split('\n')
|
89 |
+
timestamp = lines[0]
|
90 |
+
sentence = ' '.join(lines[1:])
|
|
|
91 |
|
92 |
data.append({
|
|
|
93 |
"timestamp": timestamp,
|
94 |
"sentence": sentence
|
95 |
})
|
|
|
109 |
def get_serialized_vtt(dicts):
|
110 |
output = "WebVTT\n\n"
|
111 |
for dic in dicts:
|
|
|
112 |
output += f'{dic["timestamp"]}\n'
|
113 |
output += f'{dic["sentence"]}\n\n'
|
114 |
return output
|