diff --git a/docs/IMPLEMENTATION.md b/docs/IMPLEMENTATION.md index c559057..55a482b 100644 --- a/docs/IMPLEMENTATION.md +++ b/docs/IMPLEMENTATION.md @@ -1023,3 +1023,8 @@ not provide a reliable insertion target. History refreshes retain the selected record/variant in their notice, including after insertion. Missing or malformed shortcuts direct the user to Settings. The shortcut is set through the existing HotkeyCaptureEdit. + +`keep_filler_words` defaults to false. When enabled, STT providers with vocabulary +prompting enabled receive hesitation examples within the shared 224-token estimate. +Clean and Polished request that the rewrite preserve fillers. Custom profiles retain +their authored instructions. Model compliance varies. diff --git a/src/config.py b/src/config.py index e8628ba..35cd680 100644 --- a/src/config.py +++ b/src/config.py @@ -733,6 +733,7 @@ class AppConfig: output_mode: str = "type" # see OUTPUT_MODES history_enabled: bool = False history_limit: int = 100 + keep_filler_words: bool = False sound_enabled: bool = True recovery_hotkey: str = "ctrl+alt+shift+key:0x56" vocabulary_entries: list[VocabularyTerm] = field(default_factory=list) diff --git a/src/main.py b/src/main.py index 151dd2b..ef2a1e1 100644 --- a/src/main.py +++ b/src/main.py @@ -493,6 +493,13 @@ def _apply_rewrite_profile(config: AppConfig, executable_path: str | None) -> st profile = resolve_rewrite_profile(config, executable_path) config.llm_enabled = profile.kind != "raw" config.llm_system_prompt = profile.prompt or "" + if config.keep_filler_words and profile.kind in {"clean", "polished"}: + config.llm_system_prompt = config.llm_system_prompt.replace( + "Remove filler words, stutters", "Remove stutters" + ) + config.llm_system_prompt += ( + "\nKeep filler words and hesitations (uh, um, ehm) exactly as spoken." + ) return profile.id def _start_recording(self) -> None: diff --git a/src/settings_dialog.py b/src/settings_dialog.py index 3dba9c8..6389c48 100644 --- a/src/settings_dialog.py +++ b/src/settings_dialog.py @@ -914,6 +914,10 @@ def _build_general_tab(self) -> None: "Insert last shortcut:", _button_row(self._recovery_hotkey_input, self._recovery_record_btn), ) + self._fillers = ToggleSwitch("Keep filler words (uh, um, ehm…)") + self._fillers.setToolTip("Asks the models to preserve hesitations. Results can vary.") + form.addRow(self._fillers) + self._fillers.toggled.connect(self._refresh_prompt_estimate) self._sound_check = ToggleSwitch("Play recording and error sounds") form.addRow(self._sound_check) @@ -1124,9 +1128,9 @@ def _refresh_prompt_estimate(self, *_args) -> None: terms = select_vocabulary(self._vocabulary_values(), language) except ValueError: terms = [] - prompt, omitted = build_whisper_prompt(terms) + prompt, omitted = build_whisper_prompt(terms, self._fillers.isChecked()) scope = language_label(language) if language else "all languages (Auto)" - if terms: + if terms or prompt: self._stt_prompt_estimate.setText( f"Prompt for {scope}: ~{estimate_prompt_tokens(prompt)} / " f"{WHISPER_PROMPT_TOKEN_BUDGET} tokens" @@ -1885,6 +1889,7 @@ def _populate(self, cfg: AppConfig) -> None: self._recovery_hotkey_input.show_hotkey(self._insert_hotkey) else: self._recovery_hotkey_input.clear() + self._fillers.setChecked(cfg.keep_filler_words) self._sound_check.setChecked(cfg.sound_enabled) self._history_check.setChecked(cfg.history_enabled) self._history_limit_spin.setValue(cfg.history_limit) @@ -1938,6 +1943,7 @@ def _collect(self) -> None: cfg.start_with_windows = self._startup_check.isChecked() cfg.output_mode = self._output_mode_combo.currentData() cfg.recovery_hotkey = self._insert_hotkey.to_canonical() if self._insert_hotkey else "" + cfg.keep_filler_words = self._fillers.isChecked() cfg.sound_enabled = self._sound_check.isChecked() cfg.history_enabled = self._history_check.isChecked() cfg.history_limit = self._history_limit_spin.value() diff --git a/src/stt.py b/src/stt.py index d1aeaa4..beb21d2 100644 --- a/src/stt.py +++ b/src/stt.py @@ -42,7 +42,9 @@ def _join_prompt(terms: list[str]) -> str: return ", ".join(terms) + "." if terms else "" -def build_whisper_prompt(terms: list[VocabularyTerm]) -> tuple[str, int]: +def build_whisper_prompt( + terms: list[VocabularyTerm], keep_filler_words: bool = False +) -> tuple[str, int]: """Render *terms* as a bare list of prior transcript text: ``PySide6, Qt, httpx.``. Returns ``(prompt, omitted)``. Terms are taken in order (``select_vocabulary`` puts @@ -50,7 +52,7 @@ def build_whisper_prompt(terms: list[VocabularyTerm]) -> tuple[str, int]: ``WHISPER_PROMPT_TOKEN_BUDGET``; the first term that does not fit stops the list, so the result never depends on the lengths of later terms. """ - kept: list[str] = [] + kept: list[str] = ["Umm, let me think, uh, ehm"] if keep_filler_words else [] for index, item in enumerate(terms): if estimate_prompt_tokens(_join_prompt([*kept, item.term])) > WHISPER_PROMPT_TOKEN_BUDGET: return _join_prompt(kept), len(terms) - index @@ -81,8 +83,8 @@ def transcribe(audio_wav: bytes, config: AppConfig) -> PipelineResult: vocabulary_prompt = "" if config.stt_prompt_primary_enabled or config.stt_prompt_fallback_enabled: terms = select_vocabulary(config.vocabulary_entries, config.stt_language) - if terms: - vocabulary_prompt, omitted = build_whisper_prompt(terms) + if terms or config.keep_filler_words: + vocabulary_prompt, omitted = build_whisper_prompt(terms, config.keep_filler_words) # Counts only: the terms themselves may be private. log.info( "STT prompt: %d terms sent, %d omitted (token budget)", diff --git a/tests/test_profiles.py b/tests/test_profiles.py index b0935cb..8db25d3 100644 --- a/tests/test_profiles.py +++ b/tests/test_profiles.py @@ -21,7 +21,7 @@ ) from src.settings_dialog import SettingsDialog from src.injector import InjectionReport, WindowIdentity -from src.main import _WorkerThread +from src.main import _TrayApp, _WorkerThread from src.utils import PipelineResult from tests.test_config import LEGACY_LLM_SYSTEM_PROMPT from tests.test_tray_menu import make_tray_app @@ -35,6 +35,17 @@ def setUp(self): self.enterContext(patch("src.config.APP_DIR", directory)) self.enterContext(patch("src.config._dpapi_available", return_value=False)) + def test_builtin_filler_instructions_are_opt_in(self): + for profile in ("clean", "polished"): + with self.subTest(profile=profile): + cfg = AppConfig(rewrite_manual_profile_id=profile) + _TrayApp._apply_rewrite_profile(cfg, None) + self.assertEqual(cfg.llm_system_prompt, resolve_rewrite_profile(cfg, None).prompt) + cfg.keep_filler_words = True + _TrayApp._apply_rewrite_profile(cfg, None) + self.assertIn("Keep filler words", cfg.llm_system_prompt) + self.assertNotIn("Remove filler words", cfg.llm_system_prompt) + def test_catalog_roundtrip_and_manual_automatic_precedence(self): custom = RewriteProfile("custom-1", "Coding", "custom", "Preserve identifiers.\r\n") catalog = encode_rewrite_catalog( @@ -66,6 +77,7 @@ def assert_disabled_legacy_prompt_migrates_once(self, prompt): settings.setValue("llm_enabled", False) settings.sync() cfg = load_config() + self.assertFalse(cfg.keep_filler_words) profiles, mappings = decode_rewrite_catalog(cfg.rewrite_catalog) self.assertEqual(len(profiles), 1) self.assertEqual(profiles[0].id, "legacy") diff --git a/tests/test_settings_dialog.py b/tests/test_settings_dialog.py index 9ea40c3..6a8390b 100644 --- a/tests/test_settings_dialog.py +++ b/tests/test_settings_dialog.py @@ -162,6 +162,14 @@ def setUp(self) -> None: self.dlg = SettingsDialog(self.cfg, devices=[]) self.addCleanup(self.dlg.deleteLater) + def test_fillers_persist_on_apply_and_cancel_discards_followup_edit(self): + self.assertFalse(self.dlg._fillers.isChecked()) + self.dlg._fillers.setChecked(True) + self.dlg._on_apply() + self.dlg._fillers.setChecked(False) + self.dlg.reject() + self.assertTrue(load_config().keep_filler_words) + def _saved_prompt(self) -> str: from src.config import resolve_rewrite_profile diff --git a/tests/test_whisper_prompt.py b/tests/test_whisper_prompt.py index b982cfb..f0c13e2 100644 --- a/tests/test_whisper_prompt.py +++ b/tests/test_whisper_prompt.py @@ -36,6 +36,12 @@ def test_bare_list_without_header_or_quotes(self): self.assertEqual(prompt, "PySide6, Qt, httpx.") self.assertEqual(omitted, 0) + def test_filler_examples_share_the_vocabulary_budget(self): + prompt, omitted = build_whisper_prompt(_long_entries(), True) + self.assertTrue(prompt.startswith("Umm, let me think")) + self.assertGreater(omitted, 0) + self.assertLessEqual(estimate_prompt_tokens(prompt), WHISPER_PROMPT_TOKEN_BUDGET) + def test_empty_selection_gives_no_prompt(self): self.assertEqual(build_whisper_prompt([]), ("", 0))