Spaces:
Running
Running
jhj0517 commited on
Commit ·
28dc833
1
Parent(s): 2efa275
Fix time format and translation case
Browse files
modules/utils/subtitle_manager.py
CHANGED
|
@@ -14,7 +14,7 @@ from .files_manager import read_file
|
|
| 14 |
|
| 15 |
def format_timestamp(
|
| 16 |
seconds: float, always_include_hours: bool = True, decimal_marker: str = ","
|
| 17 |
-
):
|
| 18 |
assert seconds >= 0, "non-negative timestamp expected"
|
| 19 |
milliseconds = round(seconds * 1000.0)
|
| 20 |
|
|
@@ -34,10 +34,17 @@ def format_timestamp(
|
|
| 34 |
|
| 35 |
|
| 36 |
def time_str_to_seconds(time_str: str, decimal_marker: str = ",") -> float:
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
seconds, fractional = rest.split(decimal_marker)
|
| 39 |
|
| 40 |
-
hours = int(hours)
|
| 41 |
minutes = int(minutes)
|
| 42 |
seconds = int(seconds)
|
| 43 |
fractional_seconds = float("0." + fractional)
|
|
@@ -401,7 +408,7 @@ def generate_file(
|
|
| 401 |
file_path = os.path.join(output_dir, f"{output_file_name}.{output_format}")
|
| 402 |
file_writer = get_writer(output_format=output_format, output_dir=output_dir)
|
| 403 |
|
| 404 |
-
if isinstance(file_writer, WriteLRC) and kwargs
|
| 405 |
kwargs["highlight_words"], kwargs["align_lrc_words"] = False, True
|
| 406 |
|
| 407 |
file_writer(result=result, output_file_name=output_file_name, **kwargs)
|
|
|
|
| 14 |
|
| 15 |
def format_timestamp(
|
| 16 |
seconds: float, always_include_hours: bool = True, decimal_marker: str = ","
|
| 17 |
+
) -> str:
|
| 18 |
assert seconds >= 0, "non-negative timestamp expected"
|
| 19 |
milliseconds = round(seconds * 1000.0)
|
| 20 |
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
def time_str_to_seconds(time_str: str, decimal_marker: str = ",") -> float:
|
| 37 |
+
times = time_str.split(":")
|
| 38 |
+
|
| 39 |
+
if len(times) == 3:
|
| 40 |
+
hours, minutes, rest = times
|
| 41 |
+
hours = int(hours)
|
| 42 |
+
else:
|
| 43 |
+
hours = 0
|
| 44 |
+
minutes, rest = times
|
| 45 |
+
|
| 46 |
seconds, fractional = rest.split(decimal_marker)
|
| 47 |
|
|
|
|
| 48 |
minutes = int(minutes)
|
| 49 |
seconds = int(seconds)
|
| 50 |
fractional_seconds = float("0." + fractional)
|
|
|
|
| 408 |
file_path = os.path.join(output_dir, f"{output_file_name}.{output_format}")
|
| 409 |
file_writer = get_writer(output_format=output_format, output_dir=output_dir)
|
| 410 |
|
| 411 |
+
if isinstance(file_writer, WriteLRC) and kwargs.get("highlight_words", False):
|
| 412 |
kwargs["highlight_words"], kwargs["align_lrc_words"] = False, True
|
| 413 |
|
| 414 |
file_writer(result=result, output_file_name=output_file_name, **kwargs)
|