Skip to content

Commit

Permalink
Adding setting for favorite languages (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
raivisdejus authored Sep 29, 2024
1 parent e63e644 commit 6f049e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
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 @@ def __init__(
) -> 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(("-------", "-------"))

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

0 comments on commit 6f049e6

Please sign in to comment.