Skip to content
Snippets Groups Projects
Commit 4465d320 authored by Jan Hartig's avatar Jan Hartig
Browse files

Display processing time and progress indicator

parent 1c021a2e
No related branches found
No related tags found
No related merge requests found
from faster_whisper import WhisperModel from faster_whisper import WhisperModel
from datetime import timedelta from datetime import timedelta
from time import perf_counter
model_size = "large-v2" model_size = "large-v2"
tStart = perf_counter()
# Run on GPU with FP32 # Run on GPU with FP32
model = WhisperModel(model_size, device="cuda", compute_type="float32") model = WhisperModel(model_size, device="cuda", compute_type="float32")
print("Model initialized")
# Run on CPU # Run on CPU
# model = WhisperModel(model_size, device="cpu", compute_type="float32") # model = WhisperModel(model_size, device="cpu", compute_type="float32")
...@@ -14,6 +18,7 @@ segments, info = model.transcribe("/input/audiofile", language="de", beam_size=5 ...@@ -14,6 +18,7 @@ segments, info = model.transcribe("/input/audiofile", language="de", beam_size=5
with open("/output/transcript.vtt", "w", encoding="utf-8") as f: with open("/output/transcript.vtt", "w", encoding="utf-8") as f:
f.write("WEBVTT\n\nNOTE This transcript was automatically generated.") f.write("WEBVTT\n\nNOTE This transcript was automatically generated.")
print("Processing...", end="")
for segment in segments: for segment in segments:
start = timedelta(seconds=segment.start) start = timedelta(seconds=segment.start)
end = timedelta(seconds=segment.end) end = timedelta(seconds=segment.end)
...@@ -21,7 +26,15 @@ with open("/output/transcript.vtt", "w", encoding="utf-8") as f: ...@@ -21,7 +26,15 @@ with open("/output/transcript.vtt", "w", encoding="utf-8") as f:
entry = "{} --> {}\n{}".format(start, end, text) entry = "{} --> {}\n{}".format(start, end, text)
print(entry)
f.write("\n\n") f.write("\n\n")
f.write(entry) f.write(entry)
progress = segment.end / info.duration
print("{:2.0%}".format(progress if progress <= 1 else 1), end="...")
print("Done!")
tEnd = perf_counter()
tDelta = tEnd - tStart
print("Processing time: {}s".format(timedelta(seconds=tDelta)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment