c461cf51478b5bdebe6ee86a1f95d505aa8f3daa
23
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
e66bd218d9 |
fix(audio): prevent dictation hangs on stalled microphones (#974)
* fix(audio): bound capture reads and support cancellation * fix(recognition): bound and serialize capture shutdown * fix(recognition): cancel retries and report stalled microphones * fix(audio): prefer pulse when the ALSA default is unavailable * fix(recognition): guard late callbacks and finalize capture tests * docs(audio): explain input selection and stall recovery * fix(speech): enforce auto-pause across buffered reload timeouts * fix(speech): recover auto-resume after reload timeout * test(speech): fix auto-pause follow-up test regressions * fix(speech): retain auto-resume after reconfigure timeout * fix(tray): preserve auto-pause recovery across suspend * test(capture-shutdown): give the bare tray the suspend path's shortcut managers _on_system_suspend now releases the main and per-language hotkey listeners before sleep (#1025); the fixture builds TrayIndicator without __init__, so it needs the two attributes present. * fix(tray): release hotkey listeners on suspend even while auto-paused Merging #1025's suspend cleanup with this branch's auto-pause handoff left an early return that skipped shortcut_manager.stop() whenever a configured game was active, keeping EVIOCGRABs held through sleep. The paused branch now only owns the model-lifecycle work; listener release and stopping active recognition run for every suspend. * fix(tray): hold the apply lock only around the download's verify and save Wrapping the whole recommended-model download in _apply_settings_lock blocked every GTK-thread settings apply (e.g. Test Dictation) for the length of the transfer. The engine already serializes reconfigures, so the lock only needs to cover verifying the download still owns the receipt and saving it; an apply that lands mid-download now proceeds instead of freezing the app. --------- Co-authored-by: Jatin K Malik <jatinkrmalik@gmail.com> |
||
|
|
3e4230ffc2 |
fix(settings): make model downloads explicit and cancel the whole intent (#1006)
* fix(settings): make model downloads explicit and cancel the whole intent "Use it" on the recommendation card applied a different model than the one shown, a cancelled or failed apply left the staged model behind so the next Test Dictation downloaded it, and cancelling a download tore down and then reloaded the previous model while the dialog waited. - Recommendation is now passive text, compared by size tier, with a link to docs/MODEL_SELECTION.md. The "Use it" button is gone. - Every Settings download asks first and shows size and source host. Declining, cancelling or failing drops the staged model spec and puts the pickers back on the saved config. - Test Dictation refuses a model that is not on disk instead of applying it. - reconfigure() fetches a missing model before releasing the loaded one, so a cancel restores state without reloading or rehashing the old model. Cancellation state is reset only when a download claim is taken or ended. - Follow-layout mode shows the resolved language in the simple Main language control, read-only, and simple edits keep the "layout" setting. Fixes #979 Fixes #980 Fixes #981 Fixes #982 Fixes #985 Fixes #988 * fix(settings): restore follow-layout mode when a model change is declined * fix(settings): keep follow-layout and dictation consistent during model changes * style(tests): format follow-layout regression tests * fix(recognition): skip resume reinit while a model download is running * fix(recognition): keep a lazy reload pending when resume is skipped during a download --------- Co-authored-by: Jatin K Malik <jatinkrmalik@gmail.com> |
||
|
|
1c299d2dc7 |
fix(whispercpp): map GPU picker to ggml devices and size threads by effective backend (#1001)
* fix(whispercpp): map GPU picker to ggml devices and size threads by effective backend The GPU picker and auto selection used vulkaninfo indices, but whisper.cpp's gpu_device is an ordinal over the GPU/IGPU devices ggml registered. ggml skips Vulkan devices it cannot use (for example a Haswell iGPU), so the indices shift and a selected NVIDIA card could fall back to CPU while logs claimed Vulkan. Read ggml's device registry through the loaded pywhispercpp extension, select and label devices by that ordinal, run on CPU explicitly when ggml has no GPU, log the effective backend after load, and pick n_threads from the effective backend instead of the presence of GPU libraries. Fixes #987 Fixes #990 * test(whispercpp): move new ggml probe tests into their test class |
||
|
|
65de3427fb |
perf: faster Settings, typing and dictation; mypy in CI, engine interface, architecture docs (#968)
* fix(perf): reduce startup and inference overhead * fix(perf): report effective whisper.cpp fallback settings * fix(injection): add opt-in X11 paste for long dictations * perf(vad): lower default silence timeout to 1.2s * fix(types): resolve mypy errors across application source * ci: run mypy in the lint job * ci: include mypy in lint dependency group * fix(types): narrow evdev timestamp comparison * refactor(recognition): add SpeechEngine protocol and engine dispatch table * refactor(settings): move About section and engine tables out of settings_dialog * docs: add ARCHITECTURE.md and refresh docs index and AGENTS layout * fix(settings): preserve GTK dialog compatibility after extraction * style: format touched Python modules * fix(types): keep local typecheck from syncing dependencies * test(vad): align main startup expectation with new default * style: sort engine registry and protocol test imports * test(settings): follow extracted About builder attribute alias * test(settings): isolate GTK dialog base in About test * test(settings): isolate About color scheme build test * test(settings): restore GTK base after About scheme test * test(settings): isolate About scheme check from GTK mocks * test(settings): support extracted dialog mixin methods * docs: add before/after performance benchmark charts * fix(injection): type instead of pasting when the clipboard holds non-text data |
||
|
|
dbe0215aad |
feat(shortcuts): add language switching shortcuts, fix PTT races, and add dictation history (#880)
* feat(shortcuts): per-language dictation shortcuts (#805) Bind extra keys that start dictation in a specific catalog language for one utterance, then restore the configured language. Bindings live in shortcuts.language_shortcuts as [{shortcut, language}], normalized against the language catalog and the backend's shortcut parser. The tray spawns one KeyboardShortcutManager per binding in the active mode; toggle presses route through start_recognition_with_language, and push-to-talk arms press/release the same way. The manager keeps the override one-shot: it applies before the utterance starts (outranking follow-keyboard-layout) and unwinds on the next IDLE/ERROR transition or when a mid-dictation reconfigure picks a new language. Engines that cannot re-language without a reload (VOSK, Parakeet, English-only whisper.cpp) refuse with the error cue and a notification instead of dictating in the wrong language. Settings gains a Language Shortcuts group under Shortcuts: each row is a language picker, an editable key entry, a Record button that retargets the shared key-capture, and a remove button; edits persist immediately and rebuild the live listeners. A non-dict shortcuts section now rebuilds instead of crashing config load. * fix(shortcuts): class-level default for language shortcut listeners TrayIndicator stubs built with __new__ (e.g. test_suspend_handler) skip __init__ but still run _quit(); give _language_shortcut_managers a class-level default so teardown iterates an empty list. * Fix Greptile review findings on per-language shortcuts (#805) - Bind each dictation session's language for transcription workers so the one-shot restore cannot rewrite a queued segment's language - Judge a shortcut's capability against the model the layout refresh will serve (whisper.cpp sibling swap) and refuse requests the engine drops - Add _oneshot_language_restore to the reconfigure snapshot and settle a revived pending restore on failure - Dedupe language bindings by gesture (modifier reordering, enter/return alias, pure-modifier side sets) instead of by string - Stop per-language listeners under external activation and never re-arm - Gate push-to-talk release on the binding that started the session, and stop a held hold before rebuilding listeners - Keep a row's last valid binding during partial edits, report rejected duplicates, cancel a capture aimed at a removed row, disarm the previous Record target, persist a recorded key once, and add the missing type hints * fix(shortcuts): resolve remaining Greptile race findings on PR #880 - Stamp each queued audio segment with the session language it was recorded under, so a worker that outlives stop_recognition's joins transcribes each utterance in its own language rather than whatever a newer session stored in _session_language. - Serialize push-to-talk press/release behind _ptt_lock: a release landing while start_recognition runs now waits for the owner claim instead of being dropped, so a quick key tap cannot leave the microphone running. - Add the missing return type hint on _stop_language_shortcut_managers. * test(shortcuts): stub _segment_started_at on bare manager stubs * fix(shortcuts): carry segment language as attribute, default language on bare managers * fix(shortcuts): keep (segment, language) queue tuples, stamp segment.language too * fix(settings): apply history toggle and limit to the live store --------- Co-authored-by: Jatin K Malik <jatinkrmalik@gmail.com> |
||
|
|
5e531cbac0 |
refactor(audio): extract capture source from recognition manager (#883)
* refactor(audio): extract capture source from recognition manager Move audio capture out of the silence-segmented dictation loop into vocalinux.audio.capture: a reusable PortAudioCaptureSource that owns device resolution, format negotiation, downmixing, resampling, and stream lifecycle (open/read/reopen/close). The dictation loop now consumes 16 kHz mono chunks and keeps only segmentation policy (VAD, silence counters, buffer limits, reconnection backoff). This unblocks alternate capture sources (PipeWire system-audio capture for #751, tdrz long-form output for #756) which need the same capture mechanics without dictation's silence segmentation. Behavior is identical: the same helpers run in the same order, moved verbatim. They are re-exported from recognition_manager for existing imports, and a CaptureSource protocol is declared in common_types.py. Tests repoint their patches of the moved helpers to the new module. Closes #760 * fix(audio): annotate capture API and keep a superseded session's source * fix(audio): reset retry counters when a new capture session starts * fix(audio): keep last-error timestamp across capture sessions The new-session reset wiped _last_audio_error_time, so an error within five seconds of the previous session's error always took the reconnect path instead of failing fast. Only the attempt count is per-session; the timestamp is also the rapid-failure throttle. --------- Co-authored-by: Jatin K Malik <jatinkrmalik@gmail.com> |
||
|
|
092dde105e |
fix(audio): open 3-8ch HDA mics at native layout (#813) (#829)
* fix(audio): open 3-8ch HDA mics at native layout (#813) HDA analog capture often reports 4 channels. Opening below that native count can abort PortAudio after read with free(): corrupted unsorted chunks (same class of bug as #666/#673). Try the reported channel count first when it is between 3 and 8, then 2ch and 1ch. Pulse devices that advertise 32/128 channels still open stereo-first. Downmix N channels to mono so engines keep seeing 1ch. Virtual-device filtering for pipewire/default (#629) is unchanged. * fix(audio): downmix HDA capture from first channel pair Averaging all N HDA channels halves speech when only the front pair is live. Keep stereo mean-of-both, and for 3+ channels average channels 0 and 1. * fix(audio): pick loudest channel for N-ch downmix First-pair-only downmix silenced mics on ch2+. For 3+ channels, select the loudest channel by per-buffer mean-square so speech stays at full level whether it lands on the front or rear pair. Stereo still averages both channels. * fix(audio): sticky N-ch downmix channel for open stream Pin the loudest-channel pick for the life of a capture stream so a noise burst on another input cannot switch the mic mid-utterance. * fix(audio): gate sticky downmix lock on speech energy Don't pin the N-ch sticky channel from a silent/ambient first buffer; only lock once the loudest channel clears a documented mean-square floor. * style: isort sticky-lock import in device config tests |
||
|
|
21b8ee8d05 |
fix(aur): build on Arch setuptools 84 and skip 1.4 context_params (#757)
AUR --no-isolation uses extra python-setuptools 84, so the <82 cap blocked the 0.16.0 rebuild. AUR pywhispercpp backends are still 1.4 and crash if we pass context_params; skip that argument below 1.5. |
||
|
|
9c3ed49317 |
fix(tray): stay idle after leftover transcription on toggle stop (#741)
* fix(tray): stay idle after leftover transcription on toggle stop Toggle stop can time out while leftover audio is still transcribing. The recognition thread then painted PROCESSING and never went idle, so the tray stayed red until another Alt+F12. Skip PROCESSING and LISTENING updates once recording has stopped, always set IDLE when that thread exits, and paint the engine's current state in the tray instead of a stale GLib.idle_add argument. * fix(tray): leftover drain must not idle a new dictation session stop_recognition already marks IDLE. Forcing IDLE when the leftover worker exits can clobber a new LISTENING start during leftover drain. |
||
|
|
582d494633 |
chore(build): uv tooling, a Python 3.11 floor, and verified model downloads (epic #701, phases 2.5 & 5) (#713)
* chore(build): migrate justfile tooling to uv All recipes now run through 'uv run' against .venv, with a shared DEV_EXTRAS variable (dev + vad) because uv syncs the environment exactly and would otherwise uninstall the dev tools between recipes. 'deps' installs dev+vad; new 'deps-all' covers every extra. 'build' switches to 'uv build'; 'version' uses --no-sync. Bump [tool.uv] required-version to >=0.12,<0.13 for uv 0.12.x, and raise the mypy python_version target to 3.12: mypy 1.19 in the lock cannot target 3.9 and numpy 2.x stubs need a 3.12 target to parse (mypy is not run in CI or pre-commit; this only affects 'just typecheck'). * fix(tests): isolate test runs from real XDG state; fix Arch model-path crash Local test runs failed en masse (185 failures) while CI stayed green: tests picked up the developer's real ~/.local/share/vocalinux models via the default XDG paths and switched IBus/keyboard code paths through the desktop session env (XDG_CURRENT_DESKTOP/ XDG_SESSION_TYPE on GNOME/Wayland, issue #478 branches). conftest now points XDG base dirs at a throwaway session-wide directory and clears session variables at import time, mirroring a fresh CI runner (paths like MODELS_DIR freeze at first import during collection, so fixture-time isolation is too late). Also guard the Arch branch of _get_system_model_paths(): it removed /usr/local/share/vocalinux/models unconditionally and crashed with ValueError on Arch hosts when a custom XDG_DATA_DIRS never added that path. Add regression tests, and make the lock-file test assert the actual $XDG_DATA_HOME/vocalinux contract instead of the hardcoded ~/.local/share default. * fix(tests): keep the IBus engine double a plain class Python 3.14's unittest.mock re-instantiates a user subclass when it builds child mocks (klass(name=...)). VocalinuxEngine inherits from whatever IBus.Engine resolves to, and the test module bound that to the MagicMock class itself, so every engine instantiation raised TypeError: VocalinuxEngine.__init__() got an unexpected keyword argument 'name' on 3.14 while passing on 3.13. Replace it with a plain stand-in class that still hands out per-instance MagicMocks for the IBus API surface the engine touches. The same pattern remains in test_ibus_engine.py, test_ibus_engine_utils.py, test_ibus_active_engine_guard.py and test_ibus_xkb_wayland.py; those never instantiate the engine, so they are unaffected for now. * fix(install): build the venv from the system Python install.sh looked up a bare `python3` from PATH. Started from an activated virtualenv — a shell left in uv's .venv after `just deps` — it built venv/ from that interpreter, where distro PyGObject is invisible even with --system-site-packages, and the run aborted with Distro PyGObject (python3-gi / python3-gobject) is not importable in the venv. A mismatched venv/ then survived every retry, because the installer reuses whatever venv it finds. - drop an inherited VIRTUAL_ENV (and its bin from PATH) before any interpreter lookup - select the interpreter explicitly: $SYSTEM_PYTHON (default /usr/bin/python3) or PATH python3, preferring one that can import gi, and create the venv with it instead of `python3` - recreate venv/ when it was built by a different interpreter - name the interpreter in the PyGObject guard's error Documents the two environments (uv's .venv for tooling, venv/ for the installed app) in CONTRIBUTING, the justfile header and AGENTS.md, and adds the mismatch symptom to the INSTALL troubleshooting section. * chore(python): raise the supported floor to 3.11 requires-python promised 3.9 while the CI matrix ran 3.9/3.10/3.11/3.13, the classifiers advertised up to 3.14, mypy targeted 3.12 and install.sh enforced 3.9 — five different answers to "which Python does this support". Settle on 3.11 everywhere: pyproject (requires-python, classifiers, black targets), install.sh's MIN_VERSION, check-system-deps.sh, the distro package map, the CI matrix (now 3.11-3.14, matching the classifiers), the release and nightly workflows, and the docs. mypy now targets the floor instead of 3.12, so type checking covers what we promise; numpy 2.x ships stubs in 3.12 syntax that a 3.11 target cannot parse, so its imports are skipped. (mypy has 71 pre-existing errors either way; no CI job gates on it.) uv.lock and the requirements/* exports are regenerated — dropping 3.9/3.10 removes most of the version-conditional resolution branches. tests/test_python_version_policy.py pins the invariant: install.sh's floor, requires-python, the classifiers and the CI matrix must agree. * ci: run lint and tests from uv.lock The lock file and the hash-pinned exports were not enforced anywhere: CI still built a venv by hand and installed unpinned `PyGObject` plus `-e ".[dev,vad]"`, so the tool versions it checked against had nothing to do with the ones `just lint` uses locally. Both Python jobs now use astral-sh/setup-uv and run through `uv sync --locked` / `uv run --locked`, which also fails the build when uv.lock drifts from pyproject.toml. Partially covers phase 5 of #701 (tests install from the lock, lock freshness gate); trusted publishing, artifact checksums and action SHA pinning are still open there. * ci: lint from a dedicated dependency group The lint job failed on this branch: `uv run --extra dev` syncs the whole project, so it tried to build pyaudio from source on a runner that installs no system dependencies. src/pyaudio/device_api.c:9:10: fatal error: portaudio.h: No such file or directory Move black/isort/flake8 out of the `dev` extra into a `lint` dependency group. CI runs `uv run --locked --only-group lint`, which installs the three pure-Python tools and skips the project entirely — no portaudio or girepository headers needed. `just deps` and DEV_EXTRAS request the group alongside the dev extras, so the local environment still carries test and lint tooling at once and `just lint` matches CI version for version. pre-commit is unaffected: its hooks pin their own tool versions upstream. * fix(install): never configure an engine the venv cannot import vosk became an optional extra in #705, but the installer still writes `"engine": "vosk"` into config.json on the whisper.cpp fallback path even when installing the extra only produced a warning. config.json also survives reinstalls — every writer guards on "file does not exist" — so an engine picked by an earlier attempt outlives the venv that supported it. Either way Vocalinux dies at startup: ModuleNotFoundError: No module named 'vosk' - the fallback now writes the vosk config only when `import vosk` actually succeeds, and otherwise leaves the engine configuration alone - a new verify_configured_engine() runs near the end of the install: if config.json selects vosk and the venv cannot import it, it says so and prints both fixes instead of leaving a broken install behind * feat(models): verify every model download against a pinned digest Pins a sha256/md5 per downloadable speech model in src/vocalinux/utils/model_checksums.txt and verifies against it in both install.sh and the runtime downloaders, before the file is moved into place. Verification fails closed. Covers phase 2.5 of #701; see the PR for details. * docs(agents): rebase AGENTS.md onto the #727 rewrite * fix(install): hash models that are already on disk instead of trusting them * refactor(models): one download path per engine, and fix Whisper's * docs(install): drop distros that cannot meet the 3.11 floor * docs: retire the distros and Python versions the 3.11 floor rules out * fix(install): abort instead of warning when Python is below the floor * fix(install): fall back to the system Python, not the one on PATH * fix(install): match an existing venv by installation, not by X.Y * fix(install): repair a config naming an engine the venv cannot import * fix(models): pin VOSK by the sha256 of bytes we fetched, not upstream's md5 * fix(justfile): request the dev set in every recipe that syncs * test(version): scan the docs and website trees for a stale Python floor * docs: correct the stale model-checksum and distro claims * fix(models): stamp the VOSK tree the app extracts, as the installer does * fix(install): replace an unverified VOSK model only once its successor is ready * docs(install): align the Fedora floor with the rest of the tree * test(install): drop an f-string with no placeholders * test(models): stub the downloader probe the VOSK installer test relies on * docs: drop the long dashes from two model-checksum comments * fix(install): gate on the interpreter, not on the distro release label * fix(justfile): export the lint group into requirements/dev.txt * fix(models): unpack the VOSK tree into staging and stamp it before the swap * fix(whisper): adopt a checkpoint an earlier release stored under the catalog name * docs(settings): state what a stray Whisper copy really means for deletion * fix(models): hash a whisper.cpp model found on disk before it reaches ctypes * docs(contributing): stop telling readers to uninstall their linters * fix(install): stop warning off distros the project documents as supported * docs(distros): file the supported derivatives under supported |
||
|
|
d8ff7052cd |
fix(settings): stop Test Dictation calling a missing model "no speech" (#702)
* fix(settings): stop Test Dictation calling a missing model "no speech" start_recognition now returns whether listening actually began. Test Dictation checks that before starting its timer, so a missing or auto-paused model gets a real error instead of "No speech detected". * fix(settings): reconfigure Test Dictation against the live engine UI matching config.json is not enough when speech_engine is still on another engine or model size. Compare those too before the listen timer. * fix(tests): keep settings_dialog lookups on one module _load_settings_dialog() restored sys.modules but left vocalinux.ui.settings_dialog pointing at the private reload. Python 3.9/3.10 mock follows that attribute, so test_whisper_list_and_delete patched a different copy than it imported and the expanduser stub hid the real cache. Point the package attribute back at the restored module, and patch the imported module object in the deletion test. |
||
|
|
279d99fea0 |
fix(whisper): honor bundled GPU libs and skip software Vulkan devices (#674)
* fix(whisper): use bundled GPU libs and skip software Vulkan devices AppImage 0.15.0 shipped a CPU-only pywhispercpp wheel, so the Settings GPU picker and host vulkaninfo never moved inference off the CPU. Rebuild pywhispercpp with Vulkan in the AppImage, log the libraries that actually load, skip llvmpipe in auto-select, and document how to verify. Fixes #604 * fix(appimage): pin gcc/g++ for Vulkan pywhispercpp rebuild Hosts that default cc/c++ to clang fail CMAKE's C++ test because clang does not search gcc's libstdc++ path. Default the rebuild to gcc/g++. |
||
|
|
c3a9695a5b |
fix(audio): open stereo mics at native channel count (#673)
Prefer 2ch before 1ch when PortAudio reports two or more input channels. Intel SOF digital mics (the Raptor Lake device in #666) often only support stereo at the PCM; opening them as converted mono can abort with heap corruption right after capture starts. Mono-only devices are still never probed with 2 channels (#567). |
||
|
|
5d06d21838 |
fix(whisper): use CUDA device 0 when pywhispercpp is CUDA-backed (#636)
* fix(whisper): use CUDA device 0 when pywhispercpp is CUDA-backed Vulkan GPU enumeration on hybrid laptops lists the iGPU as GPU0 and the dGPU as GPU1, but CUDA ordinals always place the first NVIDIA GPU at 0. Auto mode and the settings UI were passing Vulkan indices into CUDA pywhispercpp, which silently fell back to CPU inference. Detect the actual pywhispercpp backend before selecting gpu_device and map CUDA installs to device 0. Vulkan-backed installs keep Vulkan indices. * test(whisper): cover CUDA gpu_device selection branches for codecov --------- Co-authored-by: Jatin K Malik <jatinkrmalik@gmail.com> |
||
|
|
20375f8657 |
fix(audio): filter unsafe virtual devices that crash capture (#629)
* fix(audio): filter unsafe virtual devices that crash capture This is a defensive fix for #624 heap corruption seen when PortAudio opens PipeWire pseudo-devices such as DeepFilterNet, default, pipewire, paplay, monitor, null, dummy, or filter-chain sources. The root cause is not fully proven, but avoiding explicit capture from these unsafe virtual rows should keep dictation on real microphones while still allowing System Default through device_index=None. If this still crashes with a physical microphone selected, please confirm with the exact physical device name and audio stack details so the capture path can be narrowed further. Fixes #624 * fix(settings): sync audio device fallback with raw name restore Address Bugbot review on #629: match legacy "(default)" saved names and clear stale config/engine state when a filtered device falls back to System Default. * fix(audio): keep system default capture off pseudo device indices Stop converting System Default to an explicit PortAudio index in the mic test, and fall back to host default capture when every enumerated input is filtered as unsafe. * test(audio): expect system-default fallback on reconnect * test(audio): cover system-default fallback paths for capture |
||
|
|
2152dbb90d |
fix(whispercpp): skip unsupported context_params on pywhispercpp 1.4 (#626)
* fix(whispercpp): skip unsupported context_params on pywhispercpp 1.4 Fixes #625 * test(whispercpp): cover context_params signature inspection failure |
||
|
|
ca24264c85 |
fix(audio): stop Bluetooth mic probing from corrupting the heap (#599)
* fix(audio): prevent Bluetooth mic probe heap corruption Open PortAudio streams only once when negotiating capture format, and always stop_stream() before close(). Separate channel/rate probing was aborting on Bluetooth SCO devices (e.g. FreeBuds) with malloc corruption. Fixes #567 * refactor(audio): open capture stream once instead of probe-close-reopen Adversarial review of the first fix found it still closed the probe stream and immediately reopened the device — the same rapid open/close pattern blamed for the Bluetooth SCO heap corruption, just fewer cycles. _open_capture_stream() now returns the successfully negotiated stream and all three callers (mic test, recording, reconnect) use it directly, so each capture session performs exactly one PortAudio open. Also drops the dead known_working_rate parameter. * test(audio): cover negotiation fallback paths for codecov patch Add tests for mic-test, recording, and reconnect fallback branches when _open_capture_stream returns no stream, plus Bluetooth settle-on-failure and empty-read reconnect cleanup. Brings patch diff coverage above 80%. |
||
|
|
b945137d60 |
fix(vulkan): auto-select discrete GPU and add manual device selection (#590)
* fix(vulkan): auto-select discrete GPU and add manual device selection On hybrid GPU systems (Intel iGPU + NVIDIA dGPU), whisper.cpp's Vulkan backend always selected device 0 (the integrated GPU), resulting in significantly slower performance. Changes: - Add detect_vulkan_devices() to enumerate all Vulkan GPUs and identify discrete vs integrated devices - Set GGML_VULKAN_DEVICE env var before model init to select the correct GPU (auto-selects discrete GPU when available) - Add whispercpp_gpu_device config option for manual device selection - Add GPU device dropdown in Settings > Advanced for users with multiple Vulkan GPUs Fixes #589 * test: add coverage for Vulkan GPU device selection - Test detect_vulkan_devices() with single/multiple GPUs - Test _prefer_discrete_vulkan_device() preference logic - Test GPU device selection in recognition_manager - Verify GGML_VULKAN_DEVICE env var is set correctly * fix(speech_recognition): pass whispercpp GPU device to pywhispercpp Model context_params The Vulkan device-selection logic from PR #590 set the GGML_VULKAN_DEVICE environment variable, but pywhispercpp did not pick it up. Pass the selected GPU device through the pywhispercpp Model context_params so whisper.cpp actually initializes the requested Vulkan device. Fixes #589 * fix(speech_recognition): fallback when pywhispercpp lacks context_params Older pywhispercpp releases (< ~1.4.0) reject the context_params keyword and raise TypeError. Detect that specific failure and retry without GPU device selection so the engine still loads on those versions. Fixes #589 * refactor(speech_recognition): inline context_params assignment Simplify the GPU device selection path and remove the temporary dict. * fix(vulkan): parse real vulkaninfo GPU0: headers detect_vulkan_devices() only recognized fictional "GPU id = N" headers, so real vulkaninfo --summary output (GPU0:/GPU1:) returned no devices and hybrid NVIDIA systems fell through to CUDA. Also resolve preferred device names by GPU id instead of list position. Fixes #589 * refactor(whispercpp): drop ineffective GGML_VULKAN_DEVICE env var pywhispercpp ignores GGML_VULKAN_DEVICE; device selection already goes through context_params={"gpu_device": N}. Remove the misleading env write so maintainers do not think the env var is the selection path. |
||
|
|
3f5a5effff |
feat(vad): add Silero VAD and drop silence-only buffers (#447)
* feat(vad): replace amplitude-based VAD with Silero neural network Replace the simple amplitude threshold VAD with Silero VAD, a lightweight neural network model that classifies audio as speech/non-speech. This addresses the root cause of #302 (silence not stopping recording) and - Add silero_vad.py wrapper using ONNX Runtime with bundled Silero v5 model - Accumulate 512-sample chunks with 64-sample context window per official API - Map existing vad_sensitivity (1-5) to Silero thresholds (0.8-0.3) - Use max() across sub-chunks to avoid missing speech onsets - Fall back to amplitude VAD when onnxruntime is unavailable - Add onnxruntime as optional dependency (pip install vocalinux[vad]) Closes #344 * address review: add tests, LICENSE, logging, validation fixes - Add unit tests for SileroVAD (process, reset, fallback, sensitivity mapping) - Add MIT LICENSE for bundled Silero VAD model in data/ - Log which VAD backend is active on init - Validate chunk length in SileroVAD.process() - Skip is_speech check until a full Silero chunk is processed - Add thread safety note to SileroVAD docstring - Document resampling rate effect on VAD resolution - Comment explaining why load_silero_vad() catches broad Exception * address review: bundle license, document [vad] extra, surface backend in UI - Pack data/LICENSE into the wheel (pyproject package-data) so attribution travels with the model - README: short note on enabling neural VAD via vocalinux[vad] - Settings: VAD Sensitivity row subtitle shows the active backend; if onnxruntime is missing, an info-row beneath the group spells out the install command and the restart requirement - silero_vad.is_silero_available() probes onnxruntime + model presence w/o instantiating an InferenceSession - CI installs .[dev,vad] so Silero paths get exercised - Integration test for _record_audio Silero branch (mocked pyaudio + scripted SileroVAD), covering silence flush, speech reset, and sensitivity threshold mapping at sens=1 vs sens=5 - Tests no longer skip when other modules globally mock numpy: pop the top-level numpy ref so a fresh import gives the real package, and swap sys.modules["numpy"] inside the _record_audio call so the lazy import inside the function picks up real numpy too * fix(vad): drop silence-only recording buffers * test(vad): align stop buffer expectations * test(vad): preserve real numpy module * fix(install): install vad support opportunistically * test(vad): cover recognition manager vad edges --------- Co-authored-by: Sbenazar <127324689+Sbenazar@users.noreply.github.com> |
||
|
|
e52c96fc38 |
test: cover recognition internals and suppress desktop notifications (#414)
* test(recognition): cover _perform_recognition and _enqueue_audio_segment
The previous commit demoted logger.info('DEBUG: ...') to logger.debug(...)
and removed a dead loop body in _perform_recognition. Codecov flagged 12
uncovered lines — all inside _perform_recognition and _enqueue_audio_segment,
which existing tests always mocked out.
Add direct (non-mocked) tests for both methods:
- _enqueue_audio_segment:
* empty buffer → early return
* normal buffer → enqueues correctly
* full queue → drops oldest and retries
- _perform_recognition:
* processes a segment then exits on None signal
* drains remaining items on None signal
* exits cleanly when idle with empty queue
* continues looping on queue timeout while recording
These tests exercise the actual threading/queue logic and cover the
logger.debug / logger.warning calls as a side effect.
* test(conftest): suppress real desktop notifications during test runs
_show_notification shells out to notify-send, which pops up real system
notifications when tests exercise the model-not-ready path. Add an autouse
fixture that patches _show_notification for all tests EXCEPT those whose
name contains 'show_notification' (so direct tests of the helper still
verify subprocess.Popen calls).
* chore(gitignore): ignore .sisyphus directory
|
||
|
|
d04947374f |
fix(recognition): preserve final speech on stop (fixes #401)
Replace hard-coded stop tail trim with configurable stop_sound_guard_ms (default 200ms) so quick key release no longer clips the final spoken word in push-to-talk mode. Co-authored-by: Fakhareddine <fe.sabbari@claranet.com> |
||
|
|
929f890b70 |
fix(audio): probe channels using device-supported sample rates (#341)
Fixes #340 by making channel probing use the device default sample rate first, then fallback rates, so 48kHz-only USB interfaces initialize correctly. |
||
|
|
fa4da40e7b |
test(coverage): improve test coverage from 57% to 80%+ (#327)
* test(coverage): improve test coverage from 57% to 80%+ Add 30 new test files with 861 additional test cases to improve overall test coverage from 57% to 80%+ (statement coverage). Key modules covered: - recognition_manager.py: 43% → 69% (audio device detection, transcription, model download, engine initialization, buffer management) - text_injector.py: improved coverage for X11/Wayland text injection, environment detection, clipboard fallback, shortcut injection - ibus_engine.py: 22% → 73% (engine lifecycle, text injection, socket server) - evdev_backend.py: 11% → 78% (device detection, key event handling) - pynput_backend.py: 43% → 76% (start/stop, key handling, callbacks) - keyboard_backends/__init__.py: 54% → improved (backend creation, env detection) - whispercpp_model_info.py: 32% → improved (GPU detection, model recommendations) - about_dialog.py, first_run_dialog.py, main.py, single_instance.py, common_types.py, config_manager.py, autostart_manager.py: various improvements All 1433 tests pass with proper test isolation to prevent mock pollution between test modules. * test(quality): audit and fix test quality issues Code review audit identified and fixed the following issues: - Remove bare try/except blocks that swallow all errors (7 tests fixed in recognition_manager_deep, replaced with proper assertions or deleted) - Delete source code inspection tests that read .py files as strings instead of testing behavior (deleted test_about_dialog_coverage.py and test_first_run_dialog_coverage.py entirely - ~35 useless tests removed) - Add meaningful assertions replacing weak assertIsNotNone/assertIsInstance checks (common_types_coverage, ibus_engine_coverage, keyboard_backends_extra) - Fix tests that mock the system under test instead of its dependencies (text_injector_extra now mocks subprocess.run instead of injection methods) - Add missing assertions to tests with no verification (ibus_engine focus_out, log window info, copy to clipboard) - Verify download tests check requests.get was called with correct URLs (coverage_boost download tests) - Fix pytest warning by renaming test_audio_input import to avoid pytest collecting it as a test function All 1356 tests pass with 0 failures and 0 warnings. Statement coverage: 80.3% (3257/4054 lines covered). * style(tests): fix black formatting and isort import ordering Auto-format all new test files with black and isort to pass CI lint checks. * fix(tests): resolve CI hangs and rename test files for clarity - Fix CI hangs by properly mocking gi/GTK/IBus in all test files - Fix sys.modules pollution in recognition manager tests by using tmp_path - Add pytest-timeout to prevent future hangs - Rename 28 test files to use descriptive, consistent names mapping to source modules * fix(tests): resolve Python 3.13 CI failures - Fix _load_stdlib_module() in test_recognition_manager_downloads.py to handle stdlib modules that are packages (directories with __init__.py) rather than single .py files. In Python 3.13, zipfile became a package, causing FileNotFoundError during test collection (exit code 2). - Fix invalid escape sequence '$' in test_cross_distro_compatibility.py by using a raw string. Python 3.13 reports this as SyntaxWarning and Python 3.14 will make it a SyntaxError. * fix(tests): use direct import for zipfile instead of _load_stdlib_module The _load_stdlib_module approach fails on Python 3.13 where zipfile is a package (zipfile/__init__.py). Loading it via spec_from_file_location with a custom name breaks relative imports inside the package (e.g. 'from ._path import ...' resolves to '_stdlib_zipfile._path' which doesn't exist). Simply import zipfile at module level before any test mocks can pollute sys.modules — this is safe because the module-level code runs during test collection, before any test fixtures or patches are applied. * fix(tests): mock gi/GTK in conftest to prevent CI hangs On CI, real PyGObject is installed and module-level imports in vocalinux source files (ibus_engine, tray_indicator, settings_dialog, etc.) trigger GTK initialization or IBus daemon connections that hang indefinitely in headless environments. pytest-timeout's signal-based timeout cannot interrupt these C-level blocking calls. Fix by mocking gi and gi.repository in conftest.py (which runs before any test module is collected), ensuring all test files are protected regardless of whether they remember to mock individually. Also add timeout-minutes: 10 to the CI test job as a safety net so that any remaining hangs fail fast instead of running indefinitely. * fix(tests): unconditionally mock gi in conftest for CI The previous 'if gi not in sys.modules' guard was ineffective on CI because PyGObject is installed via pip, so the real gi module is already loaded. This caused GTK initialization and IBus daemon connections that hang indefinitely in headless CI environments. Now unconditionally replace gi and gi.repository with mocks during test collection, regardless of whether the real package is installed. * fix(tests): reduce timeout to 10s and use thread-based timeout Use timeout_method=thread instead of signal (default) so that pytest-timeout can interrupt C-level blocking calls (GTK operations, socket accepts, subprocess waits) that the signal-based method cannot handle. Also reduce per-test timeout from 30s to 10s since no legitimate unit test should take longer, and hanging tests were consuming the entire CI job timeout budget. * fix(tests): set global socket timeout to prevent blocking on CI Tests in test_ibus_engine.py create real Unix sockets with daemon threads that block on socket.accept(). When tests fail or timeout, these threads remain blocked indefinitely, preventing pytest from completing. The thread-based timeout catches the hang but cannot terminate the blocking accept() call. Set socket.setdefaulttimeout(5) in conftest.py so all socket operations (accept, connect, recv) will raise socket.timeout after 5 seconds instead of blocking forever. * fix(tests): add cleanup fixture for IBus socket server threads Add autouse fixture that stops any leftover VocalinuxEngine socket server threads after each test. Tests that trigger _start_socket_server() spawn daemon threads blocking on socket.accept() that persist after the test completes, eventually causing pytest-timeout to kill the process. The cleanup fixture sets _server_running=False and closes the server socket, which unblocks the accept() call and allows the daemon thread to terminate. * fix(tests): reduce socket timeout to 0.1s to avoid slowing tests The 5-second socket timeout caused socket operations in daemon threads to block for 5 seconds per iteration before timing out, significantly slowing the test suite on CI. Reduce to 0.1s so blocking socket calls fail fast without noticeably impacting test execution time. * fix(tests): use 2s socket timeout and increase CI timeout to 15min The 0.1s socket timeout was too aggressive and caused legitimate test socket operations to fail. Use 2s which is long enough for test sockets to work but short enough to unblock daemon threads. Increase CI job timeout to 15 minutes to accommodate the socket timeout overhead from daemon threads that retry every 2 seconds. * fix(tests): block known-blocking daemon threads to prevent CI hangs Instead of using socket timeouts (which either break tests or are too slow), prevent specific known-blocking daemon threads from starting: - ibus_engine.server_thread: blocks on socket.accept() - evdev_backend._monitor_devices: blocks on select.select() These threads are identified by their target function name and skipped during Thread.start(). The thread is marked as started/stopped so join() calls in cleanup code don't raise RuntimeError. Test-created daemon threads (e.g. mock socket servers) are unaffected since they use different target function names. * fix(tests): patch Thread.join for Python 3.13 compatibility Python 3.13 changed threading internals — join() now uses _handle.join() which raises 'thread not started' for threads that were never actually started. Instead of trying to fake internal state, patch join() to be a no-op for threads that were skipped by our _safe_thread_start guard. This fixes the 2 remaining test_evdev_backend_ext failures on Python 3.13. |