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

Add progress bar and report overall processing time.

parent 4465d320
No related branches found
No related tags found
No related merge requests found
FROM ghcr.io/opennmt/ctranslate2:latest-ubuntu20.04-cuda11.2
# install faster-whisper
RUN python3 -m pip --no-cache-dir install faster-whisper
RUN python3 -m pip --no-cache-dir install faster-whisper tqdm
# preload model
RUN python3 -c "import faster_whisper; faster_whisper.download_model('large-v2')"
......
from faster_whisper import WhisperModel
from datetime import timedelta
from time import perf_counter
from tqdm import tqdm
model_size = "large-v2"
......@@ -18,23 +18,30 @@ segments, info = model.transcribe("/input/audiofile", language="de", beam_size=5
with open("/output/transcript.vtt", "w", encoding="utf-8") as f:
f.write("WEBVTT\n\nNOTE This transcript was automatically generated.")
print("Processing...", end="")
for segment in segments:
start = timedelta(seconds=segment.start)
end = timedelta(seconds=segment.end)
text = segment.text[1:]
print("Start processing...")
with tqdm(total=info.duration, leave=False) as pbar:
previousEnd = 0
for segment in segments:
# calculate cue times
startM, startS = divmod(segment.start, 60)
startH, startM = divmod(startM, 60)
entry = "{} --> {}\n{}".format(start, end, text)
endM, endS = divmod(segment.end, 60)
endH, endM = divmod(endM, 60)
f.write("\n\n")
f.write(entry)
# write cue & text
f.write("\n\n{:02.0f}:{:02.0f}:{:06.3f} --> {:02.0f}:{:02.0f}:{:06.3f}\n".format(startH, startM, startS, endH, endM, endS))
f.write(segment.text[1:])
progress = segment.end / info.duration
print("{:2.0%}".format(progress if progress <= 1 else 1), end="...")
# update progressbar
pbar.update(segment.end - previousEnd)
previousEnd = segment.end
print("Done!")
tEnd = perf_counter()
tDelta = tEnd - tStart
tDelta = perf_counter() - tStart
tDeltaM, tDeltaS = divmod(tDelta, 60)
print("Processing time: {}s".format(timedelta(seconds=tDelta)))
durationM, durationS = divmod(info.duration, 60)
print("Processed {:02.0f}m {:02.0f}s audio in {:02.0f}m {:02.0f}s".format(durationM, durationS, tDeltaM, tDeltaS))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment