mirror of
https://github.com/shirayu/whispering.git
synced 2024-09-20 18:40:12 +00:00
40 lines
1,002 B
Python
40 lines
1,002 B
Python
#!/usr/bin/env python3
|
|
import threading
|
|
import time
|
|
|
|
from tqdm import tqdm
|
|
from whisper.audio import CHUNK_LENGTH, HOP_LENGTH
|
|
|
|
|
|
class ProgressBar(threading.Thread):
|
|
def __init__(self, *, num_block: int):
|
|
super().__init__()
|
|
self.started = threading.Event()
|
|
self.alive = True
|
|
self.start()
|
|
self.started.set() # start
|
|
self.num_block = num_block
|
|
|
|
def __del__(self):
|
|
self.kill()
|
|
|
|
def kill(self):
|
|
self.started.set()
|
|
self.alive = False
|
|
self.join()
|
|
|
|
def end(self):
|
|
self.started.clear()
|
|
|
|
def run(self):
|
|
self.started.wait()
|
|
with tqdm(
|
|
total=self.num_block,
|
|
leave=False,
|
|
bar_format="Listening (Elapsed: {elapsed}, Estimated remaining: {remaining})",
|
|
) as t:
|
|
for _ in range(self.num_block):
|
|
time.sleep(CHUNK_LENGTH / HOP_LENGTH)
|
|
t.update(1)
|
|
if not self.alive:
|
|
break
|