mirror of
https://github.com/openai/whisper.git
synced 2025-11-29 16:38:40 +00:00
Do not assert for a negative timestamp
This may be thrown when `verbose` is set to True and a very short audio is transcribed, resulting in a negative timestamp. Even though this is not a desired use case, it is preferable to keep going without raising an exception.
This commit is contained in:
parent
ba3f3cd54b
commit
17de1f20c0
@ -50,7 +50,9 @@ def compression_ratio(text) -> float:
|
||||
def format_timestamp(
|
||||
seconds: float, always_include_hours: bool = False, decimal_marker: str = "."
|
||||
):
|
||||
assert seconds >= 0, "non-negative timestamp expected"
|
||||
sign = "-" if seconds < 0 else ""
|
||||
seconds = abs(seconds)
|
||||
|
||||
milliseconds = round(seconds * 1000.0)
|
||||
|
||||
hours = milliseconds // 3_600_000
|
||||
@ -64,7 +66,7 @@ def format_timestamp(
|
||||
|
||||
hours_marker = f"{hours:02d}:" if always_include_hours or hours > 0 else ""
|
||||
return (
|
||||
f"{hours_marker}{minutes:02d}:{seconds:02d}{decimal_marker}{milliseconds:03d}"
|
||||
f"{sign}{hours_marker}{minutes:02d}:{seconds:02d}{decimal_marker}{milliseconds:03d}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user