-
Notifications
You must be signed in to change notification settings - Fork 172
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
Backend import for 'as-a-module' use #10
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to "submit review"
whisper_online.py
Outdated
self.commited_in_buffer = [] | ||
self.buffer = [] | ||
self.new = [] | ||
|
||
self.last_commited_time = 0 | ||
self.last_commited_word = None | ||
|
||
self.output = output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename self.output to self.logfile. Otherwise I agree, good idea.
Btw., logging module should be used, but I am too lazy for that. The Python code should stay simple.
whisper_online.py
Outdated
@@ -465,11 +476,11 @@ def split(self, text): | |||
#asr = WhisperASR(lan=language, modelsize=size) | |||
|
|||
if args.backend == "faster-whisper": | |||
from faster_whisper import WhisperModel | |||
#from faster_whisper import WhisperModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
whisper_online.py
Outdated
asr_cls = FasterWhisperASR | ||
else: | ||
import whisper | ||
import whisper_timestamped | ||
#import whisper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
whisper_online.py
Outdated
import whisper | ||
import whisper_timestamped | ||
#import whisper | ||
#import whisper_timestamped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
# join transcribe words with this character (" " for whisper_timestamped, "" for faster-whisper because it emits the spaces when neeeded) | ||
sep = " " | ||
sep = " " # join transcribe words with this character (" " for whisper_timestamped, | ||
# "" for faster-whisper because it emits the spaces when neeeded) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
whisper_online.py
Outdated
|
||
def __init__(self, lan, modelsize=None, cache_dir=None, model_dir=None): | ||
self.transcribe_kargs = {} | ||
self.original_language = lan | ||
|
||
self.import_backend() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too complicated code. Let's just do the imports in load_model in the childs that need it.
@Luca-Pozzi Great work! Do you plan on finishing this PR? I would really like to use whisper_online as a module, being unable to greatly limits composability into more end user facing apps. |
@lrq3000 It is really a minor contribution, but thank you! |
@Luca-Pozzi Awesome, thank you very much! Please let me know if I can help, I am experienced in Python coding but not in deep learning modules. |
@Gldkslfmsd I have edited the PR as per your suggestions! |
Thanks! No worries for late. |
Thank you both for your great work on this! :D |
How to use this to allow multiple clients to connect when you host a server or create an API for live transcription? |
I don't know, it's a topic that requires a separate issue. |
Thank you. Using one GPU for each client is a tall ask for me as there could be up to a dozen clients active at a particular time for my use case. I think there are a few backends which do support batched processing. e.g. https://github.com/Blair-Johnson/batch-whisper |
With reference to issue #9, the present PR implements a
import_backed
method inASRBase
. The method is then appropriately overridden both inWhisperTimestampedASR
andFasterWhisperASR
to import the required libraries.To make the use more flexible, I have also exposed the
output
arg inOnlineASRProcessor
. It receives a file-like object, so one could pass:sys.stderr
(as before) which in most cases will result into printing to terminalopen("/path/to/file.txt", "a")
) to log the output to a text fileopen(os.devnull, "w")
, to send the output to/dev/null
, i.e. to discard it