From e9e6ae1f93a152718beffe63d1e263a38afafbab Mon Sep 17 00:00:00 2001 From: linozen Date: Mon, 13 Jan 2025 09:47:13 +0100 Subject: [PATCH] feat: add some error catching / ignoring needed as sometimes transcription errors out on `std::bad_cast` on Mac OS X with whisper-mlx. Does not seem to impact quality that much when these chunks are simply skipped. --- verbatim/verbatim.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/verbatim/verbatim.py b/verbatim/verbatim.py index 4eb694c..3cef775 100644 --- a/verbatim/verbatim.py +++ b/verbatim/verbatim.py @@ -352,18 +352,23 @@ def transcribe_window(self) -> Tuple[List[Word], List[Word]]: break prefix_text += word.word whisper_prompt = self.config.whisper_prompts[lang] if lang in self.config.whisper_prompts else self.config.whisper_prompts["en"] - transcript_words = self.models.transcriber.transcribe( - audio=self.state.rolling_window.array, - lang=lang, - prompt=whisper_prompt, - prefix=prefix_text, - window_ts=self.state.window_ts, - audio_ts=self.state.audio_ts, - whisper_beam_size=self.config.whisper_beam_size, - whisper_best_of=self.config.whisper_best_of, - whisper_patience=self.config.whisper_patience, - whisper_temperatures=self.config.whisper_temperatures, - ) + + try: + transcript_words = self.models.transcriber.transcribe( + audio=self.state.rolling_window.array, + lang=lang, + prompt=whisper_prompt, + prefix=prefix_text, + window_ts=self.state.window_ts, + audio_ts=self.state.audio_ts, + whisper_beam_size=self.config.whisper_beam_size, + whisper_best_of=self.config.whisper_best_of, + whisper_patience=self.config.whisper_patience, + whisper_temperatures=self.config.whisper_temperatures, + ) + except RuntimeError as e: + LOG.warning(f"Transcription failed with RuntimeError: {str(e)}. Skipping this chunk.") + return [], [] self.state.transcript_candidate_history.advance(self.state.window_ts) confirmed_words = self.state.transcript_candidate_history.confirm(