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

Fix for live transcription with Faster whisper #787

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 9 in buzz/buzz.py

View check run for this annotation

Codecov / codecov/patch

buzz/buzz.py#L9

Added line #L9 was not covered by tests

from buzz.assets import APP_BASE_DIR

Expand Down Expand Up @@ -59,6 +59,7 @@

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

Check warning on line 62 in buzz/buzz.py

View check run for this annotation

Codecov / codecov/patch

buzz/buzz.py#L62

Added line #L62 was not covered by tests

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 @@
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)

Check warning on line 58 in buzz/transcriber/recording_transcriber.py

View check run for this annotation

Codecov / codecov/patch

buzz/transcriber/recording_transcriber.py#L57-L58

Added lines #L57 - L58 were not covered by tests
else: # ModelType.HUGGING_FACE
model = transformers_whisper.load_model(model_path)

Expand Down Expand Up @@ -113,7 +116,24 @@
transcription_options=self.transcription_options
),
)
else:
elif (

Check warning on line 119 in buzz/transcriber/recording_transcriber.py

View check run for this annotation

Codecov / codecov/patch

buzz/transcriber/recording_transcriber.py#L119

Added line #L119 was not covered by tests
self.transcription_options.model.model_type
== ModelType.FASTER_WHISPER
):
assert isinstance(model, faster_whisper.WhisperModel)
whisper_segments, info = model.transcribe(

Check warning on line 124 in buzz/transcriber/recording_transcriber.py

View check run for this annotation

Codecov / codecov/patch

buzz/transcriber/recording_transcriber.py#L123-L124

Added lines #L123 - L124 were not covered by tests
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])}

Check warning on line 134 in buzz/transcriber/recording_transcriber.py

View check run for this annotation

Codecov / codecov/patch

buzz/transcriber/recording_transcriber.py#L134

Added line #L134 was not covered by tests

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