From 6f049e6d096b28186cccdc3472e706b19226ca03 Mon Sep 17 00:00:00 2001 From: Raivis Dejus Date: Sun, 29 Sep 2024 09:16:21 +0300 Subject: [PATCH] Adding setting for favorite languages (#915) --- .../transcriber/languages_combo_box.py | 23 ++++++++++++++++--- docs/docs/preferences.md | 11 +++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/buzz/widgets/transcriber/languages_combo_box.py b/buzz/widgets/transcriber/languages_combo_box.py index c775c6a32..7ab6c5b0d 100644 --- a/buzz/widgets/transcriber/languages_combo_box.py +++ b/buzz/widgets/transcriber/languages_combo_box.py @@ -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 @@ -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 diff --git a/docs/docs/preferences.md b/docs/docs/preferences.md index 86e098754..055bbb49b 100644 --- a/docs/docs/preferences.md +++ b/docs/docs/preferences.md @@ -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.