Skip to content

Commit

Permalink
Fix for live transcription with Faster whisper (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
raivisdejus authored Jun 8, 2024
1 parent d737b50 commit c19e7ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion buzz/buzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
from typing import TextIO

from platformdirs import user_log_dir
from platformdirs import user_log_dir, user_cache_dir

from buzz.assets import APP_BASE_DIR

Expand Down Expand Up @@ -59,6 +59,7 @@ def main():

logging.debug("app_dir: %s", APP_BASE_DIR)
logging.debug("log_dir: %s", log_dir)
logging.debug("cache_dir: %s", user_cache_dir("Buzz"))

app = Application(sys.argv)
parse_command_line(app)
Expand Down
22 changes: 21 additions & 1 deletion buzz/transcriber/recording_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from buzz.transformers_whisper import TransformersWhisper

import whisper
import faster_whisper


class RecordingTranscriber(QObject):
Expand Down Expand Up @@ -53,6 +54,8 @@ def start(self):
model = whisper.load_model(model_path)
elif self.transcription_options.model.model_type == ModelType.WHISPER_CPP:
model = WhisperCpp(model_path)
elif self.transcription_options.model.model_type == ModelType.FASTER_WHISPER:
model = faster_whisper.WhisperModel(model_path)
else: # ModelType.HUGGING_FACE
model = transformers_whisper.load_model(model_path)

Expand Down Expand Up @@ -113,7 +116,24 @@ def start(self):
transcription_options=self.transcription_options
),
)
else:
elif (
self.transcription_options.model.model_type
== ModelType.FASTER_WHISPER
):
assert isinstance(model, faster_whisper.WhisperModel)
whisper_segments, info = model.transcribe(
audio=samples,
language=self.transcription_options.language
if self.transcription_options.language is not ""
else None,
task=self.transcription_options.task.value,
temperature=self.transcription_options.temperature,
initial_prompt=self.transcription_options.initial_prompt,
word_timestamps=self.transcription_options.word_level_timings,
)
result = {"text": " ".join([segment.text for segment in whisper_segments])}

else: # ModelType.HUGGING_FACE
assert isinstance(model, TransformersWhisper)
result = model.transcribe(
audio=samples,
Expand Down

0 comments on commit c19e7ac

Please sign in to comment.