Skip to content
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

Proccess hanging in infinite loop when input audio is not loud enough #67

Open
Pop-Vlad opened this issue Jan 27, 2024 · 1 comment
Open

Comments

@Pop-Vlad
Copy link

Running the followig code results in the process getting stuck when not speaking loud enough:

mic = WhisperMic()
result = mic.record(duration=2)
print(result)

The issue seems to come from the function __transcribe, where self.result_queue is filled only when is_audio_loud_enough is true:

    if is_audio_loud_enough:
        # faster_whisper returns an iterable object rather than a string
        if self.faster:
            segments, info = self.audio_model.transcribe(audio_data)
            predicted_text = ''
            for segment in segments:
                predicted_text += segment.text
        else:
            if self.english:
                result = self.audio_model.transcribe(audio_data,language='english',suppress_tokens="")
            else:
                result = self.audio_model.transcribe(audio_data,suppress_tokens="")
                predicted_text = result["text"]

        if not self.verbose:
            if predicted_text not in self.banned_results:
                self.result_queue.put_nowait(predicted_text)
        else:
            if predicted_text not in self.banned_results:
                self.result_queue.put_nowait(result)

As a result, the functions listen and record get stuck in the following loop, because self.result_queue is always empty:

    while True:
        if not self.result_queue.empty():
            return self.result_queue.get()
@FontaineRiant
Copy link

FontaineRiant commented Apr 17, 2024

Here's what you can do in the meantime:

from whisper_mic import WhisperMic, get_logger

class CustomMic(WhisperMic):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def listen(self, timeout=None, phrase_time_limit=None):
        self.logger.info("Listening...")
        while self.result_queue.empty():
            self._WhisperMic__listen_handler(timeout, phrase_time_limit)
        while True:
            if not self.result_queue.empty():
                return self.result_queue.get()

    def record(self, duration=None, offset=None):
        self.logger.info("Listening...")
        while self.result_queue.empty():
            self._WhisperMic__record_handler(duration, offset)
        while True:
            if not self.result_queue.empty():
                return self.result_queue.get()

And use that custom class instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants