Skip to content
Open
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
5 changes: 5 additions & 0 deletions docs/IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions src/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 6 additions & 4 deletions src/stt.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ 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
the language's own terms first) and added whole while the estimate fits
``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
Expand Down Expand Up @@ -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)",
Expand Down
14 changes: 13 additions & 1 deletion tests/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions tests/test_settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions tests/test_whisper_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Loading