Building a local speech-to-text interview assistant for Linux in C++23: whisper.cpp on a 4 GB GPU, KDE Wayland overlay, CPU fallback

TL;DR: consigliere is a desktop assistant for technical interviews on Linux (Kubuntu 26.04, KDE Plasma 6.6 Wayland, NVIDIA). It transcribes both sides of the call locally with whisper.cpp, OCRs the task from a screen region with Tesseract, and streams an LLM answer into a click-through overlay. Below: the audio pipeline, VAD windowing, fitting whisper into 4 GB of VRAM, trimming ggml's CUDA kernels (package 89 → 34 MB), a time budget per speech window, interrupting the encoder mid-pass on CPU (34 s → 59 ms), and a one-byte circuit breaker.

I'm building consigliere, a desktop assistant for technical interviews on Linux. Yes, some people consider this an ethically grey area. But there are plenty of such tools, and I didn't find one for Linux. It also fits other uses: mock interviews, solving problems out loud, interviews where assistants are allowed, language practice. Under the hood: C++23, a 16 kHz audio pipeline, whisper.cpp, speech recognition inside 4 GB of VRAM.

What it does

  • Listens to both sides. Two PipeWire streams, the interviewer and the candidate, are transcribed by whisper.cpp on the GPU.
  • Reads the task. A hotkey captures a pre-selected screen region with the problem statement, and Tesseract turns it into text.
  • Suggests an answer. The transcript and the task go to an LLM (Anthropic or OpenAI, your own key), and the answer streams into the window as it is generated. A second mode asks clarifying questions about the task.
  • Catches the candidate's mistakes. What the candidate says is checked too, and a likely mistake is highlighted while it can still be corrected out loud.
  • Stays out of the way. The window is transparent and passes clicks through. Only the app's own global shortcuts are captured.

No audio is uploaded: speech recognition and OCR run locally. Screenshots leave the machine only as the pages of a multi-page task. Otherwise only text goes to the LLM.

Why only Kubuntu, KDE Plasma and NVIDIA

Because the goal is a class of machines without compatibility layers, not portability. I'd like more, but there are limits at this stage. Every number below was measured on the development machine: an RTX 3050 Laptop with 4 GB of VRAM and 32 GB of RAM. The stack is fixed: Kubuntu 26.04, KDE Plasma 6.6 on Wayland, an NVIDIA GPU.

The one hard rule: the GPU does speech recognition and nothing else. OCR runs on the CPU and system RAM on any GPU, and the LLM is remote (because of the constraints of this machine class).

Audio: two streams, one ring buffer each

Audio is captured by two PipeWire streams on a pw_thread_loop. The interviewer's stream sets PW_KEY_STREAM_CAPTURE_SINK=true, so it records the monitor of the default output, i.e. the call audio, not a microphone. The second stream is the default microphone. Everything is converted to 16 kHz mono, which is what whisper expects.

Between the PipeWire callback and the rest of the app sits CaptureRing, a single-producer/single-consumer ring buffer on std::atomic with atomic::wait/notify, no mutexes, no condition variables. Capacity is rounded up to a power of two and the index is masked. The default is 2¹⁸ samples, about 16 seconds of audio per source.

VAD and windows: from a stream to chunks of speech

Before audio reaches whisper it passes a voice activity detector (VAD), whose job is to decide in real time whether the current frame contains human speech or just background noise and silence. The detector is Silero VAD converted to ggml (ggml-silero-v5.1.2), executed by whisper.cpp itself, so I didn't have to pull a second ML runtime into the app. You'll see ggml a lot from here on: it's Georgi Gerganov's C tensor library that whisper.cpp and llama.cpp are built on. It stores models in its own format, builds a compute graph and runs it on one of its backends: CPU (its own thread pool, SIMD) or CUDA.

The VAD looks at audio in frames of 512 samples. The two sources are tuned differently:

Interviewer (speakers) Candidate (microphone)
Speech probability threshold 0.5 0.6
Minimum speech 250 ms 300 ms
Padding before and after 300 ms 300 ms
Silence that closes a phrase 700 ms 700 ms
Maximum window 14 s 14 s

This yields speech windows from 550 ms to 14 seconds. Each window is one whisper job.

The recognition queue has two lanes. Interviewer windows are never evicted and always go first: missing a question is worse than falling behind on your own reply. Microphone windows live in a 4-slot ring: if recognition can't keep up, the oldest candidate utterances are dropped.

whisper: what's on and what's off

Speech is recognised by whisper, OpenAI's open speech recognition model, run through whisper.cpp, the ggml implementation of whisper. The family ranges from tiny to large: the bigger the model, the more accurate and the slower. I settled on large-v3-turbo, a lighter version of the most accurate large-v3 with a cut-down decoder, so it is noticeably faster at similar accuracy. It is stored in q8_0 quantisation (8 bit). That matters, because it is first of all about memory, which is the scarce resource on this machine class.

A neural network is hundreds of millions of numbers, its weights. Usually each one is stored as a half-precision float (FP16), 16 bits. Quantisation compresses these numbers to fewer bits at the cost of a small loss in precision. In ggml this is done in blocks of 32 weights: each block stores one shared FP16 scale, and the weights themselves as small integers that are multiplied by that scale during computation.

Official whisper models are quantised to three formats: 8 bit (q8_0) and 5 bit (q5_0, q5_1).

Format Layout of a block of 32 weights Bits per weight
FP16 (uncompressed) 32 numbers of 16 bits 16
q8_0 FP16 scale + 32 eight-bit integers, 34 bytes 8.5
q5_1 FP16 scale and offset + 32 five-bit integers, 24 bytes 6
q5_0 FP16 scale + 32 five-bit integers, 22 bytes 5.5

The large-v3-turbo file is 874 MB in q8_0 and 574 MB in q5_0, and would take about 1.6 GB in FP16. On a 4 GB card, where compute buffers have to fit next to the weights, that difference matters.

Besides saving memory, quantisation speeds up inference: compressed weights are read from VRAM faster, and for q8_0 and q5_x ggml has dedicated fast matrix-multiplication kernels that work directly on the compressed data (MMQ). A kernel is a small program the GPU runs; in CUDA there is one per math operation, and separate variants for every compressed-weight format and every attention head size (flash attention), all of it for every GPU generation. By default ggml compiles kernels for every case, which is hundreds of variants. With them the consigliere package weighed 89 MB. I kept only what whisper needs: fast matrix multiplication for 8- and 5-bit weights, and flash attention for head size 64 with F16 (it is the same for all whisper models, so kernels for 80, 96, 128, 256 and so on aren't needed). Out of 137 kernels per generation, 86 remain, the package shrank from 89 to 34 MB, and the build got 2.6× faster. Kernels are built for four generations: sm_75 (RTX 20xx, GTX 16xx), sm_86 (RTX 30xx), sm_89 (RTX 40xx) and sm_120a (RTX 50xx). By general CUDA rules, sm_86 kernels also run on other 8.x chips with a minor version of at least 6. GTX 10xx (Pascal, sm_61) and the A100 datacenter card (sm_80) are not covered. The package ships no PTX (the intermediate code the driver could JIT for an unknown card), so the CUDA path most likely won't work on those cards.

For large-v3-turbo in q8_0, the live settings are tuned for latency rather than maximum quality:

  • greedy decoding;
  • no temperature fallback ladder;
  • instead of whisper's own context, the prompt carries the tail of the transcript of the same source, up to 96 tokens, reset after 20 seconds of silence.

Each source has its own language. In auto-detect mode the language gets "sealed" after 2 seconds of confident speech, and whisper stops spending time on detection after that.

A model in another format still runs: the missing operations go through generic cuBLAS kernels or to the CPU, slower, but never refused.

When there is no GPU

I originally wrote this for CUDA only. Measurements showed that hosts without it can be supported: such machines should get either a CPU transcript or a clear "your CPU can't keep up" message, not a silent app. ggml is built for an x86-64-v3 baseline (AVX2, FMA, F16C, BMI2); on an older CPU speech recognition is switched off with a clear status instead of a SIGILL, and everything else keeps working.

The window budget, or how long you may think about one chunk of speech

A window is a chunk of speech cut out by the VAD, 550 ms to 14 seconds of audio, one phrase or part of one. Each window is a separate whisper call.

The pipeline's main rule: recognising a window must not take longer than the speech itself lasted. If a 3-second phrase takes 5 seconds to recognise, the transcript falls further behind with every phrase, and after a couple of minutes the suggestions arrive for a question that is already closed. So every call has a time budget, and as soon as it's exhausted whisper is interrupted through its abort callback. The window is lost, but the pipeline doesn't accumulate lag.

The naive budget is the window's duration. It breaks on short windows. whisper has a cost that barely depends on the audio length: the encoder always processes the spectrogram of a fixed 30-second chunk, however much speech is in it. So 0.6 seconds of "uh-huh" can't be recognised in 0.6 seconds even on a good GPU, let alone a CPU. The budget therefore needs a lower bound, a floor: the window's budget is the larger of the window's duration and the floor.

The floor depends on the machine and can't be a constant. So the app measures it at startup; that's the calibration. Right after loading the model, whisper recognises one second of silence twice:

  • the first run pays the one-off costs: allocating compute buffers and the first load of the GPU kernels; its time is discarded;
  • the second run shows the steady-state cost of one call on this hardware; that's the time that is used.

The floor is twice the second run's time, clamped to 550–14,000 ms.

Why double? Calibration recognises silence, while a real window with speech costs more: the decoder has something to write. Across four models and 200+ windows, a real window cost 1.00–1.37× the warm-up. ×2 is the smallest integer that covers this; the measurement only confirms it is enough, it doesn't pick it.

Why not below 550 ms? On the GPU calibration takes about 239 ms; doubling gives 478, shorter than the shortest window. The lower bound keeps the floor from getting stricter than it was before calibration.

Why not above 14,000 ms? A floor above the longest window would mean every window's budget is the floor, and the "no longer than the speech itself" rule would cease to exist. If a machine can't fit even 14 seconds, that's no longer a budget question: the app honestly says the CPU can't keep up.

In practice: on the GPU the floor is 550 ms and the budget almost always equals the phrase's own duration. On a CPU with no GPU, one encoder pass takes 8–19 seconds, the floor hits 14,000 ms, and it is clear at startup that a live transcript with this model won't happen. The app says "CPU too slow" right away instead of making you talk for ten seconds to find out.

If a call hasn't finished even within two budgets, it's treated as a hang, not slowness. All these rules are pure constexpr functions; the edge cases (overflow when doubling, both ends of the range) are checked with static_assert.

language=auto costs two encoder passes

During calibration the app also predicts whether the host can recognise in real time. It turned out that with language auto-detection whisper runs two full encoder passes per window: first it detects the language, then it transcribes. On the CPU the auto / fixed-language ratio was 1.94–1.99. The prediction was off by half.

Where the two comes from is visible in whisper.cpp itself. Here is an abridged fragment of whisper_full_with_state (error handling and everything irrelevant removed):

// whisper.cpp, whisper_full_with_state() — abridged
if (params.language == nullptr || strlen(params.language) == 0 ||
    strcmp(params.language, "auto") == 0 || params.detect_language) {
    // inside: a full encoder pass, whisper_encode_internal(...)
    const auto lang_id = whisper_lang_auto_detect_internal(ctx, state, 0, /* … */);
}
// …
// the main decoding loop: one more encoder pass
if (!whisper_encode_internal(*ctx, *state, seek, params.n_threads, /* … */)) { /* … */ }

So with language=auto the encoder runs twice, with a fixed language once. The fix is not a per-CPU fudge factor like "×1.97" but this structural fact, written into the app's engine:

// consigliere, src/core/.../stt/inference_budget.hpp
[[nodiscard]] constexpr std::uint32_t encoder_passes_per_window(Language language) noexcept
{
    switch (language)  // closed switch, no default: a new language won't compile without an answer
    {
    case Language::Auto:
        return 2;
    case Language::En:
        /* … the other languages … */
        return 1;
    }
    return 1;
}

The predicted window cost is the calibration times this number. The 1.94–1.99 measurement only confirms the two; it doesn't pick it. If a future whisper.cpp learns to reuse the encoder output from language detection, the two becomes wrong.

After this, prediction and reality differed by no more than 2%.

Once we know we can't keep up, stop burning CPU

After the app decided the host was too slow, the worker still kept handing every window to whisper, and each one took 8–35 seconds of CPU just to be cut off by the budget. Now, after that decision, no window reaches the engine until restart. Three windows after the latch cost 428 seconds of CPU time; now they cost 1 ms.

Interrupting the encoder mid-pass

whisper.cpp asks the abort callback only after a full encoder pass, and the language-detection pass can't be interrupted at all. On the CPU a window with a 14-second budget ran for up to 35 seconds, and closing the app waited just as long.

Yet ggml's CPU backend already checks for an abort between graph nodes; whisper just passes nullptr there. The fix is a small patch of my own that forwards my callback into the backend, plus a copy of a recent upstream commit that checks at the boundaries of language detection. The callback is called from thread 0 of ggml's pool, which is the same thread that started the computation (OpenMP is off, but that's another story), so the "budget fired" flag stays a plain bool.

Scenario (CPU) Before After
Stop, fixed language 16,245 ms 55 ms
Stop, auto 34,287 ms 59 ms
Budget abort, auto 21,442 ms 103 ms

Engine errors and a one-byte circuit breaker

whisper errors come in two kinds. After some, the context is dead: with return code −7 whisper frees its own state itself while the pointer in the context stays dangling. I moved the app's engine to owning its whisper_state (whisper_init_state + whisper_full_with_state): after such a code it lets go of the pointer without freeing it a second time and answers every later window with ContextLost. After other errors the context is alive, and it's wiser to drop one window than to kill transcription in the middle of an interview.

But a recoverable error that repeats on every window means silently losing the transcript. So each source has a breaker: the history of the last eight windows in one std::uint8_t.

history = static_cast<std::uint8_t>((history << 1) | (failed ? 1U : 0U));
const bool trip = std::popcount(history) >= 4    // half of the recent windows lost
               || std::countr_one(history) >= 3; // or three in a row

The counters are per source: short successful "uh-huh"s from the microphone must not mask a broken interviewer channel. A "fail, fail, ok" rhythm trips on the fifth window; a single mic click split across two windows doesn't. Separately, an error counts as "too slow" only if the budget actually fired in that call, not just because a lot of time passed.

An overlay on Wayland

The app's UI is a HUD (heads-up display): Qt Quick (QQuickView) with a QML scene of three zones: answer, code and transcript. On Wayland you can't just make an "always on top" window, so the window is a layer-shell surface (LayerShellQt, layer LayerOverlay):

  • the background is transparent and Qt::WindowTransparentForInput is set by default, so every click goes to the application under the overlay;
  • the keyboard isn't grabbed (KeyboardInteractivityNone); focus is enabled only while the user works with one of the zones.

OCR

Screenshots of the pre-selected screen region are parsed by Tesseract OCR in LSTM-only mode (OEM_LSTM_ONLY, PSM_SINGLE_BLOCK), with 11 language models. There's almost no preprocessing, just cropping to the selected region, no binarisation, no upscaling. OCR lives in one std::jthread and takes 370–409 ms (p95) against an 800 ms budget. A long task can be assembled from several captures in a row, e.g. when the problem statement doesn't fit on one screen.

LLM client

Talking to the LLM is done with libcurl and streaming. The response is parsed by a hand-written SSE parser implemented as a finite-state machine; provider events turn into chunks of text in the HUD immediately.

Context is limited. Token estimation is conservative, with a ×1.2 margin. At least 512 tokens are always reserved for the task and 300 for your session instructions; if a request doesn't fit, you find out in the settings, before sending.

Checking the candidate's answers is a separate short request that runs only for utterances of at least 5 words.

The API key is stored in KDE Wallet via the Secret Service API: OpenSession → ReadAlias("default") → SearchItems → GetSecrets. For writing into a locked collection the app handles both behaviours, ksecretd's and gnome-keyring's.

Under the hood

The project is C++23: clang 21, Conan 2, CMake. The code is split into:

  • a core: pure value types, ranges, no I/O, tested without mocks;
  • a shell: threads, PipeWire, Qt, D-Bus, libcurl.

Qt doesn't leak into the core.

Checking the project is one script, check.sh: clang-format, three builds with tests (ASan+UBSan, TSan, and the shipping release build), cppcheck and a full clang-tidy pass.

Licences without accounts

I wanted the app to work offline after activation, without an account and without online checks; I don't need any of that. I care about the project growing and being useful, not about your wallet or your soul.

The licence gateway is written in Go and lives behind a Cloudflare Tunnel. Licences are signed with a key in AWS KMS.

Try it

There's a trial: 7 days from the first press of Start, one per machine. It's a good idea to configure the app before pressing Start.

For those without Kubuntu 26.04 there's a Kubuntu-based live image that boots from a USB stick (I like Ventoy for that). Inside: the app, the models and the NVIDIA driver (the GPU image). A CPU-only image without the models or the driver is published alongside it. The image is built by a script from the official ISO: unpack the squashfs, install the package, rebuild the initrd and replay the original boot setup with xorriso. There's no installer in the image: Calamares is removed during the build and the "Install" entries are gone from the boot menu. An empty KDE wallet for the live user is created by a casper hook in the initramfs, only on a live boot and only for that user, so if you dd the image to a disk by hand there won't be an empty-password wallet on it. The default theme is Kubuntu Dark.

All articles