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

Adding setting for favorite languages #915

Merged
merged 1 commit into from
Sep 29, 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
23 changes: 20 additions & 3 deletions buzz/widgets/transcriber/languages_combo_box.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional
import os

from PyQt6.QtCore import pyqtSignal
from PyQt6.QtCore import pyqtSignal, Qt
from PyQt6.QtWidgets import QComboBox, QWidget
from PyQt6.QtGui import QStandardItem, QStandardItemModel

from buzz.locale import _
from buzz.transcriber.transcriber import LANGUAGES
Expand All @@ -18,13 +20,28 @@
) -> None:
super().__init__(parent)

favorite_languages = os.getenv("BUZZ_FAVORITE_LANGUAGES", '')
favorite_languages = favorite_languages.split(",")
favorite_languages = [(lang, LANGUAGES[lang].title()) for lang in favorite_languages
if lang in LANGUAGES]
if favorite_languages:
favorite_languages.insert(0, ("-------", "-------"))
favorite_languages.append(("-------", "-------"))

Check warning on line 29 in buzz/widgets/transcriber/languages_combo_box.py

View check run for this annotation

Codecov / codecov/patch

buzz/widgets/transcriber/languages_combo_box.py#L28-L29

Added lines #L28 - L29 were not covered by tests

whisper_languages = sorted(
[(lang, LANGUAGES[lang].title()) for lang in LANGUAGES],
key=lambda lang: lang[1],
)
self.languages = [("", _("Detect Language"))] + whisper_languages
self.languages = [("", _("Detect Language"))] + favorite_languages + whisper_languages

model = QStandardItemModel()
for lang in self.languages:
item = QStandardItem(lang[1])
if lang[0] == "-------":
item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsSelectable & ~Qt.ItemFlag.ItemIsEnabled)

Check warning on line 41 in buzz/widgets/transcriber/languages_combo_box.py

View check run for this annotation

Codecov / codecov/patch

buzz/widgets/transcriber/languages_combo_box.py#L41

Added line #L41 was not covered by tests
model.appendRow(item)

self.addItems([lang[1] for lang in self.languages])
self.setModel(model)
self.currentIndexChanged.connect(self.on_index_changed)

default_language_key = default_language if default_language != "" else None
Expand Down
11 changes: 7 additions & 4 deletions docs/docs/preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ set SOME_OTHER_VARIABLE=some_other_value

### Available variables

**BUZZ_WHISPERCPP_N_THREADS** - Number of threads to use for Whisper.cpp model. Default is `4`. Available from `v1.0.2`.
**BUZZ_WHISPERCPP_N_THREADS** - Number of threads to use for Whisper.cpp model. Default is `4`.

On a laptop with 16 threads setting `BUZZ_WHISPERCPP_N_THREADS=8` leads to some 15% speedup in transcription time.
Increasing number of threads even more will lead in slower transcription time as results from parallel threads has to be
combined to produce the final answer.

**BUZZ_TRANSLATION_API_BASE_URl** - Base URL of OpenAI compatible API to use for translation. Available from `v1.0.2`.
**BUZZ_TRANSLATION_API_BASE_URl** - Base URL of OpenAI compatible API to use for translation.

**BUZZ_TRANSLATION_API_KEY** - Api key of OpenAI compatible API to use for translation. Available from `v1.0.2`.
**BUZZ_TRANSLATION_API_KEY** - Api key of OpenAI compatible API to use for translation.

**BUZZ_MODEL_ROOT** - Root directory to store model files. Defaults to [user_cache_dir](https://pypi.org/project/platformdirs/). Available from `v1.0.2`.
**BUZZ_MODEL_ROOT** - Root directory to store model files.
Defaults to [user_cache_dir](https://pypi.org/project/platformdirs/).

**BUZZ_FAVORITE_LANGUAGES** - Coma separated list of supported language codes to show on top of language list.
Loading