Import error when using `whisper_online` as module
Luca-Pozzi opened this issue · comments
Hi!
First of all, thank you very much for this repo, impressive work!
Issue
As I am trying to use Whisper for ASR on a robot, I want to use whisper_online.py
as a module. In my main application, I tried to use
something like
import whisper
import whisper_timestamped
import whisper_streaming
...
sr = whisper_online.WhisperTimestampedASR(lan = kwargs.get('lan'),
modelsize = kwargs.get('model'),
cache_dir = kwargs.get('model_cache_dir'),
model_dir = kwargs.get('model_dir')
)
while True:
a = # receive new audio chunk (and e.g. wait for min_chunk_size seconds first, ...
online.insert_audio_chunk(a)
o = online.process_iter()
print(o) # do something with current partial output
but I get a ModuleNotFoundError: No module named 'whisper'
. I am sure that whisper
is installed as running whisper_online.py
as main works smoothly. Moreover, I have run import whisper
in a Python shell, and it throws no error.
Solution(s)
- placing the
import
statements at the top of thewhisper_online
script works, but indeed the possibility to import only the necessary backend is lost. - alternatively, I have tried to add an
import_backend
method inASRBase
, to import the required libraries. E.g. forWhisperTimestampedASR
it would be:
def import_backend(self):
global whisper, whisper_timestamped
import whisper
import whisper_timestamped
hi, thanks for feedback.
I primarily use faster-whisper backend, and I stopped testing debugging whisper
backend, so I think I missed this. I think that a similar approach to this could help:
whisper_streaming/whisper_online.py
Line 93 in d649c4b
In other words: Can you try adding `import whisper' into load_model of WhisperTimestampedASR? And then let's remove the comments "if used, requires import ..." It's wrong.
Thank you for the prompt answer!
whisper_streaming/whisper_online.py
Lines 49 to 65 in d649c4b
Indeed adding import whisper
in load_model
and import whisper_timestamped
in transcribe
works!
Though with a slightly different approach, I have proposed a solution with PR #10. If needed (and useful) I can modify it as you suggested.
Indeed adding import whisper in load_model
yes
and import whisper_timestamped in transcribe works!
Let's not import within transcribe
. This function is called many times, it would be ineffective. Rather in load_model
. It's fine because it's called only once per process, usually
and yes, I noticed your PR and gave feedback -- based on reading, not testing the code now. I'm busy
Let's not import within
transcribe
. This function is called many times, it would be ineffective. Rather inload_model
. It's fine because it's called only once per process, usually
Ok, thank you for the advice.
and yes, I noticed your PR and gave feedback -- based on reading, not testing the code now. I'm busy
Thank you very much for your time!