Update server/subtitle.py
Browse files- server/subtitle.py +8 -5
server/subtitle.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
import re
|
| 2 |
import os
|
|
|
|
|
|
|
|
|
|
| 3 |
def convert_time_to_srt_format(seconds):
|
| 4 |
"""Converts seconds to the standard SRT time format (HH:MM:SS,ms)."""
|
| 5 |
hours = int(seconds // 3600)
|
|
@@ -83,7 +86,7 @@ def merge_punctuation_glitches(subtitles):
|
|
| 83 |
|
| 84 |
return cleaned
|
| 85 |
|
| 86 |
-
|
| 87 |
def write_sentence_srt(
|
| 88 |
word_level_timestamps, output_file="subtitles_professional.srt", max_lines=2,
|
| 89 |
max_duration_s=7.0, max_chars_per_line=38, hard_pause_threshold=0.5,
|
|
@@ -206,10 +209,10 @@ def write_sentence_srt(
|
|
| 206 |
def make_subtitle(word_level_timestamps,file_path):
|
| 207 |
os.makedirs("./subtitles/",exist_ok=True)
|
| 208 |
file_name = os.path.splitext(os.path.basename(file_path))[0]
|
| 209 |
-
|
| 210 |
-
word_level_srt_file=f"./subtitles/{file_name}
|
| 211 |
-
sentence_srt_file=f"./subtitles/{file_name}
|
| 212 |
-
shorts_srt_file=f"./subtitles/{file_name}
|
| 213 |
word_level_srt(
|
| 214 |
word_level_timestamps,
|
| 215 |
srt_path=word_level_srt_file,
|
|
|
|
| 1 |
import re
|
| 2 |
import os
|
| 3 |
+
import uuid
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
def convert_time_to_srt_format(seconds):
|
| 7 |
"""Converts seconds to the standard SRT time format (HH:MM:SS,ms)."""
|
| 8 |
hours = int(seconds // 3600)
|
|
|
|
| 86 |
|
| 87 |
return cleaned
|
| 88 |
|
| 89 |
+
|
| 90 |
def write_sentence_srt(
|
| 91 |
word_level_timestamps, output_file="subtitles_professional.srt", max_lines=2,
|
| 92 |
max_duration_s=7.0, max_chars_per_line=38, hard_pause_threshold=0.5,
|
|
|
|
| 209 |
def make_subtitle(word_level_timestamps,file_path):
|
| 210 |
os.makedirs("./subtitles/",exist_ok=True)
|
| 211 |
file_name = os.path.splitext(os.path.basename(file_path))[0]
|
| 212 |
+
unique_id = str(uuid.uuid4())[:6]
|
| 213 |
+
word_level_srt_file=f"./subtitles/{file_name}_subtitle_word_level_{unique_id}.srt"
|
| 214 |
+
sentence_srt_file=f"./subtitles/{file_name}_subtitle_sentences_{unique_id}.srt"
|
| 215 |
+
shorts_srt_file=f"./subtitles/{file_name}_subtitle_reels_{unique_id}.srt"
|
| 216 |
word_level_srt(
|
| 217 |
word_level_timestamps,
|
| 218 |
srt_path=word_level_srt_file,
|