Use comma as SRT separator (#280)

This commit is contained in:
Chidi Williams 2023-01-01 12:45:39 +00:00 committed by GitHub
parent f6ef2d5fe3
commit 5f9045c347
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View file

@ -7,4 +7,4 @@ omit =
directory = coverage/html directory = coverage/html
[report] [report]
fail_under = 74 fail_under = 73

View file

@ -474,7 +474,7 @@ def write_output(path: str, segments: List[Segment], should_open: bool, output_f
for (i, segment) in enumerate(segments): for (i, segment) in enumerate(segments):
file.write(f'{i + 1}\n') file.write(f'{i + 1}\n')
file.write( file.write(
f'{to_timestamp(segment.start)} --> {to_timestamp(segment.end)}\n') f'{to_timestamp(segment.start, ms_separator=",")} --> {to_timestamp(segment.end, ms_separator=",")}\n')
file.write(f'{segment.text}\n\n') file.write(f'{segment.text}\n\n')
if should_open: if should_open:
@ -495,14 +495,14 @@ def segments_to_text(segments: List[Segment]) -> str:
return result return result
def to_timestamp(ms: float) -> str: def to_timestamp(ms: float, ms_separator='.') -> str:
hr = int(ms / (1000 * 60 * 60)) hr = int(ms / (1000 * 60 * 60))
ms = ms - hr * (1000 * 60 * 60) ms = ms - hr * (1000 * 60 * 60)
min = int(ms / (1000 * 60)) min = int(ms / (1000 * 60))
ms = ms - min * (1000 * 60) ms = ms - min * (1000 * 60)
sec = int(ms / 1000) sec = int(ms / 1000)
ms = int(ms - sec * 1000) ms = int(ms - sec * 1000)
return f'{hr:02d}:{min:02d}:{sec:02d}.{ms:03d}' return f'{hr:02d}:{min:02d}:{sec:02d}{ms_separator}{ms:03d}'
SUPPORTED_OUTPUT_FORMATS = 'Audio files (*.mp3 *.wav *.m4a *.ogg);;\ SUPPORTED_OUTPUT_FORMATS = 'Audio files (*.mp3 *.wav *.m4a *.ogg);;\

View file

@ -205,7 +205,7 @@ class TestWhisperCpp:
(OutputFormat.TXT, 'Bien venue dans\n'), (OutputFormat.TXT, 'Bien venue dans\n'),
( (
OutputFormat.SRT, OutputFormat.SRT,
'1\n00:00:00.040 --> 00:00:00.299\nBien\n\n2\n00:00:00.299 --> 00:00:00.329\nvenue dans\n\n'), '1\n00:00:00,040 --> 00:00:00,299\nBien\n\n2\n00:00:00,299 --> 00:00:00,329\nvenue dans\n\n'),
(OutputFormat.VTT, (OutputFormat.VTT,
'WEBVTT\n\n00:00:00.040 --> 00:00:00.299\nBien\n\n00:00:00.299 --> 00:00:00.329\nvenue dans\n\n'), 'WEBVTT\n\n00:00:00.040 --> 00:00:00.299\nBien\n\n00:00:00.299 --> 00:00:00.329\nvenue dans\n\n'),
]) ])