-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ProgressBar handler #80
Comments
Hello, The from tqdm import tqdm
from faster_whisper import WhisperModel
model = WhisperModel("tiny")
segments, info = model.transcribe("audio.mp3")
total_duration = round(info.duration, 2) # Same precision as the Whisper timestamps.
with tqdm(total=total_duration, unit=" seconds") as pbar:
for segment in segments:
segment_duration = segment.end - segment.start
pbar.update(segment_duration) |
Thanks |
just a minor enhancement, when using SileroVAD, not all segments are continuous of others from tqdm import tqdm
from faster_whisper import WhisperModel
model = WhisperModel("tiny")
segments, info = model.transcribe("audio.mp3", vad_filter=True)
total_duration = round(info.duration, 2) # Same precision as the Whisper timestamps.
timestamps = 0.0 # to get the current segments
with tqdm(total=total_duration, unit=" audio seconds") as pbar:
for segment in segments:
pbar.update(segment.end - timestamps)
timestamps = segment.end
if timestamps < info.duration: # silence at the end of the audio
pbar.update(info.duration - timestamps) |
How to redirect tqdm's output to |
what do you mean? you want to |
I want PS |
why ? |
@phineas-pta But it can't handle console's title bar, that's where I want to see progress bar. |
is there any library to do that ? |
You don't need lib for that. My problem was solved, but I saw various glitches from tqdm and I think the progress bar examples posted above doesn't work properly. |
Examples above are inaccurate because there tqdm process only a first segment from chunk and the rest are ignored. import time
import io
from threading import Thread
from time import sleep
from os import system
from tqdm import tqdm
from faster_whisper import WhisperModel
model = WhisperModel("tiny")
segments, info = model.transcribe("audio.mp3")
def pbar_delayed(): # to get last timestamp from chunk
global timestamp_prev
sleep(set_delay) # wait for whole chunk to be iterated
pbar.update(timestamp_last - timestamp_prev)
timestamp_prev = timestamp_last
system("title " + capture.getvalue().splitlines()[-1].replace("|","^|").replace("<","^<").replace("?","0"))
print(capture.getvalue().splitlines()[-1])
total_dur = round(info.duration)
td_len = str(len(str(total_dur))) # get length for n_fmt
global timestamp_prev, timestamp_last
timestamp_prev = 0 # last timestamp in previous chunk
timestamp_last = 0 # current timestamp
capture = io.StringIO() # capture progress bars from tqdm
last_burst = 0.0 # time of last iteration burst aka chunk
set_delay = 0.1 # max time it takes to iterate chunk & minimum time between chunks.
s_time = time.time()
print("")
bar_f = "{percentage:3.0f}% | {n_fmt:>"+td_len+"}/{total_fmt} | {elapsed}<<{remaining} | {rate_noinv_fmt}"
with tqdm(file=capture, total=total_dur, unit=" audio seconds", smoothing=0.00001, bar_format=bar_f) as pbar:
for segment in segments:
timestamp_last = round(segment.end)
time_now = time.time()
if time_now - last_burst > set_delay: # catch new chunk
last_burst = time_now
Thread(target=pbar_delayed, daemon=False).start()
sleep(set_delay + 0.3) # wait for the last pbar_delayed to finish
if timestamp_last < total_dur: # silence at the end of the audio
pbar.update(total_dur - timestamp_last)
system("title " + capture.getvalue().splitlines()[-1].replace("|","^|").replace("<","^<").replace("?","0"))
print(capture.getvalue().splitlines()[-1])
print("\n\nFinished! Speed: %s audio seconds/s" % round(info.duration / ((time.time() - s_time)), 2)) EDIT: To get progress in Linux terminal's title try to replace |
Hi,
I want to use your script with a progressbar but segments doesn't implement len. Is it possible to solve this ? Please
Bonjour d'Evreux (27)
Thanks
The text was updated successfully, but these errors were encountered: