From 733d7dddeae40798bb7ae536d6760a01f83dca85 Mon Sep 17 00:00:00 2001 From: Chidi Williams Date: Mon, 10 Apr 2023 21:50:55 +0100 Subject: [PATCH 1/7] Save settings --- buzz/constants.py | 1 + buzz/gui.py | 49 +++++++++++++++++++++++++++++++++++------------ buzz/settings.py | 29 ++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 buzz/constants.py create mode 100644 buzz/settings.py diff --git a/buzz/constants.py b/buzz/constants.py new file mode 100644 index 000000000..c4151e220 --- /dev/null +++ b/buzz/constants.py @@ -0,0 +1 @@ +APP_NAME = 'Buzz' diff --git a/buzz/gui.py b/buzz/gui.py index 8e3b51f0e..84b8b0e15 100644 --- a/buzz/gui.py +++ b/buzz/gui.py @@ -28,15 +28,15 @@ from buzz.cache import TasksCache from .__version__ import VERSION +from .constants import APP_NAME from .model_loader import ModelLoader, WhisperModelSize, ModelType, TranscriptionModel from .recording import RecordingAmplitudeListener +from .settings import Settings from .transcriber import (SUPPORTED_OUTPUT_FORMATS, FileTranscriptionOptions, OutputFormat, Task, get_default_output_file_path, segments_to_text, write_output, TranscriptionOptions, FileTranscriberQueueWorker, FileTranscriptionTask, RecordingTranscriber, LOADED_WHISPER_DLL) -APP_NAME = 'Buzz' - def get_asset_path(path: str): if getattr(sys, 'frozen', False): @@ -228,6 +228,7 @@ class FileTranscriberWidget(QWidget): # (TranscriptionOptions, FileTranscriptionOptions, str) triggered = pyqtSignal(tuple) openai_access_token_changed = pyqtSignal(str) + settings = Settings() def __init__(self, file_paths: List[str], openai_access_token: Optional[str] = None, parent: Optional[QWidget] = None, flags: Qt.WindowType = Qt.WindowType.Widget) -> None: @@ -236,18 +237,23 @@ def __init__(self, file_paths: List[str], openai_access_token: Optional[str] = N self.setWindowTitle(file_paths_as_title(file_paths)) self.file_paths = file_paths - self.transcription_options = TranscriptionOptions(openai_access_token=openai_access_token) + self.transcription_options = TranscriptionOptions(openai_access_token=openai_access_token, + task=self.settings.value( + key=Settings.Key.FILE_TRANSCRIBER_TASK, + default_value=Task.TRANSCRIBE)) self.file_transcription_options = FileTranscriptionOptions( file_paths=self.file_paths) layout = QVBoxLayout(self) transcription_options_group_box = TranscriptionOptionsGroupBox( - default_transcription_options=self.transcription_options, parent=self) + default_transcription_options=self.transcription_options, settings=self.settings, parent=self) transcription_options_group_box.transcription_options_changed.connect( self.on_transcription_options_changed) self.word_level_timings_checkbox = QCheckBox(_('Word-level timings')) + self.word_level_timings_checkbox.setChecked( + self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_WORD_LEVEL_TIMINGS, default_value=False)) self.word_level_timings_checkbox.stateChanged.connect( self.on_word_level_timings_changed) @@ -255,8 +261,11 @@ def __init__(self, file_paths: List[str], openai_access_token: Optional[str] = N file_transcription_layout.addRow('', self.word_level_timings_checkbox) export_format_layout = QHBoxLayout() + export_format_states: List[str] = self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_EXPORT_FORMATS, + default_value=[]) for output_format in OutputFormat: export_format_checkbox = QCheckBox(f'{output_format.value.upper()}', parent=self) + export_format_checkbox.setChecked(output_format.value in export_format_states) export_format_checkbox.stateChanged.connect(self.get_on_checkbox_state_changed_callback(output_format)) export_format_layout.addWidget(export_format_checkbox) @@ -279,6 +288,9 @@ def on_checkbox_state_changed(state: int): self.file_transcription_options.output_formats.add(output_format) elif state == Qt.CheckState.Unchecked.value: self.file_transcription_options.output_formats.remove(output_format) + self.settings.set_value(key=Settings.Key.FILE_TRANSCRIBER_EXPORT_FORMATS, + value=[export_format.value for export_format in + self.file_transcription_options.output_formats]) return on_checkbox_state_changed @@ -348,6 +360,8 @@ def reset_model_download(self): def on_word_level_timings_changed(self, value: int): self.transcription_options.word_level_timings = value == Qt.CheckState.Checked.value + self.settings.set_value(key=Settings.Key.FILE_TRANSCRIBER_WORD_LEVEL_TIMINGS, + value=self.transcription_options.word_level_timings) def closeEvent(self, event: QtGui.QCloseEvent) -> None: if self.transcriber_thread is not None: @@ -501,6 +515,7 @@ def __init__(self, parent: Optional[QWidget] = None, flags: Optional[Qt.WindowTy self.setWindowFlags(flags) layout = QVBoxLayout(self) + settings = Settings() self.current_status = self.RecordingStatus.STOPPED self.setWindowTitle(_('Live Recording')) @@ -524,6 +539,7 @@ def __init__(self, parent: Optional[QWidget] = None, flags: Optional[Qt.WindowTy default_transcription_options=self.transcription_options, # Live transcription with OpenAI Whisper API not implemented model_types=[model_type for model_type in ModelType if model_type is not ModelType.OPEN_AI_WHISPER_API], + settings=settings, parent=self) transcription_options_group_box.transcription_options_changed.connect( self.on_transcription_options_changed) @@ -1280,11 +1296,12 @@ class TranscriptionOptionsGroupBox(QGroupBox): transcription_options: TranscriptionOptions transcription_options_changed = pyqtSignal(TranscriptionOptions) - def __init__(self, default_transcription_options: TranscriptionOptions = TranscriptionOptions(), + def __init__(self, settings: Settings, default_transcription_options: TranscriptionOptions = TranscriptionOptions(), model_types: Optional[List[ModelType]] = None, parent: Optional[QWidget] = None): super().__init__(title='', parent=parent) self.transcription_options = default_transcription_options + self.settings = settings self.form_layout = QFormLayout(self) @@ -1294,7 +1311,8 @@ def __init__(self, default_transcription_options: TranscriptionOptions = Transcr self.tasks_combo_box.taskChanged.connect(self.on_task_changed) self.languages_combo_box = LanguagesComboBox( - default_language=self.transcription_options.language, + default_language=settings.value(key=Settings.Key.FILE_TRANSCRIBER_LANGUAGE, + default_value=self.transcription_options.language, value_type=str), parent=self) self.languages_combo_box.languageChanged.connect( self.on_language_changed) @@ -1315,14 +1333,17 @@ def __init__(self, default_transcription_options: TranscriptionOptions = Transcr if model_type == ModelType.WHISPER_CPP and LOADED_WHISPER_DLL is False: continue self.model_type_combo_box.addItem(model_type.value) - self.model_type_combo_box.setCurrentText(default_transcription_options.model.model_type.value) + self.model_type_combo_box.setCurrentText(settings.value(key=Settings.Key.FILE_TRANSCRIBER_MODEL_TYPE, + default_value=default_transcription_options.model.model_type.value)) self.model_type_combo_box.currentTextChanged.connect(self.on_model_type_changed) self.whisper_model_size_combo_box = QComboBox(self) self.whisper_model_size_combo_box.addItems([size.value.title() for size in WhisperModelSize]) - if default_transcription_options.model.whisper_model_size is not None: - self.whisper_model_size_combo_box.setCurrentText( - default_transcription_options.model.whisper_model_size.value.title()) + self.whisper_model_size_combo_box.setCurrentText(settings.value( + key=Settings.Key.FILE_TRANSCRIBER_WHISPER_MODEL_SIZE, + default_value=default_transcription_options.model.whisper_model_size.value.title() + if default_transcription_options.model.whisper_model_size is not None + else '')) self.whisper_model_size_combo_box.currentTextChanged.connect(self.on_whisper_model_size_changed) self.openai_access_token_edit = QLineEdit(self) @@ -1350,22 +1371,26 @@ def on_openai_access_token_edit_changed(self, access_token: str): def on_language_changed(self, language: str): self.transcription_options.language = language self.transcription_options_changed.emit(self.transcription_options) + self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_LANGUAGE, self.transcription_options.language) def on_task_changed(self, task: Task): self.transcription_options.task = task self.transcription_options_changed.emit(self.transcription_options) + self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_TASK, self.transcription_options.task) def on_temperature_changed(self, temperature: Tuple[float, ...]): self.transcription_options.temperature = temperature self.transcription_options_changed.emit(self.transcription_options) + self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_TEMPERATURE, self.transcription_options.temperature) def on_initial_prompt_changed(self, initial_prompt: str): self.transcription_options.initial_prompt = initial_prompt self.transcription_options_changed.emit(self.transcription_options) + self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_INITIAL_PROMPT, self.transcription_options.initial_prompt) def open_advanced_settings(self): dialog = AdvancedSettingsDialog( - transcription_options=self.transcription_options, parent=self) + transcription_options=self.transcription_options, settings=settings, parent=self) dialog.transcription_options_changed.connect( self.on_transcription_options_changed) dialog.exec() @@ -1440,7 +1465,7 @@ class AdvancedSettingsDialog(QDialog): transcription_options: TranscriptionOptions transcription_options_changed = pyqtSignal(TranscriptionOptions) - def __init__(self, transcription_options: TranscriptionOptions, parent: QWidget | None = None): + def __init__(self, transcription_options: TranscriptionOptions, settings: Settings, parent: QWidget | None = None): super().__init__(parent) self.transcription_options = transcription_options diff --git a/buzz/settings.py b/buzz/settings.py new file mode 100644 index 000000000..f43c7edc4 --- /dev/null +++ b/buzz/settings.py @@ -0,0 +1,29 @@ +import enum +import typing + +from PyQt6.QtCore import QSettings + +from buzz.constants import APP_NAME + + +class Settings: + settings = QSettings(APP_NAME) + + class Key(enum.Enum): + RECORDING_TRANSCRIBER_TASK = 'recording-transcriber/task' + RECORDING_TRANSCRIBER_LANGUAGE = 'recording-transcriber/language' + FILE_TRANSCRIBER_TASK = 'file-transcriber/task' + FILE_TRANSCRIBER_LANGUAGE = 'file-transcriber/language' + FILE_TRANSCRIBER_WORD_LEVEL_TIMINGS = 'file-transcriber/word-level-timings' + FILE_TRANSCRIBER_EXPORT_FORMATS = 'file-transcriber/export-formats' + FILE_TRANSCRIBER_MODEL_TYPE = 'file-transcriber/model-type' + FILE_TRANSCRIBER_WHISPER_MODEL_SIZE = 'file-transcriber/whisper-model-size' + FILE_TRANSCRIBER_TEMPERATURE = 'file-transcriber/temperature' + FILE_TRANSCRIBER_INITIAL_PROMPT = 'file-transcriber/initial-prompt' + + def set_value(self, key: Key, value: typing.Any) -> None: + self.settings.setValue(key.value, value) + + def value(self, key: Key, default_value: typing.Any, value_type: typing.Optional[type] = None) -> typing.Any: + return self.settings.value(key.value, default_value, + value_type if value_type is not None else type(default_value)) From 83bdbc692c8037af6f25656d885b0051f9989464 Mon Sep 17 00:00:00 2001 From: Chidi Williams Date: Mon, 10 Apr 2023 22:06:03 +0100 Subject: [PATCH 2/7] Updates --- buzz/gui.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/buzz/gui.py b/buzz/gui.py index 84b8b0e15..7faa28635 100644 --- a/buzz/gui.py +++ b/buzz/gui.py @@ -35,7 +35,8 @@ from .transcriber import (SUPPORTED_OUTPUT_FORMATS, FileTranscriptionOptions, OutputFormat, Task, get_default_output_file_path, segments_to_text, write_output, TranscriptionOptions, - FileTranscriberQueueWorker, FileTranscriptionTask, RecordingTranscriber, LOADED_WHISPER_DLL) + FileTranscriberQueueWorker, FileTranscriptionTask, RecordingTranscriber, LOADED_WHISPER_DLL, + DEFAULT_WHISPER_TEMPERATURE) def get_asset_path(path: str): @@ -237,10 +238,15 @@ def __init__(self, file_paths: List[str], openai_access_token: Optional[str] = N self.setWindowTitle(file_paths_as_title(file_paths)) self.file_paths = file_paths - self.transcription_options = TranscriptionOptions(openai_access_token=openai_access_token, - task=self.settings.value( - key=Settings.Key.FILE_TRANSCRIBER_TASK, - default_value=Task.TRANSCRIBE)) + self.transcription_options = TranscriptionOptions( + openai_access_token=openai_access_token, + task=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_TASK, default_value=Task.TRANSCRIBE), + language=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_LANGUAGE, default_value=None), + initial_prompt=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_INITIAL_PROMPT, default_value=''), + temperature=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_TEMPERATURE, + default_value=DEFAULT_WHISPER_TEMPERATURE), + word_level_timings=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_WORD_LEVEL_TIMINGS, + default_value=False)) self.file_transcription_options = FileTranscriptionOptions( file_paths=self.file_paths) @@ -1296,12 +1302,11 @@ class TranscriptionOptionsGroupBox(QGroupBox): transcription_options: TranscriptionOptions transcription_options_changed = pyqtSignal(TranscriptionOptions) - def __init__(self, settings: Settings, default_transcription_options: TranscriptionOptions = TranscriptionOptions(), + def __init__(self, default_transcription_options: TranscriptionOptions = TranscriptionOptions(), model_types: Optional[List[ModelType]] = None, parent: Optional[QWidget] = None): super().__init__(title='', parent=parent) self.transcription_options = default_transcription_options - self.settings = settings self.form_layout = QFormLayout(self) @@ -1311,8 +1316,7 @@ def __init__(self, settings: Settings, default_transcription_options: Transcript self.tasks_combo_box.taskChanged.connect(self.on_task_changed) self.languages_combo_box = LanguagesComboBox( - default_language=settings.value(key=Settings.Key.FILE_TRANSCRIBER_LANGUAGE, - default_value=self.transcription_options.language, value_type=str), + default_language=self.transcription_options.language, parent=self) self.languages_combo_box.languageChanged.connect( self.on_language_changed) @@ -1333,17 +1337,14 @@ def __init__(self, settings: Settings, default_transcription_options: Transcript if model_type == ModelType.WHISPER_CPP and LOADED_WHISPER_DLL is False: continue self.model_type_combo_box.addItem(model_type.value) - self.model_type_combo_box.setCurrentText(settings.value(key=Settings.Key.FILE_TRANSCRIBER_MODEL_TYPE, - default_value=default_transcription_options.model.model_type.value)) + self.model_type_combo_box.setCurrentText(default_transcription_options.model.model_type.value) self.model_type_combo_box.currentTextChanged.connect(self.on_model_type_changed) self.whisper_model_size_combo_box = QComboBox(self) self.whisper_model_size_combo_box.addItems([size.value.title() for size in WhisperModelSize]) - self.whisper_model_size_combo_box.setCurrentText(settings.value( - key=Settings.Key.FILE_TRANSCRIBER_WHISPER_MODEL_SIZE, - default_value=default_transcription_options.model.whisper_model_size.value.title() - if default_transcription_options.model.whisper_model_size is not None - else '')) + if default_transcription_options.model.whisper_model_size is not None: + self.whisper_model_size_combo_box.setCurrentText( + default_transcription_options.model.whisper_model_size.value.title()) self.whisper_model_size_combo_box.currentTextChanged.connect(self.on_whisper_model_size_changed) self.openai_access_token_edit = QLineEdit(self) From 538eca10ebb9801ed553020649d98b89d9aeda20 Mon Sep 17 00:00:00 2001 From: Chidi Williams Date: Mon, 10 Apr 2023 22:11:41 +0100 Subject: [PATCH 3/7] Updates --- buzz/gui.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/buzz/gui.py b/buzz/gui.py index 7faa28635..7c5af5309 100644 --- a/buzz/gui.py +++ b/buzz/gui.py @@ -253,7 +253,7 @@ def __init__(self, file_paths: List[str], openai_access_token: Optional[str] = N layout = QVBoxLayout(self) transcription_options_group_box = TranscriptionOptionsGroupBox( - default_transcription_options=self.transcription_options, settings=self.settings, parent=self) + default_transcription_options=self.transcription_options, parent=self) transcription_options_group_box.transcription_options_changed.connect( self.on_transcription_options_changed) @@ -267,11 +267,11 @@ def __init__(self, file_paths: List[str], openai_access_token: Optional[str] = N file_transcription_layout.addRow('', self.word_level_timings_checkbox) export_format_layout = QHBoxLayout() - export_format_states: List[str] = self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_EXPORT_FORMATS, - default_value=[]) + default_export_format_states: List[str] = self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_EXPORT_FORMATS, + default_value=[]) for output_format in OutputFormat: export_format_checkbox = QCheckBox(f'{output_format.value.upper()}', parent=self) - export_format_checkbox.setChecked(output_format.value in export_format_states) + export_format_checkbox.setChecked(output_format.value in default_export_format_states) export_format_checkbox.stateChanged.connect(self.get_on_checkbox_state_changed_callback(output_format)) export_format_layout.addWidget(export_format_checkbox) @@ -294,9 +294,6 @@ def on_checkbox_state_changed(state: int): self.file_transcription_options.output_formats.add(output_format) elif state == Qt.CheckState.Unchecked.value: self.file_transcription_options.output_formats.remove(output_format) - self.settings.set_value(key=Settings.Key.FILE_TRANSCRIBER_EXPORT_FORMATS, - value=[export_format.value for export_format in - self.file_transcription_options.output_formats]) return on_checkbox_state_changed @@ -366,12 +363,21 @@ def reset_model_download(self): def on_word_level_timings_changed(self, value: int): self.transcription_options.word_level_timings = value == Qt.CheckState.Checked.value - self.settings.set_value(key=Settings.Key.FILE_TRANSCRIBER_WORD_LEVEL_TIMINGS, - value=self.transcription_options.word_level_timings) def closeEvent(self, event: QtGui.QCloseEvent) -> None: if self.transcriber_thread is not None: self.transcriber_thread.wait() + + self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_LANGUAGE, self.transcription_options.language) + self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_TASK, self.transcription_options.task) + self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_TEMPERATURE, self.transcription_options.temperature) + self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_INITIAL_PROMPT, self.transcription_options.initial_prompt) + self.settings.set_value(key=Settings.Key.FILE_TRANSCRIBER_WORD_LEVEL_TIMINGS, + value=self.transcription_options.word_level_timings) + self.settings.set_value(key=Settings.Key.FILE_TRANSCRIBER_EXPORT_FORMATS, + value=[export_format.value for export_format in + self.file_transcription_options.output_formats]) + super().closeEvent(event) @@ -1372,22 +1378,18 @@ def on_openai_access_token_edit_changed(self, access_token: str): def on_language_changed(self, language: str): self.transcription_options.language = language self.transcription_options_changed.emit(self.transcription_options) - self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_LANGUAGE, self.transcription_options.language) def on_task_changed(self, task: Task): self.transcription_options.task = task self.transcription_options_changed.emit(self.transcription_options) - self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_TASK, self.transcription_options.task) def on_temperature_changed(self, temperature: Tuple[float, ...]): self.transcription_options.temperature = temperature self.transcription_options_changed.emit(self.transcription_options) - self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_TEMPERATURE, self.transcription_options.temperature) def on_initial_prompt_changed(self, initial_prompt: str): self.transcription_options.initial_prompt = initial_prompt self.transcription_options_changed.emit(self.transcription_options) - self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_INITIAL_PROMPT, self.transcription_options.initial_prompt) def open_advanced_settings(self): dialog = AdvancedSettingsDialog( From 61fb6d233c6fd7993c683501836a42a110c3f185 Mon Sep 17 00:00:00 2001 From: Chidi Williams Date: Mon, 10 Apr 2023 22:21:34 +0100 Subject: [PATCH 4/7] Updates --- buzz/constants.py | 1 - buzz/gui.py | 21 +++++++++++++-------- buzz/settings.py | 13 ++++++++----- 3 files changed, 21 insertions(+), 14 deletions(-) delete mode 100644 buzz/constants.py diff --git a/buzz/constants.py b/buzz/constants.py deleted file mode 100644 index c4151e220..000000000 --- a/buzz/constants.py +++ /dev/null @@ -1 +0,0 @@ -APP_NAME = 'Buzz' diff --git a/buzz/gui.py b/buzz/gui.py index 7c5af5309..210c17a7b 100644 --- a/buzz/gui.py +++ b/buzz/gui.py @@ -28,10 +28,9 @@ from buzz.cache import TasksCache from .__version__ import VERSION -from .constants import APP_NAME from .model_loader import ModelLoader, WhisperModelSize, ModelType, TranscriptionModel from .recording import RecordingAmplitudeListener -from .settings import Settings +from .settings import Settings, APP_NAME from .transcriber import (SUPPORTED_OUTPUT_FORMATS, FileTranscriptionOptions, OutputFormat, Task, get_default_output_file_path, segments_to_text, write_output, TranscriptionOptions, @@ -240,6 +239,7 @@ def __init__(self, file_paths: List[str], openai_access_token: Optional[str] = N self.file_paths = file_paths self.transcription_options = TranscriptionOptions( openai_access_token=openai_access_token, + model=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_MODEL, default_value=TranscriptionModel()), task=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_TASK, default_value=Task.TRANSCRIBE), language=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_LANGUAGE, default_value=None), initial_prompt=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_INITIAL_PROMPT, default_value=''), @@ -527,14 +527,20 @@ def __init__(self, parent: Optional[QWidget] = None, flags: Optional[Qt.WindowTy self.setWindowFlags(flags) layout = QVBoxLayout(self) - settings = Settings() self.current_status = self.RecordingStatus.STOPPED self.setWindowTitle(_('Live Recording')) + self.settings = Settings() self.transcription_options = TranscriptionOptions( - model=TranscriptionModel(model_type=ModelType.WHISPER_CPP if LOADED_WHISPER_DLL else ModelType.WHISPER, - whisper_model_size=WhisperModelSize.TINY)) + model=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_MODEL, default_value=TranscriptionModel( + model_type=ModelType.WHISPER_CPP if LOADED_WHISPER_DLL else ModelType.WHISPER, + whisper_model_size=WhisperModelSize.TINY)), + task=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_TASK, default_value=Task.TRANSCRIBE), + language=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_LANGUAGE, default_value=None), + initial_prompt=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_INITIAL_PROMPT, default_value=''), + temperature=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_TEMPERATURE, + default_value=DEFAULT_WHISPER_TEMPERATURE), word_level_timings=False) self.audio_devices_combo_box = AudioDevicesComboBox(self) self.audio_devices_combo_box.device_changed.connect( @@ -551,7 +557,6 @@ def __init__(self, parent: Optional[QWidget] = None, flags: Optional[Qt.WindowTy default_transcription_options=self.transcription_options, # Live transcription with OpenAI Whisper API not implemented model_types=[model_type for model_type in ModelType if model_type is not ModelType.OPEN_AI_WHISPER_API], - settings=settings, parent=self) transcription_options_group_box.transcription_options_changed.connect( self.on_transcription_options_changed) @@ -1393,7 +1398,7 @@ def on_initial_prompt_changed(self, initial_prompt: str): def open_advanced_settings(self): dialog = AdvancedSettingsDialog( - transcription_options=self.transcription_options, settings=settings, parent=self) + transcription_options=self.transcription_options, parent=self) dialog.transcription_options_changed.connect( self.on_transcription_options_changed) dialog.exec() @@ -1468,7 +1473,7 @@ class AdvancedSettingsDialog(QDialog): transcription_options: TranscriptionOptions transcription_options_changed = pyqtSignal(TranscriptionOptions) - def __init__(self, transcription_options: TranscriptionOptions, settings: Settings, parent: QWidget | None = None): + def __init__(self, transcription_options: TranscriptionOptions, parent: QWidget | None = None): super().__init__(parent) self.transcription_options = transcription_options diff --git a/buzz/settings.py b/buzz/settings.py index f43c7edc4..dca525bd2 100644 --- a/buzz/settings.py +++ b/buzz/settings.py @@ -3,7 +3,7 @@ from PyQt6.QtCore import QSettings -from buzz.constants import APP_NAME +APP_NAME = 'Buzz' class Settings: @@ -11,15 +11,18 @@ class Settings: class Key(enum.Enum): RECORDING_TRANSCRIBER_TASK = 'recording-transcriber/task' + RECORDING_TRANSCRIBER_MODEL = 'recording-transcriber/model' RECORDING_TRANSCRIBER_LANGUAGE = 'recording-transcriber/language' + RECORDING_TRANSCRIBER_TEMPERATURE = 'recording-transcriber/temperature' + RECORDING_TRANSCRIBER_INITIAL_PROMPT = 'recording-transcriber/initial-prompt' + FILE_TRANSCRIBER_TASK = 'file-transcriber/task' + FILE_TRANSCRIBER_MODEL = 'file-transcriber/model' FILE_TRANSCRIBER_LANGUAGE = 'file-transcriber/language' - FILE_TRANSCRIBER_WORD_LEVEL_TIMINGS = 'file-transcriber/word-level-timings' - FILE_TRANSCRIBER_EXPORT_FORMATS = 'file-transcriber/export-formats' - FILE_TRANSCRIBER_MODEL_TYPE = 'file-transcriber/model-type' - FILE_TRANSCRIBER_WHISPER_MODEL_SIZE = 'file-transcriber/whisper-model-size' FILE_TRANSCRIBER_TEMPERATURE = 'file-transcriber/temperature' FILE_TRANSCRIBER_INITIAL_PROMPT = 'file-transcriber/initial-prompt' + FILE_TRANSCRIBER_WORD_LEVEL_TIMINGS = 'file-transcriber/word-level-timings' + FILE_TRANSCRIBER_EXPORT_FORMATS = 'file-transcriber/export-formats' def set_value(self, key: Key, value: typing.Any) -> None: self.settings.setValue(key.value, value) From 53809a94a928b888b8c053a07f93ece696e24fbe Mon Sep 17 00:00:00 2001 From: Chidi Williams Date: Mon, 10 Apr 2023 22:23:53 +0100 Subject: [PATCH 5/7] Updates --- buzz/gui.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/buzz/gui.py b/buzz/gui.py index 210c17a7b..e19662263 100644 --- a/buzz/gui.py +++ b/buzz/gui.py @@ -372,6 +372,7 @@ def closeEvent(self, event: QtGui.QCloseEvent) -> None: self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_TASK, self.transcription_options.task) self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_TEMPERATURE, self.transcription_options.temperature) self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_INITIAL_PROMPT, self.transcription_options.initial_prompt) + self.settings.set_value(Settings.Key.FILE_TRANSCRIBER_MODEL, self.transcription_options.model) self.settings.set_value(key=Settings.Key.FILE_TRANSCRIBER_WORD_LEVEL_TIMINGS, value=self.transcription_options.word_level_timings) self.settings.set_value(key=Settings.Key.FILE_TRANSCRIBER_EXPORT_FORMATS, @@ -731,6 +732,14 @@ def closeEvent(self, event: QCloseEvent) -> None: if self.recording_amplitude_listener is not None: self.recording_amplitude_listener.stop_recording() self.recording_amplitude_listener.deleteLater() + + self.settings.set_value(Settings.Key.RECORDING_TRANSCRIBER_LANGUAGE, self.transcription_options.language) + self.settings.set_value(Settings.Key.RECORDING_TRANSCRIBER_TASK, self.transcription_options.task) + self.settings.set_value(Settings.Key.RECORDING_TRANSCRIBER_TEMPERATURE, self.transcription_options.temperature) + self.settings.set_value(Settings.Key.RECORDING_TRANSCRIBER_INITIAL_PROMPT, + self.transcription_options.initial_prompt) + self.settings.set_value(Settings.Key.RECORDING_TRANSCRIBER_MODEL, self.transcription_options.model) + return super().closeEvent(event) From 5234670b38a209db7bb072483fbeb219e007281b Mon Sep 17 00:00:00 2001 From: Chidi Williams Date: Mon, 10 Apr 2023 22:31:23 +0100 Subject: [PATCH 6/7] Updates --- buzz/gui.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/buzz/gui.py b/buzz/gui.py index e19662263..d6f24b889 100644 --- a/buzz/gui.py +++ b/buzz/gui.py @@ -241,7 +241,8 @@ def __init__(self, file_paths: List[str], openai_access_token: Optional[str] = N openai_access_token=openai_access_token, model=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_MODEL, default_value=TranscriptionModel()), task=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_TASK, default_value=Task.TRANSCRIBE), - language=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_LANGUAGE, default_value=None), + language=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_LANGUAGE, default_value=None, + value_type=str), initial_prompt=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_INITIAL_PROMPT, default_value=''), temperature=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_TEMPERATURE, default_value=DEFAULT_WHISPER_TEMPERATURE), @@ -538,7 +539,8 @@ def __init__(self, parent: Optional[QWidget] = None, flags: Optional[Qt.WindowTy model_type=ModelType.WHISPER_CPP if LOADED_WHISPER_DLL else ModelType.WHISPER, whisper_model_size=WhisperModelSize.TINY)), task=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_TASK, default_value=Task.TRANSCRIBE), - language=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_LANGUAGE, default_value=None), + language=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_LANGUAGE, default_value=None, + value_type=str), initial_prompt=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_INITIAL_PROMPT, default_value=''), temperature=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_TEMPERATURE, default_value=DEFAULT_WHISPER_TEMPERATURE), word_level_timings=False) From de129f536e5f83bc71c085fd7bfc16b4470601cf Mon Sep 17 00:00:00 2001 From: Chidi Williams Date: Mon, 10 Apr 2023 22:47:07 +0100 Subject: [PATCH 7/7] Updates --- buzz/gui.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/buzz/gui.py b/buzz/gui.py index d6f24b889..1795e4ace 100644 --- a/buzz/gui.py +++ b/buzz/gui.py @@ -237,12 +237,12 @@ def __init__(self, file_paths: List[str], openai_access_token: Optional[str] = N self.setWindowTitle(file_paths_as_title(file_paths)) self.file_paths = file_paths + default_language = self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_LANGUAGE, default_value='') self.transcription_options = TranscriptionOptions( openai_access_token=openai_access_token, model=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_MODEL, default_value=TranscriptionModel()), task=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_TASK, default_value=Task.TRANSCRIBE), - language=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_LANGUAGE, default_value=None, - value_type=str), + language=default_language if default_language != '' else None, initial_prompt=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_INITIAL_PROMPT, default_value=''), temperature=self.settings.value(key=Settings.Key.FILE_TRANSCRIBER_TEMPERATURE, default_value=DEFAULT_WHISPER_TEMPERATURE), @@ -534,13 +534,13 @@ def __init__(self, parent: Optional[QWidget] = None, flags: Optional[Qt.WindowTy self.setWindowTitle(_('Live Recording')) self.settings = Settings() + default_language = self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_LANGUAGE, default_value='') self.transcription_options = TranscriptionOptions( model=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_MODEL, default_value=TranscriptionModel( model_type=ModelType.WHISPER_CPP if LOADED_WHISPER_DLL else ModelType.WHISPER, whisper_model_size=WhisperModelSize.TINY)), task=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_TASK, default_value=Task.TRANSCRIBE), - language=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_LANGUAGE, default_value=None, - value_type=str), + language=default_language if default_language != '' else None, initial_prompt=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_INITIAL_PROMPT, default_value=''), temperature=self.settings.value(key=Settings.Key.RECORDING_TRANSCRIBER_TEMPERATURE, default_value=DEFAULT_WHISPER_TEMPERATURE), word_level_timings=False)