Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e63897a4f6 | |||
| a94ba824d6 | |||
| e04b003bf8 | |||
| a87a12ae7e | |||
| 09cac68075 | |||
| ee76328daf | |||
| 02581c0c27 | |||
| dd25b2f58b | |||
| 95af0f224b | |||
| d56260fdb9 |
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# Build directories
|
# Build directories
|
||||||
build/
|
build*/
|
||||||
deps/
|
deps/
|
||||||
*.vcxproj
|
*.vcxproj
|
||||||
*.vcxproj.filters
|
*.vcxproj.filters
|
||||||
|
|||||||
@@ -1,411 +0,0 @@
|
|||||||
# Win Dictation — Architecture Analysis & Dev Guide (Build 4)
|
|
||||||
|
|
||||||
Two parts:
|
|
||||||
|
|
||||||
- **Part A — Architecture analysis & recommendations.** Where the app stands now (post-fixes) and what's worth hardening.
|
|
||||||
- **Part B — Dev guide** for the two things you asked for: (1) removing the leftover Windows chrome (combo dropdown buttons, button hairlines, the line around *Pinned*), and (2) showing real transcription progress + a time estimate instead of a static "Transcribing…".
|
|
||||||
|
|
||||||
Context: native C++ / Win32 + SDL2 + whisper.cpp, CPU-only (i5-7th-gen, 2c/4t). Companion docs: `MODERN-UI-AND-FIXES.md`, `FINDINGS-FIXES-TESTS.md`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Part A — Architecture Analysis & Recommendations
|
|
||||||
|
|
||||||
## A1. Current architecture (it's in good shape)
|
|
||||||
|
|
||||||
```
|
|
||||||
┌── UI thread (message loop) ───────────────┐ ┌── Audio thread (SDL callback) ──┐
|
|
||||||
│ • window, hotkeys, tray, GDI+ paint │ │ • append f32 samples to │
|
|
||||||
│ • owns Transcriber │◀────│ m_capture (mutex) │
|
|
||||||
│ • marshals worker results via PostMessage│ │ • update VU energy (atomic) │
|
|
||||||
└──────────────┬────────────────────────────┘ └─────────────────────────────────┘
|
|
||||||
│ stop_and_transcribe()
|
|
||||||
▼
|
|
||||||
┌── Worker thread (one per utterance) ──────┐
|
|
||||||
│ • run_inference(): whisper_full() ONCE │
|
|
||||||
│ • PostMessage(WM_APP_RESULT, text) │
|
|
||||||
└────────────────────────────────────────────┘
|
|
||||||
```
|
|
||||||
|
|
||||||
State machine: **Idle → Recording → Transcribing → Idle**, with the model preloaded on a detached thread at startup.
|
|
||||||
|
|
||||||
**What's genuinely good now:**
|
|
||||||
- **Clean thread boundaries.** Audio capture, inference, and UI never block each other; all cross-thread hand-offs are atomics or `PostMessage`. This is the right shape.
|
|
||||||
- **Batch (record-then-transcribe).** The correct model for dictation on a slow CPU — no real-time deadline, latency independent of clip length.
|
|
||||||
- **Core is decoupled and unit-testable** (`Transcriber` + `run_inference`/`transcribe_sync`, `text_util.h`). The UI is a thin shell over it.
|
|
||||||
- **Robust startup** (single-instance, honest `g_modelOk`, `g_initializing` guard, `m_cfg_mtx`) — the earlier crashes are designed out, not patched over.
|
|
||||||
|
|
||||||
The remaining issues are **polish and hardening**, not structural. No rewrite needed.
|
|
||||||
|
|
||||||
## A2. Recommendations (ranked by impact ÷ effort)
|
|
||||||
|
|
||||||
| # | Recommendation | Why | Effort |
|
|
||||||
|---|---|---|---|
|
|
||||||
| 1 | **Transcription progress + ETA** (Part B2) | The #1 UX gap: a 1:40 clip shows a static "Transcribing…" with no sign of life. whisper.cpp already exposes a progress callback — wire it up. | S |
|
|
||||||
| 2 | **De-theme the stock controls** (Part B1.1) | The hairlines around the buttons / *Pinned* are themed-edge leftovers. `SetWindowTheme(h, L"", L"")` + `WS_CLIPCHILDREN` + hide-focus removes them. | S |
|
|
||||||
| 3 | **Replace the comboboxes with custom dropdowns** (Part B1.2) | A `CBS_OWNERDRAWFIXED` combo *cannot* hide its native dropdown button — that's the "second arrow" you see. The only clean fix is to not use a combobox. | M |
|
|
||||||
| 4 | **Persist settings** | Mic, model, pin, auto-paste, window position all reset every launch. A tiny INI (`WritePrivateProfileStringW`) or registry blob fixes it. | S |
|
|
||||||
| 5 | **Cancel/abort during transcription** | Pairs with #1 — if a long clip is wrong, let the user abort via `whisper_full_params.abort_callback`. | S |
|
|
||||||
| 6 | **Delete the stale `src/CMakeLists.txt`** | It references removed APIs (`init`, `is_using_gpu`) and a `test-audio` target the root build ignores. It's a trap for the next contributor. | XS |
|
|
||||||
| 7 | **Bound the capture buffer** | `m_capture` grows ~1.9 MB/30 s with no cap. Add a soft limit (e.g. auto-stop at 10 min) so a forgotten recording can't grow unbounded. | XS |
|
|
||||||
| 8 | **Configurable hotkeys + conflict check** | `Ctrl+Shift+Space`/`H` are hard-coded; `RegisterHotKey` failures are silently ignored. Surface a warning and allow remap. | M |
|
|
||||||
| 9 | **Lightweight logging** | A single rotating log line per session (model, threads, last error) makes field issues diagnosable without a debugger. | S |
|
|
||||||
|
|
||||||
**Architectural note for the future:** the app leans on owner-drawing *stock* controls (buttons, combos). That's fine at this size, but every stock control fights you on chrome (edges, focus cues, dropdown buttons). If the UI grows, the higher-leverage move is a small set of **fully custom controls** (a `Button`, a `Select`, a `ProgressBar` you paint entirely in `WM_PAINT` and hit-test yourself) rather than more owner-draw patches. Part B1.2's custom dropdown is the first step down that path.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Part B — Dev Guide
|
|
||||||
|
|
||||||
## B1. Remove the leftover Windows chrome
|
|
||||||
|
|
||||||
There are **three** separate sources of "Windows-y" pixels, each with a different cause:
|
|
||||||
|
|
||||||
| What you see | Cause |
|
|
||||||
|---|---|
|
|
||||||
| Thin light line around *Pinned*; vertical line left + horizontal line top of Copy/Paste/Clear | The visual-style **themed edge** drawn behind owner-draw buttons, plus **focus rectangles** |
|
|
||||||
| Two arrows / a boxy button on the mic + model selectors | A `CBS_OWNERDRAWFIXED` combo still lets the **system draw the dropdown button** and field border — owner-draw only covers the text/items |
|
|
||||||
|
|
||||||
### B1.1 Kill the button hairlines + focus rectangles (quick, high-impact)
|
|
||||||
|
|
||||||
Three changes, all small:
|
|
||||||
|
|
||||||
**(a) De-theme the owner-draw controls.** `SetWindowTheme(h, L"", L"")` strips the UxTheme styling from a control so Windows stops painting its themed border/edge behind your `WM_DRAWITEM`. Add the header/lib and call it on every owner-draw control right after you create it:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#include <uxtheme.h>
|
|
||||||
#pragma comment(lib, "uxtheme.lib")
|
|
||||||
|
|
||||||
// after creating each owner-draw button (Record, Pin, Copy, Paste, Clear):
|
|
||||||
SetWindowTheme(hBtn, L"", L""); // remove themed edges
|
|
||||||
SetWindowSubclass(hBtn, BtnProc, 1, 0);
|
|
||||||
```
|
|
||||||
|
|
||||||
**(b) Stop the parent painting under the children.** Add `WS_CLIPCHILDREN` to the main window so its double-buffered `WM_PAINT` never bleeds a pixel into a child's rectangle:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
hMainWnd = CreateWindowExW(
|
|
||||||
WS_EX_TOPMOST,
|
|
||||||
L"WhisperDictationClass", L"Dictation",
|
|
||||||
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, // <- add WS_CLIPCHILDREN
|
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, 400, 340,
|
|
||||||
nullptr, nullptr, hInstance, nullptr);
|
|
||||||
```
|
|
||||||
|
|
||||||
**(c) Hide focus rectangles app-wide.** The dotted/thin rect that appears on whichever control has keyboard focus (often *Pinned* after you click it). Tell the UI-state machine to keep focus cues hidden — once, after the controls exist:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
SendMessageW(hMainWnd, WM_CHANGEUISTATE, MAKEWPARAM(UIS_SET, UISF_HIDEFOCUS), 0);
|
|
||||||
```
|
|
||||||
|
|
||||||
After (a)+(b)+(c), the only remaining stock chrome is the combo dropdown button, handled next.
|
|
||||||
|
|
||||||
### B1.2 Replace the comboboxes with a custom dropdown (removes the native button)
|
|
||||||
|
|
||||||
A combobox always owns its dropdown button — you can't draw it away. Replace each combo with a **flat owner-draw "select" button** (you already draw exactly this look in `DrawCombo`) that opens a **custom dark popup window**. No native button, no field edge, fully on-theme.
|
|
||||||
|
|
||||||
**Data model** (replace `g_modelComboPaths` usage as needed; keep a label list + selection per selector):
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
std::vector<std::wstring> g_audioItems; int g_audioSel = 0;
|
|
||||||
std::vector<std::wstring> g_modelItems; int g_modelSel = 0; // parallel to g_modelComboPaths
|
|
||||||
```
|
|
||||||
Populate these in `RefreshAudioDevices` / `RefreshModelList` instead of `CB_ADDSTRING`. Create `ID_SEL_AUDIO` / `ID_SEL_MODEL` as `BS_OWNERDRAW` buttons (not comboboxes) and draw them with a field renderer:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
void DrawSelect(LPDRAWITEMSTRUCT d, const std::wstring& text) {
|
|
||||||
Graphics g(d->hDC); g.SetSmoothingMode(SmoothingModeAntiAlias);
|
|
||||||
Rect rc(d->rcItem.left, d->rcItem.top, d->rcItem.right-d->rcItem.left, d->rcItem.bottom-d->rcItem.top);
|
|
||||||
SolidBrush bg(C_BG); g.FillRectangle(&bg, rc);
|
|
||||||
Rect field = rc; field.Inflate(-1,-1);
|
|
||||||
bool hover = GetWindowLongPtr(d->hwndItem, GWLP_USERDATA) != 0;
|
|
||||||
FillRound(g, hover ? C_SURFACEHI : C_SURFACE, field, 9);
|
|
||||||
StrokeRound(g, C_BORDER, field, 9, 1.0f);
|
|
||||||
Font f(d->hDC, g_fUI);
|
|
||||||
RectF tb((REAL)field.X+10, (REAL)field.Y, (REAL)(field.Width-28), (REAL)field.Height);
|
|
||||||
DrawTextC(g, text.c_str(), f, C_TEXT, tb, StringAlignmentNear, StringAlignmentCenter);
|
|
||||||
int cx = field.GetRight()-16, cy = field.Y + field.Height/2; // our chevron, the only one now
|
|
||||||
Pen pen(C_TEXTDIM, 1.6f);
|
|
||||||
g.DrawLine(&pen, cx-4, cy-2, cx, cy+2); g.DrawLine(&pen, cx, cy+2, cx+4, cy-2);
|
|
||||||
}
|
|
||||||
// in WM_DRAWITEM:
|
|
||||||
// case ID_SEL_AUDIO: DrawSelect(d, g_audioItems.empty()?L"No devices":g_audioItems[g_audioSel]); return TRUE;
|
|
||||||
// case ID_SEL_MODEL: DrawSelect(d, g_modelItems.empty()?L"—":g_modelItems[g_modelSel]); return TRUE;
|
|
||||||
```
|
|
||||||
|
|
||||||
**The popup window** — a small borderless top-level you paint yourself; closes on pick or focus loss:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
struct PopupState { std::vector<std::wstring> items; int sel; int hot; HWND owner; int ctrlId; };
|
|
||||||
static PopupState g_pop;
|
|
||||||
|
|
||||||
LRESULT CALLBACK PopupProc(HWND h, UINT m, WPARAM w, LPARAM l) {
|
|
||||||
switch (m) {
|
|
||||||
case WM_MOUSEMOVE: {
|
|
||||||
int row = GET_Y_LPARAM(l) / 30;
|
|
||||||
if (row != g_pop.hot) { g_pop.hot = row; InvalidateRect(h, nullptr, FALSE); }
|
|
||||||
TRACKMOUSEEVENT t{ sizeof(t), TME_LEAVE, h, 0 }; TrackMouseEvent(&t);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case WM_MOUSELEAVE: g_pop.hot = -1; InvalidateRect(h, nullptr, FALSE); return 0;
|
|
||||||
case WM_LBUTTONUP: {
|
|
||||||
int row = GET_Y_LPARAM(l) / 30;
|
|
||||||
if (row >= 0 && row < (int)g_pop.items.size())
|
|
||||||
PostMessageW(g_pop.owner, WM_APP_SELECT, (WPARAM)g_pop.ctrlId, (LPARAM)row);
|
|
||||||
DestroyWindow(h); return 0;
|
|
||||||
}
|
|
||||||
case WM_KILLFOCUS: DestroyWindow(h); return 0;
|
|
||||||
case WM_ERASEBKGND: return 1;
|
|
||||||
case WM_PAINT: {
|
|
||||||
PAINTSTRUCT ps; HDC hdc = BeginPaint(h, &ps);
|
|
||||||
RECT rc; GetClientRect(h, &rc);
|
|
||||||
HDC mem = CreateCompatibleDC(hdc);
|
|
||||||
HBITMAP bmp = CreateCompatibleBitmap(hdc, rc.right, rc.bottom);
|
|
||||||
HBITMAP old = (HBITMAP)SelectObject(mem, bmp);
|
|
||||||
{
|
|
||||||
Graphics g(mem); g.SetSmoothingMode(SmoothingModeAntiAlias);
|
|
||||||
Rect all(0,0,rc.right,rc.bottom);
|
|
||||||
FillRound(g, C_SURFACE, all, 10); StrokeRound(g, C_BORDER, all, 10, 1.0f);
|
|
||||||
Font f(mem, g_fUI);
|
|
||||||
for (int i = 0; i < (int)g_pop.items.size(); ++i) {
|
|
||||||
Rect row(3, i*30+3, rc.right-6, 28);
|
|
||||||
if (i == g_pop.hot) FillRound(g, C_SURFACEHI, row, 7);
|
|
||||||
RectF tb((REAL)row.X+9,(REAL)row.Y,(REAL)row.Width-12,(REAL)row.Height);
|
|
||||||
DrawTextC(g, g_pop.items[i].c_str(), f, (i==g_pop.sel)?C_ACCENT:C_TEXT,
|
|
||||||
tb, StringAlignmentNear, StringAlignmentCenter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BitBlt(hdc,0,0,rc.right,rc.bottom,mem,0,0,SRCCOPY);
|
|
||||||
SelectObject(mem, old); DeleteObject(bmp); DeleteDC(mem);
|
|
||||||
EndPaint(h, &ps); return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DefWindowProc(h, m, w, l);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShowSelectPopup(HWND owner, int ctrlId, const std::vector<std::wstring>& items, int sel) {
|
|
||||||
static bool reg = false;
|
|
||||||
if (!reg) { WNDCLASSEXW wc{ sizeof(wc) }; wc.lpfnWndProc = PopupProc; wc.hInstance = hInst;
|
|
||||||
wc.hCursor = LoadCursor(nullptr, IDC_ARROW); wc.lpszClassName = L"DictPopup";
|
|
||||||
RegisterClassExW(&wc); reg = true; }
|
|
||||||
g_pop = { items, sel, -1, owner, ctrlId };
|
|
||||||
RECT rc; GetWindowRect(GetDlgItem(owner, ctrlId), &rc);
|
|
||||||
int h = (int)items.size()*30 + 6, wdt = rc.right - rc.left;
|
|
||||||
HWND p = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, L"DictPopup", L"",
|
|
||||||
WS_POPUP, rc.left, rc.bottom+2, wdt, h, owner, nullptr, hInst, nullptr);
|
|
||||||
int corner = DWMWCP_ROUND; DwmSetWindowAttribute(p, DWMWA_WINDOW_CORNER_PREFERENCE, &corner, sizeof(corner));
|
|
||||||
ShowWindow(p, SW_SHOWNA); SetForegroundWindow(p); SetFocus(p);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Wire it up: clicking a selector opens the popup; the popup posts the chosen row back:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
// WM_COMMAND:
|
|
||||||
case ID_SEL_AUDIO: ShowSelectPopup(hWnd, ID_SEL_AUDIO, g_audioItems, g_audioSel); break;
|
|
||||||
case ID_SEL_MODEL: ShowSelectPopup(hWnd, ID_SEL_MODEL, g_modelItems, g_modelSel); break;
|
|
||||||
|
|
||||||
// new message handler:
|
|
||||||
case WM_APP_SELECT: { // #define WM_APP_SELECT (WM_USER + 5)
|
|
||||||
int ctrlId = (int)wParam, idx = (int)lParam;
|
|
||||||
if (ctrlId == ID_SEL_AUDIO) { g_audioSel = idx; g_config.capture_id = idx; }
|
|
||||||
else if (ctrlId == ID_SEL_MODEL && idx < (int)g_modelComboPaths.size()) {
|
|
||||||
g_modelSel = idx;
|
|
||||||
g_config.model_path = exe_dir() + "\\" + g_modelComboPaths[idx];
|
|
||||||
g_modelLoaded = false; g_modelOk = false; SetStatus(hWnd, L"Loading model…");
|
|
||||||
std::thread([]{ bool ok=g_tx.reload(g_config); g_modelOk=ok; g_modelLoaded=true; }).detach();
|
|
||||||
}
|
|
||||||
InvalidateRect(GetDlgItem(hWnd, ctrlId), nullptr, FALSE);
|
|
||||||
} break;
|
|
||||||
```
|
|
||||||
|
|
||||||
You can now delete the `CBS_*`/`WM_MEASUREITEM`/`DrawCombo` combo code and the `WM_CTLCOLORLISTBOX` handler. The selectors are now pixel-identical to your other controls with exactly one (your) chevron.
|
|
||||||
|
|
||||||
> Lighter alternative if you don't want a popup window yet: keep the combos but call `SetWindowTheme(hCombo, L"", L"")` — it flattens the dropdown button to a plain square. It's *less* boxy but the button is still there, so the popup-window route above is the real fix.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## B2. Transcription progress + time estimate
|
|
||||||
|
|
||||||
You don't have to guess the timing — **whisper.cpp reports real progress.** `whisper_full_params` has a `progress_callback` that fires repeatedly during inference with an `int` 0–100 (fraction of the audio processed). Feed that to a determinate progress bar + a live ETA, so "Transcribing…" becomes "Transcribing 1:40 of audio · 45% · ~9s left".
|
|
||||||
|
|
||||||
### B2.1 transcriber — expose progress + audio length
|
|
||||||
|
|
||||||
`transcriber.h` (public):
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
using ProgressCb = std::function<void(int)>; // 0..100
|
|
||||||
void set_progress_callback(ProgressCb cb) { m_on_progress = std::move(cb); }
|
|
||||||
float audio_seconds() const { return m_audio_seconds.load(); }
|
|
||||||
void request_cancel() { m_abort = true; } // optional (B2.4)
|
|
||||||
```
|
|
||||||
`transcriber.h` (private):
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
ProgressCb m_on_progress;
|
|
||||||
std::atomic<float> m_audio_seconds{0.0f};
|
|
||||||
std::atomic<bool> m_abort{false};
|
|
||||||
static void s_progress(struct whisper_context*, struct whisper_state*, int p, void* ud);
|
|
||||||
static bool s_abort(void* ud);
|
|
||||||
```
|
|
||||||
|
|
||||||
`transcriber.cpp` — the static trampolines and the `run_inference` hook:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
void Transcriber::s_progress(whisper_context*, whisper_state*, int p, void* ud) {
|
|
||||||
auto* self = static_cast<Transcriber*>(ud);
|
|
||||||
if (self && self->m_on_progress) self->m_on_progress(p);
|
|
||||||
}
|
|
||||||
bool Transcriber::s_abort(void* ud) {
|
|
||||||
auto* self = static_cast<Transcriber*>(ud);
|
|
||||||
return self && self->m_abort.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Transcriber::run_inference(std::vector<float>& audio) {
|
|
||||||
if (!m_ctx) return "";
|
|
||||||
m_abort = false;
|
|
||||||
if (m_cfg.trim_silence) trim_silence(audio);
|
|
||||||
m_audio_seconds = (float)(audio.size() / (double)WHISPER_SAMPLE_RATE); // for the UI
|
|
||||||
|
|
||||||
whisper_full_params wp = whisper_full_default_params(WHISPER_SAMPLING_GREEDY);
|
|
||||||
wp.print_progress = false; wp.print_realtime = false; wp.print_timestamps = false;
|
|
||||||
wp.no_timestamps = true; wp.translate = false;
|
|
||||||
wp.language = m_cfg.language.c_str();
|
|
||||||
wp.n_threads = m_cfg.n_threads;
|
|
||||||
wp.no_context = true; wp.suppress_blank = true; wp.suppress_nst = true; wp.temperature = 0.0f;
|
|
||||||
wp.progress_callback = &Transcriber::s_progress; // <- live progress
|
|
||||||
wp.progress_callback_user_data = this;
|
|
||||||
wp.abort_callback = &Transcriber::s_abort; // <- optional cancel
|
|
||||||
wp.abort_callback_user_data = this;
|
|
||||||
|
|
||||||
std::string out;
|
|
||||||
if (whisper_full(m_ctx, wp, audio.data(), (int)audio.size()) == 0) {
|
|
||||||
int n = whisper_full_n_segments(m_ctx);
|
|
||||||
for (int i = 0; i < n; ++i) { const char* t = whisper_full_get_segment_text(m_ctx, i); if (t) out += t; }
|
|
||||||
out = clean_text(out);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
> If your `whisper.h` predates `abort_callback`, drop those two lines — `progress_callback` has been in whisper.cpp far longer and is what matters here.
|
|
||||||
|
|
||||||
### B2.2 main.cpp — progress state + ETA
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define WM_APP_PROGRESS (WM_USER + 6)
|
|
||||||
std::atomic<int> g_progress{0};
|
|
||||||
DWORD g_busyStart = 0;
|
|
||||||
|
|
||||||
// at startup, next to set_result_callback:
|
|
||||||
g_tx.set_progress_callback([](int p){ PostMessage(hMainWnd, WM_APP_PROGRESS, (WPARAM)p, 0); });
|
|
||||||
```
|
|
||||||
|
|
||||||
Start the clock when transcription begins (HK_TOGGLE stop branch):
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
} else { // was recording -> stop
|
|
||||||
g_busyStart = GetTickCount();
|
|
||||||
g_progress = 0;
|
|
||||||
g_tx.stop_and_transcribe();
|
|
||||||
SetStatus(hWnd, L"Transcribing…");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Receive progress and repaint the bar:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
case WM_APP_PROGRESS:
|
|
||||||
g_progress = (int)wParam;
|
|
||||||
InvalidateRect(hWnd, &g_vuRect, FALSE);
|
|
||||||
return 0;
|
|
||||||
```
|
|
||||||
|
|
||||||
ETA text (replace the `is_busy()` branch in `UpdateStatus`):
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
} else if (g_tx.is_busy()) {
|
|
||||||
int p = g_progress.load();
|
|
||||||
float total = g_tx.audio_seconds();
|
|
||||||
float elapsed = (GetTickCount() - g_busyStart) / 1000.0f;
|
|
||||||
int mm = (int)total / 60, ss = (int)total % 60;
|
|
||||||
if (p >= 3) {
|
|
||||||
float est = elapsed * 100.0f / p; // projected total
|
|
||||||
float remain = est - elapsed; if (remain < 0) remain = 0;
|
|
||||||
swprintf_s(buf, L"Transcribing %d:%02d • %d%% • ~%ds left", mm, ss, p, (int)(remain + 0.5f));
|
|
||||||
} else {
|
|
||||||
swprintf_s(buf, L"Transcribing %d:%02d of audio…", mm, ss);
|
|
||||||
}
|
|
||||||
SetStatus(hwnd, buf);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### B2.3 Reuse the VU strip as a determinate progress bar
|
|
||||||
|
|
||||||
While recording the strip shows the VU; while transcribing it shows progress. Add a renderer and branch in `WM_PAINT`:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
void DrawProgress(Graphics& g, const RECT& r, float frac) {
|
|
||||||
Rect track(r.left, r.top, r.right - r.left, r.bottom - r.top);
|
|
||||||
FillRound(g, C_SURFACEHI, track, 4);
|
|
||||||
frac = frac < 0 ? 0 : (frac > 1 ? 1 : frac);
|
|
||||||
int w = (int)((r.right - r.left) * frac);
|
|
||||||
if (w > 0) { Rect fill(r.left, r.top, w, r.bottom - r.top); FillRound(g, C_ACCENT, fill, 4); }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
```cpp
|
|
||||||
// in WM_PAINT, where you currently call DrawVU:
|
|
||||||
if (g_tx.is_busy()) DrawProgress(g, g_vuRect, g_progress.load() / 100.0f);
|
|
||||||
else DrawVU(g, g_vuRect, g_energy);
|
|
||||||
```
|
|
||||||
|
|
||||||
Keep it ticking between callbacks so the ETA counts down smoothly — in `WM_TIMER`, add:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
else if (g_tx.is_busy()) {
|
|
||||||
InvalidateRect(hWnd, &g_vuRect, FALSE); // (UpdateStatus already runs each tick below)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
That's it: a moving bar, a percentage, and a shrinking "~Ns left" — the user can see it's alive and roughly how long is left. The estimate self-corrects as real progress arrives (the first few percent are rougher; it tightens quickly).
|
|
||||||
|
|
||||||
### B2.4 (Optional) Cancel a long transcription
|
|
||||||
|
|
||||||
You added `request_cancel()` + the abort callback in B2.1. Hook it so that pressing the button **while busy** aborts instead of being ignored, and treat the empty result as "Cancelled":
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
// top of the HK_TOGGLE handler:
|
|
||||||
if (g_tx.is_busy()) { g_tx.request_cancel(); SetStatus(hWnd, L"Cancelling…"); break; }
|
|
||||||
```
|
|
||||||
`whisper_full` returns promptly with no/aborted segments → your existing `WM_APP_RESULT` empty-string path shows "No speech detected"; change that label to "Cancelled" when a cancel was requested if you want to distinguish them.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## B3. Build & test
|
|
||||||
|
|
||||||
- **New link deps:** `uxtheme.lib` (added via `#pragma comment` in B1.1). GDI+ is already linked.
|
|
||||||
- **New files:** none required for B2; B1.2 adds the popup window proc inside `main.cpp` (no new translation unit).
|
|
||||||
- **Rebuild:** `cmake --build build --config Release` as usual.
|
|
||||||
|
|
||||||
**Verify:**
|
|
||||||
- [ ] No hairline around *Pinned*; no left/top lines on Copy/Paste/Clear; focus no longer draws a dotted rect.
|
|
||||||
- [ ] Mic + model selectors show a single (your) chevron, open a dark rounded popup, and selecting reloads the model / switches device.
|
|
||||||
- [ ] Record a ~1–2 min clip → the strip fills as a progress bar, the status shows `%` and a shrinking `~Ns left`, and it completes (no static "Transcribing…").
|
|
||||||
- [ ] (If added) pressing the button mid-transcription cancels promptly.
|
|
||||||
|
|
||||||
**Headless regression (extends `tests/test_core.cpp` from `FINDINGS-FIXES-TESTS.md`):**
|
|
||||||
- Set a progress callback that records the max value seen; assert it reaches ~100 for `samples/jfk.wav`, and that callbacks arrive in non-decreasing order. This locks in that progress reporting keeps working across whisper.cpp upgrades.
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
int last = -1, maxp = 0; bool monotonic = true;
|
|
||||||
t.set_progress_callback([&](int p){ if (p < last) monotonic = false; last = p; if (p > maxp) maxp = p; });
|
|
||||||
t.transcribe_sync(audio);
|
|
||||||
CHECK(monotonic, "progress is non-decreasing");
|
|
||||||
CHECK(maxp >= 95, "progress reaches ~100%");
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*Apply order: B1.1 (5 min, instant visual win) → B2 (progress, the big UX gain) → B1.2 (custom dropdowns) → optional B2.4 cancel. Each is independent and safe to ship on its own.*
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
# Win Dictation - AI Voice to Text for Windows
|
# Win Dictation — Voice to Text for Windows
|
||||||
|
|
||||||
A push-to-talk speech-to-text utility for Windows using OpenAI's Whisper model. Record, transcribe, and paste with a single hotkey.
|
A push-to-talk speech-to-text utility for Windows. Press a hotkey, speak, and your words land in whatever app you were just using — fully offline, powered by Whisper.
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Quick Download
|
## Quick Download
|
||||||
|
|
||||||
@@ -12,12 +10,18 @@ Extract the ZIP file and run `win-dictation.exe`. The release includes all requi
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
- **[User Manual](win-dictation-user-manual.html)** — How to use every feature
|
||||||
|
- **[Architecture & Engineering Review](win-dictation-architecture-engineering-review.html)** — Deep dive into the codebase for developers
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
### Performance
|
### Performance
|
||||||
- **Physical-core threading**: Uses one thread per physical core for efficient batch transcription
|
- **Physical-core threading**: Uses one thread per physical core for efficient batch transcription
|
||||||
- **CPU-only**: Optimised for the target Intel i5-7th-gen 2-core/4-thread machine
|
- **CPU-only**: Optimised for ordinary laptops — no GPU required
|
||||||
- **Smart model selection**: Auto-selects tiny.en for CPU-only, base.en when GPU is present
|
|
||||||
- **Self-calibrating progress**: Learns transcription speed per model and machine, delivering a smooth countdown
|
- **Self-calibrating progress**: Learns transcription speed per model and machine, delivering a smooth countdown
|
||||||
|
|
||||||
### User Interface
|
### User Interface
|
||||||
@@ -28,23 +32,25 @@ Extract the ZIP file and run `win-dictation.exe`. The release includes all requi
|
|||||||
|
|
||||||
### Audio Processing
|
### Audio Processing
|
||||||
- **Push-to-talk**: Press Ctrl+Shift+Space, speak, press again to transcribe
|
- **Push-to-talk**: Press Ctrl+Shift+Space, speak, press again to transcribe
|
||||||
- **500ms auto-end**: Stops recording after 500ms of silence
|
|
||||||
- **Multiple microphones**: Select from all available input devices
|
- **Multiple microphones**: Select from all available input devices
|
||||||
- **16 kHz sample rate**: Optimised for Whisper
|
- **16 kHz sample rate**: Optimised for Whisper
|
||||||
|
- **Silence trimming**: Leading and trailing silence is trimmed before transcription
|
||||||
|
|
||||||
## Usage
|
## Quick Start
|
||||||
|
|
||||||
|
1. Launch `win-dictation.exe`
|
||||||
|
2. Click into wherever you want text, then press `Ctrl+Shift+Space`
|
||||||
|
3. Speak, then press `Ctrl+Shift+Space` again
|
||||||
|
4. Your words appear in the app you were using
|
||||||
|
|
||||||
|
Full instructions in the [User Manual](win-dictation-user-manual.html).
|
||||||
|
|
||||||
### Controls
|
### Controls
|
||||||
- **Record**: Click the Record pill or press `Ctrl+Shift+Space`
|
- **Record/Stop**: Click the pill or press `Ctrl+Shift+Space`
|
||||||
|
- **Hide window**: `Ctrl+Shift+H`
|
||||||
- **Pin**: Keep window always-on-top
|
- **Pin**: Keep window always-on-top
|
||||||
- **Copy / Paste / Clear**: Text actions
|
- **Copy / Paste / Clear**: Text actions below the transcript
|
||||||
- **Model / Mic**: Select from popup menus
|
- **Model / Mic / History**: Select from popup menus
|
||||||
- **Hide**: `Ctrl+Shift+H` hides the window
|
|
||||||
|
|
||||||
### Indicators
|
|
||||||
- **Level**: Live audio energy during recording
|
|
||||||
- **Progress bar**: Smooth, counting-down estimate during transcription
|
|
||||||
- **Status**: Thread count at idle, elapsed time during recording
|
|
||||||
|
|
||||||
## Building from Source
|
## Building from Source
|
||||||
|
|
||||||
@@ -52,13 +58,13 @@ Extract the ZIP file and run `win-dictation.exe`. The release includes all requi
|
|||||||
|
|
||||||
- **Windows 10/11**
|
- **Windows 10/11**
|
||||||
- **CMake** 3.5+
|
- **CMake** 3.5+
|
||||||
- **Visual Studio 2022/2026** with C++ workload
|
- **Visual Studio 2022** with C++ workload
|
||||||
- **SDL2** (included in deps/)
|
- **SDL2** (included in deps/)
|
||||||
|
|
||||||
### Build Steps
|
### Build Steps
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
cmake -S . -B build -G "Visual Studio 18 2026" \
|
cmake -S . -B build -G "Visual Studio 17 2022" ^
|
||||||
-DSDL2_DIR="deps/SDL2-2.28.5/cmake"
|
-DSDL2_DIR="deps/SDL2-2.28.5/cmake"
|
||||||
cmake --build build --config Release
|
cmake --build build --config Release
|
||||||
```
|
```
|
||||||
@@ -73,34 +79,43 @@ The executable will be at `build\bin\Release\win-dictation.exe`.
|
|||||||
Hotkey → SDL Capture → Stop → Batch whisper_full → Text → Auto-paste
|
Hotkey → SDL Capture → Stop → Batch whisper_full → Text → Auto-paste
|
||||||
```
|
```
|
||||||
|
|
||||||
1. **SDL audio capture**: 16kHz mono recording into memory
|
1. **SDL audio capture**: 16 kHz mono recording into memory. CPU stays near idle while recording.
|
||||||
2. **Stop-and-transcribe**: Press stop or hit max length (600s), then one `whisper_full` call
|
2. **Stop-and-transcribe**: One `whisper_full` call processes the full clip at once.
|
||||||
3. **Progress estimation**: Linear model fitted per machine/model, fused with whisper's chunk progress
|
3. **Progress estimation**: Decayed online least-squares model per machine/model, fused with whisper's chunk progress into a strictly monotonic countdown.
|
||||||
4. **Text output**: Appended to transcript, copied to clipboard, optionally auto-pasted
|
4. **Text output**: Inserted at cursor with smart spacing, copied to clipboard, and optionally auto-pasted into the window you came from.
|
||||||
|
|
||||||
### Model
|
### Models
|
||||||
|
|
||||||
Place `.bin` files in `models/` next to the executable. The app auto-detects available models:
|
Place `.bin` files in `models/` next to the executable, or download them from the Settings screen in-app:
|
||||||
|
|
||||||
| Model | Size | Params | Best for |
|
| Model | Size | Best for |
|
||||||
|-------|------|--------|----------|
|
|-------|------|----------|
|
||||||
| tiny.en | 75 MB | 39M | CPU-only systems |
|
| tiny.en | ~75 MB | Fastest — everyday dictation |
|
||||||
| base.en | 140 MB | 74M | GPU-accelerated systems |
|
| tiny.en-q8_0 | ~42 MB | Same speed, smaller file |
|
||||||
|
| base.en-q5_1 | ~59 MB | Good accuracy bump for little cost |
|
||||||
|
| base.en | ~142 MB | More accurate; still reasonable on two cores |
|
||||||
|
| small.en-q5_1 | ~182 MB | Accurate, but slower |
|
||||||
|
| small.en | ~466 MB | Most accurate — and slowest |
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
win-dictation/
|
win-dictation/
|
||||||
├── src/ # Application source
|
├── src/ # Application source
|
||||||
│ ├── main.cpp # UI and message handling
|
│ ├── main.cpp # Window, painting, interaction, settings, clipboard, popups
|
||||||
│ ├── transcriber.* # Recording and transcription
|
│ ├── transcriber.* # SDL capture, Whisper preload/inference, progress callbacks
|
||||||
│ ├── timing.h # Progress estimation engine
|
│ ├── timing.h # Learned timing model + live progress estimator
|
||||||
|
│ ├── history.h # Session text files, index, pruning
|
||||||
|
│ ├── downloader.h # WinHTTP model downloader (background thread)
|
||||||
|
│ ├── stats.h # Lifetime usage totals + derived figures
|
||||||
│ ├── settings.h # INI persistence
|
│ ├── settings.h # INI persistence
|
||||||
│ ├── text_util.h # Transcript helpers
|
│ ├── text_util.h # Transcript concatenation helpers
|
||||||
│ └── logging.h # Log utilities
|
│ ├── logging.h # Timestamped file log
|
||||||
|
│ └── tests/ # Unit tests (test-core.exe)
|
||||||
├── whisper/ # Whisper.cpp library
|
├── whisper/ # Whisper.cpp library
|
||||||
├── ggml/ # GGML tensor library
|
├── ggml/ # GGML tensor library
|
||||||
├── models/ # Whisper model files
|
├── models/ # Whisper model files
|
||||||
|
├── history/ # Saved dictation sessions
|
||||||
├── release/ # Pre-built package
|
├── release/ # Pre-built package
|
||||||
└── CMakeLists.txt # Build configuration
|
└── CMakeLists.txt # Build configuration
|
||||||
```
|
```
|
||||||
@@ -111,5 +126,7 @@ MIT — follows [whisper.cpp](https://github.com/ggerganov/whisper.cpp).
|
|||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
|
- [User Manual](win-dictation-user-manual.html)
|
||||||
|
- [Architecture & Engineering Review](win-dictation-architecture-engineering-review.html)
|
||||||
- [Whisper.cpp](https://github.com/ggerganov/whisper.cpp)
|
- [Whisper.cpp](https://github.com/ggerganov/whisper.cpp)
|
||||||
- [Model Download](https://huggingface.co/ggerganov/whisper.cpp)
|
- [Model Downloads](https://huggingface.co/ggerganov/whisper.cpp)
|
||||||
|
|||||||
@@ -0,0 +1,509 @@
|
|||||||
|
# Fix 03 — History drop-down: draw above everything + dynamic scrolling
|
||||||
|
|
||||||
|
**Files touched:** `src/main.cpp` only. No changes to `history.h`, `CMakeLists.txt`, or any other file.
|
||||||
|
**Estimated effort:** 1–2 hours including testing.
|
||||||
|
**Convention reminder:** this is a companion fix note (Fix-01, Fix-02, …) — do not edit older docs.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Why the drop-down draws *behind* the transcript box (read this first)
|
||||||
|
|
||||||
|
The history drop-down is currently **painted onto the main window's surface** inside
|
||||||
|
`PaintSurface()` (the block that starts `if (g_histOpen >= 0 && g_view == View::Main)`).
|
||||||
|
|
||||||
|
The transcript box, however, is **not** part of that painted surface. It is a real Win32
|
||||||
|
child window — the `EDIT` control with ID `ID_EDIT_TEXT`. Two Win32 rules make the current
|
||||||
|
approach impossible to fix by re-ordering paint calls:
|
||||||
|
|
||||||
|
1. **Child windows always render above the parent's client-area painting.** Whatever the
|
||||||
|
parent draws in its own `WM_PAINT` sits *underneath* every child HWND. There is no
|
||||||
|
"draw later so it ends up on top" — the EDIT is simply not on our canvas.
|
||||||
|
2. The main window is created with **`WS_CLIPCHILDREN`** (see `CreateWindowExW` in
|
||||||
|
`wWinMain`). That flag explicitly removes the EDIT's rectangle from the region the
|
||||||
|
parent is even allowed to paint into. Our GDI+ drawing inside the EDIT's rect is
|
||||||
|
silently clipped away. That is exactly why you only see the strip of drop-down in the
|
||||||
|
gap *below* the EDIT in the screenshot.
|
||||||
|
|
||||||
|
A surface-painted drop-down also can never extend past the app window's edge, and we are
|
||||||
|
re-implementing hover/scroll/click routing by hand. All three problems go away with the
|
||||||
|
same fix.
|
||||||
|
|
||||||
|
## 2. The fix — strategy
|
||||||
|
|
||||||
|
**Stop painting the drop-down on the surface. Use a real top-level popup window instead.**
|
||||||
|
|
||||||
|
The app already contains exactly the right mechanism and we reuse it:
|
||||||
|
|
||||||
|
- The **microphone selector** already opens a small floating window of class `DictPopup`
|
||||||
|
(`PopupProc` + `ShowSelectPopup` in `main.cpp`). It is created with
|
||||||
|
`WS_POPUP | WS_EX_TOPMOST | WS_EX_TOOLWINDOW`, i.e. a top-level window that floats
|
||||||
|
above the app, above the EDIT control, above *everything*, and is not clipped by the
|
||||||
|
app window's edges at all.
|
||||||
|
- The selection plumbing for history **already exists**: in `WndProc`, the
|
||||||
|
`WM_APP_SELECT` handler already has an `ID_SEL_HISTORY` branch that archives the
|
||||||
|
current text and loads the chosen entry. It was wired up but never used. We will not
|
||||||
|
touch it — we just finally route clicks into it.
|
||||||
|
|
||||||
|
So the work is:
|
||||||
|
|
||||||
|
1. Upgrade the shared popup so it can **scroll** (max ~8 visible rows, mouse wheel,
|
||||||
|
scrollbar thumb), positions itself **above or below** the anchor depending on screen
|
||||||
|
space, and uses **DPI-scaled** row heights.
|
||||||
|
2. Point the **History button** at `ShowSelectPopup(...)` with `ID_SEL_HISTORY`.
|
||||||
|
3. **Delete** every line of the old surface-painted drop-down.
|
||||||
|
|
||||||
|
Bonus: the mic selector automatically gains scrolling and screen-edge handling too.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Step 1 — Replace `PopupState`
|
||||||
|
|
||||||
|
In `src/main.cpp`, find this (one line plus the variable under it):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
struct PopupState { std::vector<std::wstring> items; int sel; int hot; HWND owner; int ctrlId; };
|
||||||
|
static PopupState g_pop;
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace it with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
struct PopupState {
|
||||||
|
std::vector<std::wstring> items;
|
||||||
|
int sel = -1; // index drawn in accent colour (current selection), -1 = none
|
||||||
|
int hot = -1; // ABSOLUTE index of the row under the mouse, -1 = none
|
||||||
|
HWND owner = nullptr;
|
||||||
|
int ctrlId = 0; // posted back in WM_APP_SELECT wParam
|
||||||
|
int scroll = 0; // index of the first visible row
|
||||||
|
int visRows = 0; // number of rows visible in the popup
|
||||||
|
int rowH = 30; // row height in px (DPI-scaled at open time)
|
||||||
|
int pad = 3; // inner padding in px
|
||||||
|
int wheelAccum = 0; // accumulates wheel deltas < 120 (trackpads)
|
||||||
|
};
|
||||||
|
static PopupState g_pop;
|
||||||
|
|
||||||
|
static const int kPopupMaxVisible = 8; // rows shown before the list scrolls
|
||||||
|
```
|
||||||
|
|
||||||
|
> Note `hot` and the value posted back are now **absolute** item indices (index into the
|
||||||
|
> full list), not visible-row indices. This matters once the list scrolls.
|
||||||
|
|
||||||
|
## 4. Step 2 — Replace `PopupProc` (and add one helper above it)
|
||||||
|
|
||||||
|
Find the existing `LRESULT CALLBACK PopupProc(HWND h, UINT m, WPARAM w, LPARAM l)` and
|
||||||
|
replace the **entire function** with the code below. Also add the small
|
||||||
|
`PopupRowFromY` helper **immediately above** `PopupProc` (it must be defined before it).
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// Convert a client-area Y coordinate inside the popup to an ABSOLUTE item index.
|
||||||
|
// Returns -1 if the point is not on a row.
|
||||||
|
static int PopupRowFromY(int y) {
|
||||||
|
int row = (y - g_pop.pad) / g_pop.rowH; // visible row 0..visRows-1
|
||||||
|
if (row < 0 || row >= g_pop.visRows) return -1;
|
||||||
|
int abs = g_pop.scroll + row; // absolute item index
|
||||||
|
if (abs >= (int)g_pop.items.size()) return -1;
|
||||||
|
return abs;
|
||||||
|
}
|
||||||
|
|
||||||
|
LRESULT CALLBACK PopupProc(HWND h, UINT m, WPARAM w, LPARAM l) {
|
||||||
|
switch (m) {
|
||||||
|
case WM_MOUSEMOVE: {
|
||||||
|
int row = PopupRowFromY(GET_Y_LPARAM(l));
|
||||||
|
if (row != g_pop.hot) { g_pop.hot = row; InvalidateRect(h, nullptr, FALSE); }
|
||||||
|
TRACKMOUSEEVENT t{ sizeof(t), TME_LEAVE, h, 0 }; TrackMouseEvent(&t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case WM_MOUSELEAVE:
|
||||||
|
g_pop.hot = -1; InvalidateRect(h, nullptr, FALSE);
|
||||||
|
return 0;
|
||||||
|
case WM_MOUSEWHEEL: {
|
||||||
|
int maxScroll = (int)g_pop.items.size() - g_pop.visRows;
|
||||||
|
if (maxScroll <= 0) return 0; // everything fits: nothing to scroll
|
||||||
|
g_pop.wheelAccum += GET_WHEEL_DELTA_WPARAM(w);
|
||||||
|
int steps = g_pop.wheelAccum / WHEEL_DELTA; // whole notches only
|
||||||
|
if (steps != 0) {
|
||||||
|
g_pop.wheelAccum -= steps * WHEEL_DELTA;
|
||||||
|
g_pop.scroll -= steps * 3; // 3 rows per wheel notch
|
||||||
|
g_pop.scroll = std::max(0, std::min(g_pop.scroll, maxScroll));
|
||||||
|
POINT pt; GetCursorPos(&pt); ScreenToClient(h, &pt);
|
||||||
|
g_pop.hot = PopupRowFromY(pt.y); // keep hover correct after scroll
|
||||||
|
InvalidateRect(h, nullptr, FALSE);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case WM_KEYDOWN:
|
||||||
|
if (w == VK_ESCAPE) DestroyWindow(h); // Esc closes the popup
|
||||||
|
return 0;
|
||||||
|
case WM_LBUTTONUP: {
|
||||||
|
int row = PopupRowFromY(GET_Y_LPARAM(l));
|
||||||
|
if (row >= 0)
|
||||||
|
PostMessageW(g_pop.owner, WM_APP_SELECT, (WPARAM)g_pop.ctrlId, (LPARAM)row);
|
||||||
|
DestroyWindow(h);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case WM_ACTIVATE:
|
||||||
|
if (LOWORD(w) == WA_INACTIVE) DestroyWindow(h); // click-away closes
|
||||||
|
return 0;
|
||||||
|
case WM_ERASEBKGND: return 1;
|
||||||
|
case WM_PAINT: {
|
||||||
|
PAINTSTRUCT ps; HDC hdc = BeginPaint(h, &ps);
|
||||||
|
RECT rc; GetClientRect(h, &rc);
|
||||||
|
HDC mem = CreateCompatibleDC(hdc);
|
||||||
|
HBITMAP bmp = CreateCompatibleBitmap(hdc, rc.right, rc.bottom);
|
||||||
|
HBITMAP old = (HBITMAP)SelectObject(mem, bmp);
|
||||||
|
{
|
||||||
|
Graphics g(mem);
|
||||||
|
g.SetSmoothingMode(SmoothingModeAntiAlias);
|
||||||
|
g.SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
|
||||||
|
Rect all(0, 0, rc.right, rc.bottom);
|
||||||
|
FillRound(g, T_CARD, all, 10);
|
||||||
|
StrokeRound(g, T_FAINT, all, 10, 1.0f);
|
||||||
|
|
||||||
|
int n = (int)g_pop.items.size();
|
||||||
|
bool hasBar = n > g_pop.visRows;
|
||||||
|
int barW = std::max(3, (int)(4 * g_dpiScale));
|
||||||
|
int rowW = rc.right - 2 * g_pop.pad - (hasBar ? barW + g_pop.pad : 0);
|
||||||
|
int last = std::min(n, g_pop.scroll + g_pop.visRows);
|
||||||
|
|
||||||
|
for (int i = g_pop.scroll; i < last; ++i) {
|
||||||
|
int vis = i - g_pop.scroll;
|
||||||
|
Rect row(g_pop.pad, g_pop.pad + vis * g_pop.rowH, rowW, g_pop.rowH - 2);
|
||||||
|
if (i == g_pop.hot) FillRound(g, T_CARD_HI, row, 7);
|
||||||
|
RectF tb((REAL)row.X + 9, (REAL)row.Y, (REAL)row.Width - 12, (REAL)row.Height);
|
||||||
|
DrawTextC(g, g_pop.items[i].c_str(), *g_gpUI,
|
||||||
|
(i == g_pop.sel) ? T_ACCENT : T_TEXT,
|
||||||
|
tb, StringAlignmentNear, StringAlignmentCenter);
|
||||||
|
}
|
||||||
|
if (hasBar) {
|
||||||
|
int trackH = rc.bottom - 2 * g_pop.pad;
|
||||||
|
int thumbH = std::max((int)(20 * g_dpiScale), trackH * g_pop.visRows / n);
|
||||||
|
int maxScroll = n - g_pop.visRows;
|
||||||
|
int thumbY = g_pop.pad + (trackH - thumbH) * g_pop.scroll / maxScroll;
|
||||||
|
Rect thumb(rc.right - g_pop.pad - barW, thumbY, barW, thumbH);
|
||||||
|
FillRound(g, T_DIM, thumb, barW / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BitBlt(hdc, 0, 0, rc.right, rc.bottom, mem, 0, 0, SRCCOPY);
|
||||||
|
SelectObject(mem, old); DeleteObject(bmp); DeleteDC(mem);
|
||||||
|
EndPaint(h, &ps);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DefWindowProc(h, m, w, l);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Two deliberate changes from the old version, so you don't think something was lost:
|
||||||
|
|
||||||
|
- The old paint code built a `Font f(mem, g_fUI)` every frame. We now use the cached
|
||||||
|
`*g_gpUI` GDI+ font — same convention as Fix-02 (cached `g_gp*` fonts everywhere).
|
||||||
|
- The mouse-wheel handler works because the popup has keyboard focus
|
||||||
|
(`SetFocus(p)` is called when it opens) — Windows delivers `WM_MOUSEWHEEL` to the
|
||||||
|
focused window. Don't remove the `SetFocus` call in Step 3.
|
||||||
|
|
||||||
|
## 5. Step 3 — Replace `ShowSelectPopup`
|
||||||
|
|
||||||
|
Replace the **entire** existing `ShowSelectPopup` function with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
void ShowSelectPopup(HWND owner, int ctrlId, const std::vector<std::wstring>& items, int sel, const RectF& anchor) {
|
||||||
|
static bool reg = false;
|
||||||
|
if (!reg) {
|
||||||
|
WNDCLASSEXW wc{ sizeof(wc) };
|
||||||
|
wc.lpfnWndProc = PopupProc;
|
||||||
|
wc.hInstance = hInst;
|
||||||
|
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||||
|
wc.hbrBackground = CreateSolidBrush(CR_SURFACE);
|
||||||
|
wc.lpszClassName = L"DictPopup";
|
||||||
|
RegisterClassExW(&wc);
|
||||||
|
reg = true;
|
||||||
|
}
|
||||||
|
if (items.empty()) return;
|
||||||
|
|
||||||
|
float s = g_dpiScale;
|
||||||
|
int rowH = (int)(30 * s);
|
||||||
|
int pad = (int)(3 * s); if (pad < 3) pad = 3;
|
||||||
|
int n = (int)items.size();
|
||||||
|
int visRows = std::min(n, kPopupMaxVisible);
|
||||||
|
|
||||||
|
g_pop = PopupState{}; // reset everything (incl. scroll/wheelAccum)
|
||||||
|
g_pop.items = items;
|
||||||
|
g_pop.sel = sel;
|
||||||
|
g_pop.owner = owner;
|
||||||
|
g_pop.ctrlId = ctrlId;
|
||||||
|
g_pop.visRows = visRows;
|
||||||
|
g_pop.rowH = rowH;
|
||||||
|
g_pop.pad = pad;
|
||||||
|
if (sel >= 0 && n > visRows) // scroll so the current selection is visible
|
||||||
|
g_pop.scroll = std::max(0, std::min(sel - visRows / 2, n - visRows));
|
||||||
|
|
||||||
|
int h = visRows * rowH + 2 * pad;
|
||||||
|
int wdt = std::max((int)anchor.Width, (int)(260 * s)); // never narrower than 260px
|
||||||
|
|
||||||
|
// Anchor rect is in CLIENT coordinates; convert its top-left to screen.
|
||||||
|
POINT tl{ (LONG)anchor.X, (LONG)anchor.Y };
|
||||||
|
ClientToScreen(owner, &tl);
|
||||||
|
int anchorTop = tl.y;
|
||||||
|
int anchorBottom = tl.y + (int)anchor.Height;
|
||||||
|
int x = tl.x;
|
||||||
|
|
||||||
|
// Place below the anchor if it fits on the monitor's work area, otherwise above.
|
||||||
|
HMONITOR mon = MonitorFromWindow(owner, MONITOR_DEFAULTTONEAREST);
|
||||||
|
MONITORINFO mi{ sizeof(mi) };
|
||||||
|
GetMonitorInfo(mon, &mi);
|
||||||
|
int y;
|
||||||
|
if (anchorBottom + 2 + h <= mi.rcWork.bottom) y = anchorBottom + 2; // open downward
|
||||||
|
else y = anchorTop - h - 2; // flip upward
|
||||||
|
if (y < mi.rcWork.top) y = mi.rcWork.top;
|
||||||
|
if (x + wdt > mi.rcWork.right) x = mi.rcWork.right - wdt;
|
||||||
|
if (x < mi.rcWork.left) x = mi.rcWork.left;
|
||||||
|
|
||||||
|
HWND p = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, L"DictPopup", L"",
|
||||||
|
WS_POPUP, x, y, wdt, h, owner, nullptr, hInst, nullptr);
|
||||||
|
if (!p) return;
|
||||||
|
|
||||||
|
int corner = DWMWCP_ROUND;
|
||||||
|
DwmSetWindowAttribute(p, DWMWA_WINDOW_CORNER_PREFERENCE, &corner, sizeof(corner));
|
||||||
|
ShowWindow(p, SW_SHOWNA);
|
||||||
|
SetFocus(p); // required: wheel + Esc are delivered to the focused window
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
- The old debug `MessageBoxW("Popup failed: ...")` is intentionally removed (it was
|
||||||
|
scaffolding). Failure now just silently returns.
|
||||||
|
- Because the popup is a top-level window, it may legitimately extend **past the app
|
||||||
|
window's edges** — that is correct and expected. It only clamps to the *monitor's*
|
||||||
|
work area.
|
||||||
|
- It positions below the button when there is monitor space, otherwise flips above —
|
||||||
|
standard combo-box behaviour. Since the History button sits near the bottom of the
|
||||||
|
app window, it will usually still have screen room below and will open downward,
|
||||||
|
floating *over* whatever is beneath. If you want it to **always open upward** like
|
||||||
|
the current build, replace the placement `if/else` with just:
|
||||||
|
`int y = anchorTop - h - 2; if (y < mi.rcWork.top) y = mi.rcWork.top;`
|
||||||
|
|
||||||
|
## 6. Step 4 — Rewire the History button
|
||||||
|
|
||||||
|
In `OnClick(HWND hWnd, WK kind)`, find the `case WK::History:` block:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case WK::History: {
|
||||||
|
if (g_histOpen >= 0) { g_histOpen = -1; InvalidateRect(hWnd, nullptr, FALSE); break; }
|
||||||
|
if (g_history.empty()) { SetStatus(hWnd, L"No history yet"); break; }
|
||||||
|
g_histOpen = (int)g_history.size();
|
||||||
|
g_histScroll = 0; g_histHot = -1;
|
||||||
|
InvalidateRect(hWnd, nullptr, FALSE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace it with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case WK::History: {
|
||||||
|
g_history = LoadHistoryIndex(); // refresh in case files changed
|
||||||
|
if (g_history.empty()) { SetStatus(hWnd, L"No history yet"); break; }
|
||||||
|
std::vector<std::wstring> labels;
|
||||||
|
labels.reserve(g_history.size());
|
||||||
|
for (const auto& e : g_history) labels.push_back(e.label);
|
||||||
|
ShowSelectPopup(hWnd, ID_SEL_HISTORY, labels, -1, g_w[(int)WK::History].r);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Do not write any new selection-handling code.** When the user clicks a row, the popup
|
||||||
|
posts `WM_APP_SELECT` with `wParam = ID_SEL_HISTORY` and `lParam = absolute index`. The
|
||||||
|
existing `else if (ctrlId == ID_SEL_HISTORY ...)` branch inside `WndProc`'s
|
||||||
|
`WM_APP_SELECT` handler already does everything (archive current text, load the entry,
|
||||||
|
set `g_lastLoadedText`, refresh the index, update the placeholder, show "Loaded from
|
||||||
|
history"). Leave it exactly as it is.
|
||||||
|
|
||||||
|
## 7. Step 5 — Delete the legacy painted drop-down (6 deletions)
|
||||||
|
|
||||||
|
All in `src/main.cpp`. Delete **only** what is quoted — the surrounding code stays.
|
||||||
|
|
||||||
|
**5a — globals.** Between `int g_setHot = -1;` and `Downloader g_dl;`, delete these three lines:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
int g_histOpen = -1;
|
||||||
|
int g_histScroll = 0;
|
||||||
|
int g_histHot = -1;
|
||||||
|
```
|
||||||
|
|
||||||
|
(Keep `g_setHot`, keep `std::vector<HistoryEntry> g_history;`, keep `g_lastLoadedText`.)
|
||||||
|
|
||||||
|
**5b — the paint block in `PaintSurface`.** Delete this whole block (it sits right
|
||||||
|
before `RECT vr = g_vuRect;`):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
if (g_histOpen >= 0 && g_view == View::Main) {
|
||||||
|
RectF& anchor = g_w[(int)WK::History].r;
|
||||||
|
...
|
||||||
|
if (g_histOpen > maxVis) {
|
||||||
|
...
|
||||||
|
FillRound(g, T_DIM, thumb, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
(~30 lines, from `if (g_histOpen >= 0 ...` down to the matching closing brace.)
|
||||||
|
|
||||||
|
**5c — the hit-test function.** Delete the entire `HistDropHitTest` function (it sits
|
||||||
|
just above `int HitTest(POINT p)`):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
static int HistDropHitTest(POINT p) {
|
||||||
|
...
|
||||||
|
return realIdx;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**5d — in `WM_MOUSEMOVE`.** Keep the `POINT p{...};` line (it is used by `HitTest(p)`
|
||||||
|
below); delete only this block:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
if (g_histOpen > 0) {
|
||||||
|
int dh = HistDropHitTest(p);
|
||||||
|
if (dh != g_histHot) { g_histHot = dh; InvalidateRect(hWnd, nullptr, FALSE); }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**5e — in `WM_MOUSELEAVE`.** Delete this line:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
if (g_histHot >= 0) { g_histHot = -1; InvalidateRect(hWnd, nullptr, FALSE); }
|
||||||
|
```
|
||||||
|
|
||||||
|
**5f — in `WM_LBUTTONDOWN`.** Delete this block (keep `g_active = g_hot;` and below):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
if (g_histOpen > 0) {
|
||||||
|
POINT p{ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
|
||||||
|
if (HistDropHitTest(p) < 0) { g_histOpen = -1; g_histHot = -1; g_active = -1; InvalidateRect(hWnd, nullptr, FALSE); return 0; }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**5g — in `WM_LBUTTONUP`.** Delete this entire block (the popup + `WM_APP_SELECT`
|
||||||
|
path replaces it; keep the settings branch above it and `ReleaseCapture()` below it):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
if (g_histOpen > 0) {
|
||||||
|
POINT p{ GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
|
||||||
|
int dh = HistDropHitTest(p);
|
||||||
|
if (dh >= 0 && dh < (int)g_history.size()) {
|
||||||
|
std::wstring cur = GetEditText(hWnd);
|
||||||
|
if (!cur.empty() && cur != g_lastLoadedText)
|
||||||
|
ArchiveSession(cur);
|
||||||
|
std::wstring text = ReadFileUtf8(g_history[dh].path);
|
||||||
|
SetWindowTextW(GetDlgItem(hWnd, ID_EDIT_TEXT), text.c_str());
|
||||||
|
g_lastLoadedText = text;
|
||||||
|
g_editDirty = false;
|
||||||
|
g_history = LoadHistoryIndex();
|
||||||
|
UpdatePlaceholder(hWnd);
|
||||||
|
SetStatus(hWnd, L"Loaded from history");
|
||||||
|
}
|
||||||
|
g_histOpen = -1; g_histHot = -1;
|
||||||
|
InvalidateRect(hWnd, nullptr, FALSE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**5h — in `WM_MOUSEWHEEL`.** Delete this block (keep the `View::Settings` scroll block
|
||||||
|
above it):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
if (g_histOpen > 6) {
|
||||||
|
g_histScroll -= GET_WHEEL_DELTA_WPARAM(wParam) / 60;
|
||||||
|
g_histScroll = std::max(0, std::min(g_histScroll, g_histOpen - 6));
|
||||||
|
InvalidateRect(hWnd, nullptr, FALSE);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Verification after Step 5:** Ctrl+F the file for `g_hist` — the only remaining
|
||||||
|
matches must be `g_history` (the vector). Search for `HistDropHitTest` — zero matches.
|
||||||
|
If anything else matches, you missed a deletion and the compiler will tell you too
|
||||||
|
(undeclared identifier `g_histOpen`).
|
||||||
|
|
||||||
|
## 8. Step 6 — (Optional polish) make the button a true toggle
|
||||||
|
|
||||||
|
Known small quirk of popup-based menus: clicking the History button **while the popup is
|
||||||
|
open** first closes it (the click deactivates the popup → `WM_ACTIVATE` destroys it),
|
||||||
|
then the button's click-handler immediately reopens it. So the button acts as
|
||||||
|
"reopen", not "toggle closed". The mic selector has always behaved this way; if nobody
|
||||||
|
has complained, skip this step. To make it a real toggle:
|
||||||
|
|
||||||
|
Add next to `g_pop`:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
static DWORD g_popClosedTick = 0; // when the popup last closed
|
||||||
|
static int g_popClosedId = 0; // which ctrlId it was showing
|
||||||
|
```
|
||||||
|
|
||||||
|
Add a case to `PopupProc`:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case WM_DESTROY:
|
||||||
|
g_popClosedTick = GetTickCount();
|
||||||
|
g_popClosedId = g_pop.ctrlId;
|
||||||
|
return 0;
|
||||||
|
```
|
||||||
|
|
||||||
|
Then make the first line of `case WK::History:` (and optionally `WK::SelAudio`):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
if (g_popClosedId == ID_SEL_HISTORY && GetTickCount() - g_popClosedTick < 250) {
|
||||||
|
g_popClosedId = 0; // this click was the user toggling the popup shut — swallow it
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 9. Build & test checklist
|
||||||
|
|
||||||
|
Build exactly as usual (`cmake --build build --config Release --target win-dictation`).
|
||||||
|
Then verify, in order:
|
||||||
|
|
||||||
|
1. **Core bug:** with 3+ history entries, click History. The list must appear **fully on
|
||||||
|
top of the transcript box** (and on top of the window edge if it extends past it).
|
||||||
|
Nothing hidden behind the EDIT control.
|
||||||
|
2. **Scrolling:** create 10+ entries (record short clips and press Clear between them, or
|
||||||
|
copy-paste extra `.txt` files in the `history\` folder using the same
|
||||||
|
`YYYY-MM-DD_HHMMSS.txt` name format). Open History: max 8 rows visible, scrollbar
|
||||||
|
thumb on the right, mouse wheel scrolls 3 rows per notch, hover highlight stays
|
||||||
|
correct while scrolling.
|
||||||
|
3. **Selection:** click an entry → transcript loads it, status shows "Loaded from
|
||||||
|
history", and the text that was in the box beforehand got archived (check the
|
||||||
|
`history\` folder gained a file).
|
||||||
|
4. **Dismiss:** click anywhere outside → closes. Press Esc → closes. Click an entry →
|
||||||
|
closes.
|
||||||
|
5. **Regression — mic selector:** the Microphone popup must still open and select
|
||||||
|
devices correctly (it shares all this code). It now also scrolls if a machine has
|
||||||
|
9+ capture devices and never clips at the screen edge.
|
||||||
|
6. **Placement:** drag the app window to the very bottom of the screen → popup flips
|
||||||
|
upward. Drag it high up → popup opens downward (or stays upward if you chose the
|
||||||
|
always-up variant).
|
||||||
|
7. **Few items:** with 1–2 entries the popup is exactly that tall, no scrollbar.
|
||||||
|
8. **Empty:** with an empty `history\` folder, clicking History shows "No history yet"
|
||||||
|
and no popup.
|
||||||
|
9. **DPI:** if you can, test at 125%/150% scaling — hover highlight must line up with
|
||||||
|
the cursor (row height is now DPI-scaled; it previously was hard-coded 30px).
|
||||||
|
|
||||||
|
## 10. Tuning knobs (all in one place)
|
||||||
|
|
||||||
|
| What | Where | Default |
|
||||||
|
|---|---|---|
|
||||||
|
| Visible rows before scrolling | `kPopupMaxVisible` | 8 |
|
||||||
|
| Rows per wheel notch | `g_pop.scroll -= steps * 3;` in `PopupProc` | 3 |
|
||||||
|
| Minimum popup width | `std::max((int)anchor.Width, (int)(260 * s))` | 260 px |
|
||||||
|
| Open direction | placement `if/else` in `ShowSelectPopup` | below, flip up if no room |
|
||||||
|
| Row height | `rowH = (int)(30 * s)` | 30 px @ 100% DPI |
|
||||||
|
|
||||||
|
## 11. Do NOT touch
|
||||||
|
|
||||||
|
- `#define ID_SEL_HISTORY 1019` — stays.
|
||||||
|
- The `ID_SEL_HISTORY` branch inside `WM_APP_SELECT` in `WndProc` — stays as-is; it is
|
||||||
|
the selection handler now.
|
||||||
|
- `g_history`, `g_lastLoadedText`, `LoadHistoryIndex()`, `ArchiveSession()`, all of
|
||||||
|
`history.h` — unchanged.
|
||||||
|
- The `WK::History` widget rect / `DrawSelectSurface(g, w, L"History")` painting of the
|
||||||
|
button itself — unchanged; only what happens on click changes.
|
||||||
@@ -0,0 +1,366 @@
|
|||||||
|
# Fix 06 — Delete individual history entries from the popup (✕ on hover)
|
||||||
|
|
||||||
|
**Builds on:** Fix-03/04 (popup) and **Fix-05 (live session archiving) — apply Fix-05 first.**
|
||||||
|
One block below references `g_sessionPath` from Fix-05; it is clearly marked in case you
|
||||||
|
must build without it.
|
||||||
|
**Files touched:** `src/main.cpp` only. `history.h` unchanged.
|
||||||
|
**Estimated effort:** 45–60 minutes including testing.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. What we're building
|
||||||
|
|
||||||
|
- Hovering a row in the **History** popup reveals a small `✕` at the row's right edge.
|
||||||
|
- Clicking the `✕` deletes that entry's file from `history\` and refreshes the list
|
||||||
|
**in place — the popup stays open**, so you can clean out several entries in one go.
|
||||||
|
- Clicking anywhere else on the row still loads the entry (unchanged behaviour).
|
||||||
|
- The `Delete` key also deletes the hovered row (the popup already owns keyboard focus).
|
||||||
|
- The **microphone popup is untouched** — it shares the same code, so the feature is
|
||||||
|
gated by a `canDelete` flag that is only true for `ID_SEL_HISTORY`.
|
||||||
|
|
||||||
|
### Design decisions (so the dev doesn't relitigate them)
|
||||||
|
|
||||||
|
1. **Popup stays open after a delete.** Closing after each delete would make cleaning
|
||||||
|
up 10–50 entries miserable. The list, scrollbar, and popup height all refresh in
|
||||||
|
place; deleting the last entry closes the popup.
|
||||||
|
2. **No confirmation dialog — and this is load-bearing, not laziness.** The popup
|
||||||
|
destroys itself on `WM_ACTIVATE / WA_INACTIVE` (that's the click-away-to-close
|
||||||
|
behaviour). A `MessageBox` shown from inside `PopupProc` would *deactivate the
|
||||||
|
popup, destroy it mid-handler, and then resume the handler with a dead `HWND`* —
|
||||||
|
undefined behaviour. **Never open a modal dialog from `PopupProc`.** If a safety
|
||||||
|
net is wanted later, use the soft-delete variant in §8 instead.
|
||||||
|
3. **Deleting the LIVE session's entry detaches the session** (see §7) so Clear/exit
|
||||||
|
don't instantly resurrect the file you just deleted.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Step 1 — Extend `PopupState`
|
||||||
|
|
||||||
|
Find the `PopupState` struct and add the two marked fields:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
struct PopupState {
|
||||||
|
std::vector<std::wstring> items;
|
||||||
|
int sel = -1;
|
||||||
|
int hot = -1;
|
||||||
|
HWND owner = nullptr;
|
||||||
|
int ctrlId = 0;
|
||||||
|
int scroll = 0;
|
||||||
|
int visRows = 0;
|
||||||
|
int rowH = 30;
|
||||||
|
int pad = 3;
|
||||||
|
int wheelAccum = 0;
|
||||||
|
bool canDelete = false; // NEW: rows show a ✕ delete button (history popup only)
|
||||||
|
int hotX = -1; // NEW: ABSOLUTE index of the row whose ✕ is hovered, -1 = none
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
(`g_pop = PopupState{};` in `ShowSelectPopup` already resets the new fields each open —
|
||||||
|
no extra reset code needed.)
|
||||||
|
|
||||||
|
## 3. Step 2 — Three small helpers
|
||||||
|
|
||||||
|
Paste these **between `PopupRowFromY` and `PopupProc`** (they must be above `PopupProc`;
|
||||||
|
`PopupRowFromY` itself is unchanged):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// The ✕ hit square for a VISIBLE row (0..visRows-1), in popup client coords.
|
||||||
|
// Sits at the right edge of the row, inside the scrollbar gutter if present.
|
||||||
|
static Rect PopupDeleteRect(const RECT& rc, int visIdx) {
|
||||||
|
int n = (int)g_pop.items.size();
|
||||||
|
bool hasBar = n > g_pop.visRows;
|
||||||
|
int barW = std::max(3, (int)(4 * g_dpiScale));
|
||||||
|
int rowW = rc.right - 2 * g_pop.pad - (hasBar ? barW + g_pop.pad : 0);
|
||||||
|
int xW = g_pop.rowH; // square zone, one row tall
|
||||||
|
return Rect(g_pop.pad + rowW - xW, g_pop.pad + visIdx * g_pop.rowH, xW, g_pop.rowH - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recompute hot row + hovered-✕ from the current cursor position. Used after
|
||||||
|
// scrolling and after a delete (the list moved under a stationary cursor).
|
||||||
|
static void PopupRefreshHotFromCursor(HWND h) {
|
||||||
|
POINT pt; GetCursorPos(&pt); ScreenToClient(h, &pt);
|
||||||
|
int row = PopupRowFromY(pt.y);
|
||||||
|
int hx = -1;
|
||||||
|
if (g_pop.canDelete && row >= 0) {
|
||||||
|
RECT rc; GetClientRect(h, &rc);
|
||||||
|
if (PopupDeleteRect(rc, row - g_pop.scroll).Contains(pt.x, pt.y)) hx = row;
|
||||||
|
}
|
||||||
|
g_pop.hot = row; g_pop.hotX = hx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the history file behind ABSOLUTE row `row`, then refresh the popup
|
||||||
|
// in place. The popup stays open so several entries can be deleted in a row.
|
||||||
|
static void PopupDeleteRow(HWND h, int row) {
|
||||||
|
if (row < 0 || row >= (int)g_history.size()) return;
|
||||||
|
std::wstring path = g_history[row].path;
|
||||||
|
bool ok = DeleteFileW(path.c_str()) != FALSE;
|
||||||
|
|
||||||
|
// ---- Requires Fix-05 (g_sessionPath). Omit this block ONLY if building
|
||||||
|
// ---- without Fix-05, and apply it when Fix-05 lands.
|
||||||
|
if (ok && path == g_sessionPath) {
|
||||||
|
// The LIVE session's file was deleted: detach the session so Clear/exit
|
||||||
|
// don't immediately re-archive the same text. If the user dictates MORE,
|
||||||
|
// a new file is created — history always mirrors the transcript box.
|
||||||
|
g_sessionPath.clear();
|
||||||
|
g_lastLoadedText = GetEditText(g_pop.owner);
|
||||||
|
}
|
||||||
|
// ---- end Fix-05-dependent block
|
||||||
|
|
||||||
|
g_history = LoadHistoryIndex(); // re-scan the folder
|
||||||
|
g_pop.items.clear();
|
||||||
|
g_pop.items.reserve(g_history.size());
|
||||||
|
for (const auto& e : g_history) g_pop.items.push_back(e.label);
|
||||||
|
|
||||||
|
SetStatus(g_pop.owner, ok ? L"Deleted" : L"Delete failed");
|
||||||
|
|
||||||
|
int n = (int)g_pop.items.size();
|
||||||
|
if (n == 0) { DestroyWindow(h); return; } // nothing left to show
|
||||||
|
|
||||||
|
// Shrink the popup when fewer rows remain than were visible. It opens
|
||||||
|
// upward, so keep the BOTTOM edge fixed and move the top edge down.
|
||||||
|
if (n < g_pop.visRows) {
|
||||||
|
g_pop.visRows = n;
|
||||||
|
int newH = n * g_pop.rowH + 2 * g_pop.pad;
|
||||||
|
RECT wr; GetWindowRect(h, &wr);
|
||||||
|
SetWindowPos(h, nullptr, wr.left, wr.bottom - newH,
|
||||||
|
wr.right - wr.left, newH, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||||
|
}
|
||||||
|
int maxScroll = std::max(0, n - g_pop.visRows);
|
||||||
|
g_pop.scroll = std::min(g_pop.scroll, maxScroll);
|
||||||
|
|
||||||
|
PopupRefreshHotFromCursor(h);
|
||||||
|
InvalidateRect(h, nullptr, FALSE);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Why this is safe to do from `PopupProc`: everything here runs on the UI thread,
|
||||||
|
`g_history` / `g_sessionPath` / `g_lastLoadedText` are main-thread globals declared
|
||||||
|
earlier in the file, and `GetEditText` / `SetStatus` / `LoadHistoryIndex` are all
|
||||||
|
declared above the popup code already. Indices stay valid because `g_pop.items` is
|
||||||
|
rebuilt 1:1 from the freshly reloaded `g_history` — the existing `WM_APP_SELECT`
|
||||||
|
handler keeps working unchanged.
|
||||||
|
|
||||||
|
## 4. Step 3 — Replace `PopupProc` (entire function)
|
||||||
|
|
||||||
|
Replace the whole `LRESULT CALLBACK PopupProc(...)` with the version below. Changes vs
|
||||||
|
Fix-04: ✕ hover tracking in `WM_MOUSEMOVE`, `WM_MOUSEWHEEL` now uses
|
||||||
|
`PopupRefreshHotFromCursor`, `WM_KEYDOWN` gains `VK_DELETE`, `WM_LBUTTONUP` routes
|
||||||
|
✕-clicks to `PopupDeleteRow` (and does NOT close), and `WM_PAINT` draws the ✕ and
|
||||||
|
reserves label space for it. Everything else is byte-for-byte the Fix-04 code.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
LRESULT CALLBACK PopupProc(HWND h, UINT m, WPARAM w, LPARAM l) {
|
||||||
|
switch (m) {
|
||||||
|
case WM_MOUSEMOVE: {
|
||||||
|
int row = PopupRowFromY(GET_Y_LPARAM(l));
|
||||||
|
int hx = -1;
|
||||||
|
if (g_pop.canDelete && row >= 0) {
|
||||||
|
RECT rc; GetClientRect(h, &rc);
|
||||||
|
if (PopupDeleteRect(rc, row - g_pop.scroll).Contains(GET_X_LPARAM(l), GET_Y_LPARAM(l)))
|
||||||
|
hx = row;
|
||||||
|
}
|
||||||
|
if (row != g_pop.hot || hx != g_pop.hotX) {
|
||||||
|
g_pop.hot = row; g_pop.hotX = hx;
|
||||||
|
InvalidateRect(h, nullptr, FALSE);
|
||||||
|
}
|
||||||
|
TRACKMOUSEEVENT t{ sizeof(t), TME_LEAVE, h, 0 }; TrackMouseEvent(&t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case WM_MOUSELEAVE:
|
||||||
|
g_pop.hot = -1; g_pop.hotX = -1; InvalidateRect(h, nullptr, FALSE);
|
||||||
|
return 0;
|
||||||
|
case WM_MOUSEWHEEL: {
|
||||||
|
int maxScroll = (int)g_pop.items.size() - g_pop.visRows;
|
||||||
|
if (maxScroll <= 0) return 0;
|
||||||
|
g_pop.wheelAccum += GET_WHEEL_DELTA_WPARAM(w);
|
||||||
|
int steps = g_pop.wheelAccum / WHEEL_DELTA;
|
||||||
|
if (steps != 0) {
|
||||||
|
g_pop.wheelAccum -= steps * WHEEL_DELTA;
|
||||||
|
g_pop.scroll -= steps * 3;
|
||||||
|
g_pop.scroll = std::max(0, std::min(g_pop.scroll, maxScroll));
|
||||||
|
PopupRefreshHotFromCursor(h);
|
||||||
|
InvalidateRect(h, nullptr, FALSE);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case WM_KEYDOWN:
|
||||||
|
if (w == VK_ESCAPE) DestroyWindow(h);
|
||||||
|
else if (w == VK_DELETE && g_pop.canDelete && g_pop.hot >= 0)
|
||||||
|
PopupDeleteRow(h, g_pop.hot);
|
||||||
|
return 0;
|
||||||
|
case WM_LBUTTONUP: {
|
||||||
|
int row = PopupRowFromY(GET_Y_LPARAM(l));
|
||||||
|
if (g_pop.canDelete && row >= 0) {
|
||||||
|
RECT rc; GetClientRect(h, &rc);
|
||||||
|
if (PopupDeleteRect(rc, row - g_pop.scroll).Contains(GET_X_LPARAM(l), GET_Y_LPARAM(l))) {
|
||||||
|
PopupDeleteRow(h, row); // delete — popup STAYS OPEN
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (row >= 0)
|
||||||
|
PostMessageW(g_pop.owner, WM_APP_SELECT, (WPARAM)g_pop.ctrlId, (LPARAM)row);
|
||||||
|
DestroyWindow(h);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
case WM_ACTIVATE:
|
||||||
|
if (LOWORD(w) == WA_INACTIVE) DestroyWindow(h);
|
||||||
|
return 0;
|
||||||
|
case WM_ERASEBKGND: return 1;
|
||||||
|
case WM_PAINT: {
|
||||||
|
PAINTSTRUCT ps; HDC hdc = BeginPaint(h, &ps);
|
||||||
|
RECT rc; GetClientRect(h, &rc);
|
||||||
|
HDC mem = CreateCompatibleDC(hdc);
|
||||||
|
HBITMAP bmp = CreateCompatibleBitmap(hdc, rc.right, rc.bottom);
|
||||||
|
HBITMAP old = (HBITMAP)SelectObject(mem, bmp);
|
||||||
|
{
|
||||||
|
Graphics g(mem);
|
||||||
|
g.SetSmoothingMode(SmoothingModeAntiAlias);
|
||||||
|
g.SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
|
||||||
|
Rect all(0, 0, rc.right, rc.bottom);
|
||||||
|
FillRound(g, T_CARD, all, 10);
|
||||||
|
StrokeRound(g, T_FAINT, all, 10, 1.0f);
|
||||||
|
int n = (int)g_pop.items.size();
|
||||||
|
bool hasBar = n > g_pop.visRows;
|
||||||
|
int barW = std::max(3, (int)(4 * g_dpiScale));
|
||||||
|
int rowW = rc.right - 2 * g_pop.pad - (hasBar ? barW + g_pop.pad : 0);
|
||||||
|
int reserve = g_pop.canDelete ? g_pop.rowH : 0; // keep labels clear of the ✕ zone
|
||||||
|
int last = std::min(n, g_pop.scroll + g_pop.visRows);
|
||||||
|
for (int i = g_pop.scroll; i < last; ++i) {
|
||||||
|
int vis = i - g_pop.scroll;
|
||||||
|
Rect row(g_pop.pad, g_pop.pad + vis * g_pop.rowH, rowW, g_pop.rowH - 2);
|
||||||
|
if (i == g_pop.hot) FillRound(g, T_CARD_HI, row, 7);
|
||||||
|
RectF tb((REAL)row.X + 9, (REAL)row.Y, (REAL)(row.Width - 12 - reserve), (REAL)row.Height);
|
||||||
|
DrawTextC(g, g_pop.items[i].c_str(), *g_gpUI,
|
||||||
|
(i == g_pop.sel) ? T_ACCENT : T_TEXT,
|
||||||
|
tb, StringAlignmentNear, StringAlignmentCenter);
|
||||||
|
if (g_pop.canDelete && i == g_pop.hot) { // ✕ only on the hovered row
|
||||||
|
Rect xr = PopupDeleteRect(rc, vis);
|
||||||
|
if (i == g_pop.hotX) FillRound(g, T_CARD_LO, xr, 6);
|
||||||
|
RectF xb((REAL)xr.X, (REAL)xr.Y, (REAL)xr.Width, (REAL)xr.Height);
|
||||||
|
DrawTextC(g, L"✕", *g_gpUI,
|
||||||
|
(i == g_pop.hotX) ? T_DANGER : T_FAINT,
|
||||||
|
xb, StringAlignmentCenter, StringAlignmentCenter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasBar) {
|
||||||
|
int trackH = rc.bottom - 2 * g_pop.pad;
|
||||||
|
int thumbH = std::max((int)(20 * g_dpiScale), trackH * g_pop.visRows / n);
|
||||||
|
int maxScroll = n - g_pop.visRows;
|
||||||
|
int thumbY = g_pop.pad + (trackH - thumbH) * g_pop.scroll / maxScroll;
|
||||||
|
Rect thumb(rc.right - g_pop.pad - barW, thumbY, barW, thumbH);
|
||||||
|
FillRound(g, T_DIM, thumb, barW / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BitBlt(hdc, 0, 0, rc.right, rc.bottom, mem, 0, 0, SRCCOPY);
|
||||||
|
SelectObject(mem, old); DeleteObject(bmp); DeleteDC(mem);
|
||||||
|
EndPaint(h, &ps);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DefWindowProc(h, m, w, l);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Visual spec, matching the app's design language: the ✕ (`✕`) appears only on the
|
||||||
|
hovered row, drawn in `T_FAINT`; when the cursor is over the ✕ itself it turns
|
||||||
|
`T_DANGER` red on a subtle `T_CARD_LO` chip. Labels always reserve the ✕ column in the
|
||||||
|
history popup so text doesn't shift when hover reveals the button.
|
||||||
|
|
||||||
|
## 5. Step 4 — Enable it for the History popup only
|
||||||
|
|
||||||
|
In `ShowSelectPopup`, find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
g_pop.ctrlId = ctrlId;
|
||||||
|
```
|
||||||
|
|
||||||
|
Add one line directly below it:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
g_pop.ctrlId = ctrlId;
|
||||||
|
g_pop.canDelete = (ctrlId == ID_SEL_HISTORY); // ✕ delete buttons: history only
|
||||||
|
```
|
||||||
|
|
||||||
|
That's the entire gating — the mic popup keeps `canDelete == false` and renders/behaves
|
||||||
|
exactly as before.
|
||||||
|
|
||||||
|
## 6. No other changes
|
||||||
|
|
||||||
|
- `OnClick` (History / SelAudio cases), `ShowSelectPopup`'s sizing/placement,
|
||||||
|
`WM_APP_SELECT`, `history.h` — all untouched.
|
||||||
|
- No new message IDs, no new globals beyond the two `PopupState` fields.
|
||||||
|
|
||||||
|
## 7. Interaction with the live session (Fix-05) — read this
|
||||||
|
|
||||||
|
Fix-05 keeps the current dictation session mirrored to a history file
|
||||||
|
(`g_sessionPath`). If the user deletes THAT entry from the popup:
|
||||||
|
|
||||||
|
- Without special handling, `FinalizeSession` would re-archive the box text on the next
|
||||||
|
Clear/exit — the file the user just deleted would instantly come back.
|
||||||
|
- The marked block in `PopupDeleteRow` prevents that: it clears `g_sessionPath` and sets
|
||||||
|
`g_lastLoadedText` to the current box text, so Clear/exit treat the box content as
|
||||||
|
"already accounted for" and do NOT re-archive it. (This is the same guard mechanism
|
||||||
|
Fix-05 documented — used deliberately here, because the user explicitly said
|
||||||
|
"forget this".)
|
||||||
|
- **Documented behaviour, not a bug:** if the user deletes the live entry and then
|
||||||
|
dictates *more*, a NEW history file is created containing the box's full text —
|
||||||
|
history always mirrors the transcript box. To make a session vanish completely:
|
||||||
|
delete the entry, then Clear.
|
||||||
|
|
||||||
|
## 8. Optional variant — soft delete (trash folder)
|
||||||
|
|
||||||
|
If you ever want an undo path, change ONE line in `PopupDeleteRow`. Replace:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
bool ok = DeleteFileW(path.c_str()) != FALSE;
|
||||||
|
```
|
||||||
|
|
||||||
|
with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::wstring trashDir = HistoryDir() + L"\\trash";
|
||||||
|
CreateDirectoryW(trashDir.c_str(), nullptr);
|
||||||
|
std::wstring dest = trashDir + path.substr(path.find_last_of(L'\\'));
|
||||||
|
bool ok = MoveFileExW(path.c_str(), dest.c_str(), MOVEFILE_REPLACE_EXISTING) != FALSE;
|
||||||
|
```
|
||||||
|
|
||||||
|
`LoadHistoryIndex` only scans `history\*.txt` (not subfolders), so trashed entries
|
||||||
|
disappear from the popup but remain recoverable by hand. Not wired to any UI — purely a
|
||||||
|
safety net. Skip this for v1 unless asked.
|
||||||
|
|
||||||
|
## 9. Build & test checklist
|
||||||
|
|
||||||
|
1. **Reveal:** open History, move the mouse down the rows — a faint ✕ appears at the
|
||||||
|
right edge of the hovered row only; it turns red when the cursor reaches it.
|
||||||
|
2. **Delete:** click a ✕ → the row disappears, the file is gone from the `history\`
|
||||||
|
folder, status shows "Deleted", and the **popup stays open**.
|
||||||
|
3. **Multi-delete:** delete 3–4 entries in a row without the popup closing; hover
|
||||||
|
highlight stays correct after each (the list shifts under the cursor).
|
||||||
|
4. **Row click still loads:** clicking a row anywhere left of the ✕ loads the entry and
|
||||||
|
closes the popup, exactly as before.
|
||||||
|
5. **Scrollbar transition:** with 9+ entries, delete down to 8 → the scrollbar
|
||||||
|
disappears and rows widen slightly; scrolled state stays sane (no blank gaps).
|
||||||
|
6. **Shrink:** with ≤7 entries left, delete more — the popup gets shorter with its
|
||||||
|
bottom edge fixed just above the selects row (it shrinks downward-in-place, never
|
||||||
|
floats away).
|
||||||
|
7. **Last entry:** deleting the final entry closes the popup; clicking History again
|
||||||
|
shows "No history yet".
|
||||||
|
8. **Delete key:** hover a row, press `Delete` → same as clicking its ✕.
|
||||||
|
9. **Live session:** dictate (entry appears per Fix-05) → open History → delete that
|
||||||
|
entry → press Clear → status "Cleared" and the entry does NOT come back. Then
|
||||||
|
dictate again → a new entry appears (documented in §7).
|
||||||
|
10. **Mic popup regression:** the Microphone popup shows NO ✕, full-width labels,
|
||||||
|
selection works — completely unchanged.
|
||||||
|
11. **Esc / click-away:** still close the popup; no delete is triggered.
|
||||||
|
12. **DPI 125/150%:** ✕ hit zone lines up with the drawn glyph.
|
||||||
|
|
||||||
|
## 10. Do NOT touch / do NOT add
|
||||||
|
|
||||||
|
- **Do NOT add a `MessageBox` confirmation inside `PopupProc`** — the popup destroys
|
||||||
|
itself on deactivation (`WM_ACTIVATE`/`WA_INACTIVE`), so a modal dialog kills the
|
||||||
|
popup mid-handler and the code resumes with a destroyed `HWND`. If confirmation is
|
||||||
|
ever required, use the §8 trash variant or build it into the popup's own surface.
|
||||||
|
- `PopupRowFromY`, `ShowSelectPopup` (besides the one-line flag), `history.h`,
|
||||||
|
`WM_APP_SELECT`, `FinalizeSession` — unchanged.
|
||||||
|
- `g_pop.sel` needs no remapping on delete: the history popup always opens with
|
||||||
|
`sel = -1`, and the mic popup (which uses `sel`) can't delete.
|
||||||
@@ -0,0 +1,317 @@
|
|||||||
|
# Fix 05 — New transcriptions never reach history (+ live session archiving)
|
||||||
|
|
||||||
|
**Builds on:** Fix-03/04 (popup history list — those are fine and unchanged).
|
||||||
|
**Files touched:** `src/main.cpp` only. `history.h` already has everything we need.
|
||||||
|
**Estimated effort:** 30–45 minutes including testing.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Root cause — one line poisons every archive path
|
||||||
|
|
||||||
|
History files are only ever written by `ArchiveSession()`, which is called from three
|
||||||
|
places, all guarded the same way:
|
||||||
|
|
||||||
|
| Where | Guard |
|
||||||
|
|---|---|
|
||||||
|
| Clear button (`OnClick` → `WK::Clear`) | `if (!cur.empty() && cur != g_lastLoadedText)` |
|
||||||
|
| Picking a history entry (`WM_APP_SELECT` → `ID_SEL_HISTORY`) | same |
|
||||||
|
| App exit (`WM_DESTROY`) | same |
|
||||||
|
|
||||||
|
`g_lastLoadedText` exists for ONE purpose: it remembers text that was loaded **FROM**
|
||||||
|
history, so that flipping between entries doesn't re-archive an unmodified copy and
|
||||||
|
create duplicates. It is supposed to be set in exactly one place — the history-load
|
||||||
|
handler.
|
||||||
|
|
||||||
|
But look at `WM_APP_RESULT` (the handler that runs when a transcription finishes).
|
||||||
|
After inserting the new text into the transcript box it does:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
UpdatePlaceholder(hWnd);
|
||||||
|
g_lastLoadedText = GetEditText(hWnd); // ← THE BUG
|
||||||
|
SetClipboardTextUtf8(hWnd, *res);
|
||||||
|
```
|
||||||
|
|
||||||
|
That line stamps the freshly-transcribed text as "this came from history". From that
|
||||||
|
moment, `cur == g_lastLoadedText` is true, so:
|
||||||
|
|
||||||
|
- **Clear** skips the archive — but still shows the (now lying) "Saved to history" status;
|
||||||
|
- **loading another history entry** silently discards the current transcription;
|
||||||
|
- **exiting the app** discards it too.
|
||||||
|
|
||||||
|
Net effect: exactly what you reported — no new transcription ever lands in `history\`.
|
||||||
|
You can confirm the diagnosis before fixing: transcribe → **manually type one extra
|
||||||
|
character** in the box → press Clear → the entry DOES appear (the edit makes
|
||||||
|
`cur != g_lastLoadedText` again).
|
||||||
|
|
||||||
|
## 2. Second problem — sessions only archived at boundaries the user rarely hits
|
||||||
|
|
||||||
|
Even with that line deleted, a session is only archived on Clear / entry-switch / exit.
|
||||||
|
The real dictation workflow is: hotkey → speak → auto-paste → keep working, app lives in
|
||||||
|
the tray. Clear is optional, exit is rare. So history would still feel "missing" most of
|
||||||
|
the time, and a crash would lose the whole session.
|
||||||
|
|
||||||
|
**Fix: live session archiving.** Every successful transcription immediately writes the
|
||||||
|
session's history file:
|
||||||
|
|
||||||
|
- the **first** clip of a session **creates** a new timestamped file (via the existing
|
||||||
|
`ArchiveSession`, which already returns the path it wrote);
|
||||||
|
- every **subsequent** clip **rewrites that same file** with the full transcript —
|
||||||
|
one file per session, never duplicates;
|
||||||
|
- Clear / entry-switch / exit just *finalize* the session (capture any manual edits made
|
||||||
|
after the last clip, then start a fresh session).
|
||||||
|
|
||||||
|
Result: open the History popup right after dictating and the session is already there,
|
||||||
|
at the top, kept current as you append. Crash-safe for free.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Step 1 — Add the session-path global
|
||||||
|
|
||||||
|
In `src/main.cpp`, find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::vector<HistoryEntry> g_history;
|
||||||
|
std::wstring g_lastLoadedText;
|
||||||
|
```
|
||||||
|
|
||||||
|
Add one line below them:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::vector<HistoryEntry> g_history;
|
||||||
|
std::wstring g_lastLoadedText;
|
||||||
|
std::wstring g_sessionPath; // history file backing the CURRENT session ("" = none yet)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Do NOT delete `g_lastLoadedText`** — it still guards against re-archiving an
|
||||||
|
unmodified entry that was loaded from history (Step 4 below still uses it).
|
||||||
|
|
||||||
|
## 4. Step 2 — Add two small helpers
|
||||||
|
|
||||||
|
Paste these **immediately above** `void OnClick(HWND hWnd, WK kind)` (right after the
|
||||||
|
`SelectsRowFullWidthAnchor()` helper from Fix-04):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// True if the string contains anything that isn't whitespace.
|
||||||
|
static bool HasInk(const std::wstring& s) {
|
||||||
|
for (wchar_t c : s) if (!iswspace(c)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// End the current session: make sure whatever is in the transcript box is in
|
||||||
|
// history (including manual edits made after the last clip), then reset the
|
||||||
|
// session so the next transcription starts a new history file.
|
||||||
|
// Returns true if the session is saved in history.
|
||||||
|
static bool FinalizeSession(HWND hWnd) {
|
||||||
|
std::wstring cur = GetEditText(hWnd);
|
||||||
|
bool saved = false;
|
||||||
|
if (!g_sessionPath.empty()) {
|
||||||
|
// Live archiving already created the file; just capture any edits
|
||||||
|
// the user made after the last transcription.
|
||||||
|
if (HasInk(cur)) WriteFileUtf8(g_sessionPath, cur);
|
||||||
|
saved = true;
|
||||||
|
} else if (HasInk(cur) && cur != g_lastLoadedText) {
|
||||||
|
// Text that was typed (never transcribed) — archive it once.
|
||||||
|
// The g_lastLoadedText guard stops unmodified loaded entries
|
||||||
|
// from being archived a second time.
|
||||||
|
saved = !ArchiveSession(cur).empty();
|
||||||
|
}
|
||||||
|
g_sessionPath.clear();
|
||||||
|
return saved;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
(`WriteFileUtf8` and `ArchiveSession` are both `inline` in `history.h`, which
|
||||||
|
`main.cpp` already includes — nothing to add there.)
|
||||||
|
|
||||||
|
## 5. Step 3 — Fix `WM_APP_RESULT` (delete the bug, add live archiving)
|
||||||
|
|
||||||
|
In `WndProc`'s `WM_APP_RESULT` case, find these four lines:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
SendMessageW(hEdit, EM_SCROLLCARET, 0, 0);
|
||||||
|
UpdatePlaceholder(hWnd);
|
||||||
|
g_lastLoadedText = GetEditText(hWnd);
|
||||||
|
SetClipboardTextUtf8(hWnd, *res);
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
SendMessageW(hEdit, EM_SCROLLCARET, 0, 0);
|
||||||
|
UpdatePlaceholder(hWnd);
|
||||||
|
{
|
||||||
|
// Live-archive: keep this session's history file current.
|
||||||
|
// First clip creates the file; later clips rewrite it.
|
||||||
|
std::wstring all = GetEditText(hWnd);
|
||||||
|
if (g_sessionPath.empty()) g_sessionPath = ArchiveSession(all);
|
||||||
|
else WriteFileUtf8(g_sessionPath, all);
|
||||||
|
}
|
||||||
|
SetClipboardTextUtf8(hWnd, *res);
|
||||||
|
```
|
||||||
|
|
||||||
|
Two things happened here — make sure both did:
|
||||||
|
|
||||||
|
1. `g_lastLoadedText = GetEditText(hWnd);` is **GONE**. This is the actual bug fix.
|
||||||
|
Do not move it somewhere else; it must only ever be assigned in the history-load
|
||||||
|
handler (Step 5b) and cleared on Clear.
|
||||||
|
2. The live-archive block was added in its place.
|
||||||
|
|
||||||
|
## 6. Step 4 — Route the three session boundaries through `FinalizeSession`
|
||||||
|
|
||||||
|
### 4a. Clear button — `OnClick`, `case WK::Clear`
|
||||||
|
|
||||||
|
Find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case WK::Clear: {
|
||||||
|
std::wstring cur = GetEditText(hWnd);
|
||||||
|
if (!cur.empty() && cur != g_lastLoadedText)
|
||||||
|
ArchiveSession(cur);
|
||||||
|
g_history = LoadHistoryIndex();
|
||||||
|
g_lastLoadedText.clear();
|
||||||
|
g_editDirty = false;
|
||||||
|
SetDlgItemText(hWnd, ID_EDIT_TEXT, L"");
|
||||||
|
UpdatePlaceholder(hWnd);
|
||||||
|
SetStatus(hWnd, L"Saved to history");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case WK::Clear: {
|
||||||
|
bool saved = FinalizeSession(hWnd);
|
||||||
|
g_history = LoadHistoryIndex();
|
||||||
|
g_lastLoadedText.clear();
|
||||||
|
g_editDirty = false;
|
||||||
|
SetDlgItemText(hWnd, ID_EDIT_TEXT, L"");
|
||||||
|
UpdatePlaceholder(hWnd);
|
||||||
|
SetStatus(hWnd, saved ? L"Saved to history" : L"Cleared");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
(Bonus fix: the status no longer claims "Saved to history" when nothing was saved —
|
||||||
|
clearing an empty box now honestly says "Cleared".)
|
||||||
|
|
||||||
|
### 4b. Picking a history entry — `WM_APP_SELECT`, the `ID_SEL_HISTORY` branch
|
||||||
|
|
||||||
|
Find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
} else if (ctrlId == ID_SEL_HISTORY && idx >= 0 && idx < (int)g_history.size()) {
|
||||||
|
std::wstring cur = GetEditText(hWnd);
|
||||||
|
if (!cur.empty() && cur != g_lastLoadedText)
|
||||||
|
ArchiveSession(cur);
|
||||||
|
std::wstring text = ReadFileUtf8(g_history[idx].path);
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace the first three body lines with one call (the rest of the branch stays):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
} else if (ctrlId == ID_SEL_HISTORY && idx >= 0 && idx < (int)g_history.size()) {
|
||||||
|
FinalizeSession(hWnd); // save the in-progress session before swapping
|
||||||
|
std::wstring text = ReadFileUtf8(g_history[idx].path);
|
||||||
|
```
|
||||||
|
|
||||||
|
Leave `g_lastLoadedText = text;` and everything after it in this branch exactly as it
|
||||||
|
is — this is the ONE place `g_lastLoadedText` is supposed to be assigned.
|
||||||
|
|
||||||
|
Note: loading an entry does NOT make it the live session (`FinalizeSession` cleared
|
||||||
|
`g_sessionPath`). If you dictate on top of a loaded entry, the next clip archives the
|
||||||
|
combined text as a **new** file — old history entries are never mutated.
|
||||||
|
|
||||||
|
### 4c. App exit — `WM_DESTROY`
|
||||||
|
|
||||||
|
Find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case WM_DESTROY: {
|
||||||
|
std::wstring cur = GetEditText(hWnd);
|
||||||
|
if (!cur.empty() && cur != g_lastLoadedText) ArchiveSession(cur);
|
||||||
|
PersistNow();
|
||||||
|
PostQuitMessage(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case WM_DESTROY: {
|
||||||
|
FinalizeSession(hWnd);
|
||||||
|
PersistNow();
|
||||||
|
PostQuitMessage(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4d. Legacy hidden Clear button — `WM_COMMAND`, `case ID_BTN_CLEAR`
|
||||||
|
|
||||||
|
This branch belongs to a hidden legacy child button and never fires, but update it to
|
||||||
|
match 4a anyway so the two Clear paths can't drift apart:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case ID_BTN_CLEAR: {
|
||||||
|
bool saved = FinalizeSession(hWnd);
|
||||||
|
g_history = LoadHistoryIndex();
|
||||||
|
g_lastLoadedText.clear();
|
||||||
|
g_editDirty = false;
|
||||||
|
SetDlgItemText(hWnd, ID_EDIT_TEXT, L"");
|
||||||
|
UpdatePlaceholder(hWnd);
|
||||||
|
SetStatus(hWnd, saved ? L"Saved to history" : L"Cleared");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 7. How the pieces behave now (mental model for the dev)
|
||||||
|
|
||||||
|
```
|
||||||
|
record clip 1 ──► WM_APP_RESULT ──► ArchiveSession(text) → creates 2026-06-11_HHMMSS.txt, g_sessionPath = that file
|
||||||
|
record clip 2 ──► WM_APP_RESULT ──► WriteFileUtf8(sessionPath) → same file rewritten with full text
|
||||||
|
edit by hand ──► (nothing yet — captured at the next clip or at finalize)
|
||||||
|
Clear / pick entry / exit ──► FinalizeSession → final write incl. edits, g_sessionPath = ""
|
||||||
|
next clip ──► new session file
|
||||||
|
```
|
||||||
|
|
||||||
|
- One file per session. Appending clips never creates duplicates.
|
||||||
|
- Cancelled clips / "No speech detected" change nothing (the result is empty, so the
|
||||||
|
live-archive block isn't reached).
|
||||||
|
- The session file keeps its creation timestamp/filename while it grows — it sorts in
|
||||||
|
the popup by when the session *started*. That's intended.
|
||||||
|
- `ArchiveSession` already refuses whitespace-only text and prunes to 100 files; both
|
||||||
|
behaviors are reused untouched.
|
||||||
|
|
||||||
|
## 8. Build & test checklist
|
||||||
|
|
||||||
|
1. **The headline fix:** launch with an empty box → dictate one clip → open History
|
||||||
|
(no Clear!) → the new session is the top entry with the right preview.
|
||||||
|
2. **Appending:** dictate a second clip → open History → still ONE entry for this
|
||||||
|
session, now containing both clips. No duplicate rows.
|
||||||
|
3. **Clear:** press Clear → "Saved to history" → box empties → dictate again → History
|
||||||
|
now shows TWO entries (old session + new session).
|
||||||
|
4. **Clear with empty box:** status says "Cleared" and no empty file appears in `history\`.
|
||||||
|
5. **Exit:** dictate → edit a word by hand → Exit via tray → relaunch → the entry
|
||||||
|
contains the hand-edit.
|
||||||
|
6. **Switching:** dictate → open History → pick an older entry → the in-progress
|
||||||
|
session was saved (visible in the list) and the older text loads.
|
||||||
|
7. **No duplicate on unmodified load:** load an entry, change nothing, press Clear →
|
||||||
|
no new file is created (status "Cleared"); the entry appears once in the list.
|
||||||
|
8. **Dictating onto a loaded entry:** load an entry → dictate → a NEW combined entry is
|
||||||
|
created; the original old file is unchanged.
|
||||||
|
9. **Typed-only session:** type text manually without dictating → Clear → archived once.
|
||||||
|
10. **Cancel:** record → hotkey again mid-transcription to cancel → no history file.
|
||||||
|
11. **Diagnosis confirmation (optional, before applying the fix):** on the OLD build,
|
||||||
|
transcribe → type one character → Clear → entry appears. That proves the
|
||||||
|
`g_lastLoadedText` poisoning was the culprit.
|
||||||
|
|
||||||
|
## 9. Do NOT touch
|
||||||
|
|
||||||
|
- `history.h` — `ArchiveSession`, `WriteFileUtf8`, `PruneHistory`, `LoadHistoryIndex`
|
||||||
|
all unchanged.
|
||||||
|
- The popup code from Fix-03/04 (`PopupProc`, `ShowSelectPopup`,
|
||||||
|
`SelectsRowFullWidthAnchor`) — unchanged.
|
||||||
|
- `g_lastLoadedText` — keep it; it is still assigned in the history-load branch and
|
||||||
|
cleared on Clear. Just never assign it anywhere else (that was the bug).
|
||||||
|
- `g_editDirty` — currently informational only; leave as is.
|
||||||
@@ -0,0 +1,294 @@
|
|||||||
|
# Fix 04 — History popup: full app width, always opens upward, no squashed text
|
||||||
|
|
||||||
|
**Builds on:** Fix-03 (the popup-window history list). Apply this only after Fix-03 is in.
|
||||||
|
**Files touched:** `src/main.cpp` (plus one optional line in `src/history.h`).
|
||||||
|
**Estimated effort:** ~30 minutes including testing.
|
||||||
|
**Important:** `PopupProc` (the popup's message handler) needs **NO changes**. All the
|
||||||
|
scroll / hover / click machinery from Fix-03 stays exactly as it is.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. What's actually wrong (two separate root causes)
|
||||||
|
|
||||||
|
### 1a. The "squashed" rows are caused by TEXT WRAPPING, not just narrowness
|
||||||
|
|
||||||
|
Look closely at the screenshot: each history row shows the timestamp on one line and a
|
||||||
|
clipped second line of preview text under it. That is GDI+ **wrapping** the label.
|
||||||
|
|
||||||
|
`DrawTextC()` builds a `StringFormat` and sets ellipsis trimming, but never sets
|
||||||
|
`StringFormatFlagsNoWrap`. GDI+ `DrawString` **wraps by default** when given a layout
|
||||||
|
rectangle. So a long label inside a 30px-tall row wraps to a second line, which doesn't
|
||||||
|
fit vertically, and gets clipped → the cramped, squashed look. The ellipsis trimming only
|
||||||
|
kicks in on the wrapped last line, which is why you see `…` mid-text.
|
||||||
|
|
||||||
|
This must be fixed at the `DrawTextC` level. Widening the popup alone is NOT enough — a
|
||||||
|
long enough entry would still wrap and squash again.
|
||||||
|
|
||||||
|
### 1b. The popup is anchored to the half-width History button, and prefers opening down
|
||||||
|
|
||||||
|
- `ShowSelectPopup` is called with `g_w[(int)WK::History].r` as the anchor, so the popup
|
||||||
|
is only as wide as the History button (half the content width, min 260px).
|
||||||
|
- The Fix-03 placement logic opens **downward** whenever the monitor has room below the
|
||||||
|
button, which is almost always (the screenshot shows it covering Copy/Paste and
|
||||||
|
spilling below the window). The requirement is now: **always open upward**, over the
|
||||||
|
transcript, inside the app's footprint.
|
||||||
|
|
||||||
|
## 2. The fix — summary
|
||||||
|
|
||||||
|
1. Add `StringFormatFlagsNoWrap` to `DrawTextC` → every label renders on exactly one
|
||||||
|
line and ellipsizes cleanly. (Safe app-wide: every `DrawTextC` caller — buttons,
|
||||||
|
status line, settings rows, stats lines, popup rows — is a single-line label. Nothing
|
||||||
|
in the app intentionally wraps.)
|
||||||
|
2. Replace `ShowSelectPopup`'s placement logic: **always upward**, with a
|
||||||
|
shrink-to-fit fallback if the window sits near the top of the screen, and use the
|
||||||
|
anchor's width **exactly** (drop the 260px minimum — the anchor itself becomes
|
||||||
|
full-width in step 3).
|
||||||
|
3. Anchor the popup to a **full-content-width rect at the selects row** (from the left
|
||||||
|
edge of the mic select to the right edge of the History select) instead of to the
|
||||||
|
individual button. Apply to History (required) and to the mic selector (same row, same
|
||||||
|
one-liner — keeps the two popups consistent and stops long device names truncating).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Step 1 — Stop GDI+ wrapping in `DrawTextC`
|
||||||
|
|
||||||
|
In `src/main.cpp`, find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
static void DrawTextC(Graphics& g, const wchar_t* s, const Font& f, const Color& c,
|
||||||
|
const RectF& box, StringAlignment h, StringAlignment v) {
|
||||||
|
StringFormat sf; sf.SetAlignment(h); sf.SetLineAlignment(v);
|
||||||
|
sf.SetTrimming(StringTrimmingEllipsisCharacter);
|
||||||
|
SolidBrush b(c); g.DrawString(s, -1, &f, box, &sf, &b);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace with (one added line):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
static void DrawTextC(Graphics& g, const wchar_t* s, const Font& f, const Color& c,
|
||||||
|
const RectF& box, StringAlignment h, StringAlignment v) {
|
||||||
|
StringFormat sf; sf.SetAlignment(h); sf.SetLineAlignment(v);
|
||||||
|
sf.SetFormatFlags(StringFormatFlagsNoWrap); // single line: ellipsize, never wrap
|
||||||
|
sf.SetTrimming(StringTrimmingEllipsisCharacter);
|
||||||
|
SolidBrush b(c); g.DrawString(s, -1, &f, box, &sf, &b);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Why this is safe globally: `DrawTextC` is used for the Record/Copy/Paste/Clear labels,
|
||||||
|
the status line, the settings catalog rows, the statistics lines, the placeholder, and
|
||||||
|
the popup rows. Every one of those is a one-line label drawn into a one-line box. None
|
||||||
|
of them relies on wrapping. This change also future-proofs the rest of the UI against
|
||||||
|
the same bug.
|
||||||
|
|
||||||
|
## 4. Step 2 — Replace `ShowSelectPopup` (always upward + exact anchor width)
|
||||||
|
|
||||||
|
Replace the **entire** `ShowSelectPopup` function with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
void ShowSelectPopup(HWND owner, int ctrlId, const std::vector<std::wstring>& items, int sel, const RectF& anchor) {
|
||||||
|
static bool reg = false;
|
||||||
|
if (!reg) {
|
||||||
|
WNDCLASSEXW wc{ sizeof(wc) };
|
||||||
|
wc.lpfnWndProc = PopupProc;
|
||||||
|
wc.hInstance = hInst;
|
||||||
|
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||||
|
wc.hbrBackground = CreateSolidBrush(CR_SURFACE);
|
||||||
|
wc.lpszClassName = L"DictPopup";
|
||||||
|
RegisterClassExW(&wc);
|
||||||
|
reg = true;
|
||||||
|
}
|
||||||
|
if (items.empty()) return;
|
||||||
|
|
||||||
|
float s = g_dpiScale;
|
||||||
|
int rowH = (int)(30 * s);
|
||||||
|
int pad = (int)(3 * s); if (pad < 3) pad = 3;
|
||||||
|
int n = (int)items.size();
|
||||||
|
|
||||||
|
// Anchor rect is in CLIENT coordinates; convert its top-left to screen.
|
||||||
|
POINT tl{ (LONG)anchor.X, (LONG)anchor.Y };
|
||||||
|
ClientToScreen(owner, &tl);
|
||||||
|
int anchorTop = tl.y;
|
||||||
|
int x = tl.x;
|
||||||
|
|
||||||
|
HMONITOR mon = MonitorFromWindow(owner, MONITOR_DEFAULTTONEAREST);
|
||||||
|
MONITORINFO mi{ sizeof(mi) };
|
||||||
|
GetMonitorInfo(mon, &mi);
|
||||||
|
|
||||||
|
// ALWAYS open upward. If the window sits so close to the top of the screen
|
||||||
|
// that the popup wouldn't fit, show fewer rows instead of spilling off-screen
|
||||||
|
// (the wheel still reaches every item).
|
||||||
|
int visRows = std::min(n, kPopupMaxVisible);
|
||||||
|
int spaceAbove = anchorTop - mi.rcWork.top - 2; // px available above the row
|
||||||
|
int fitRows = (spaceAbove - 2 * pad) / rowH;
|
||||||
|
if (fitRows < 1) fitRows = 1;
|
||||||
|
if (visRows > fitRows) visRows = fitRows;
|
||||||
|
|
||||||
|
g_pop = PopupState{};
|
||||||
|
g_pop.items = items;
|
||||||
|
g_pop.sel = sel;
|
||||||
|
g_pop.owner = owner;
|
||||||
|
g_pop.ctrlId = ctrlId;
|
||||||
|
g_pop.visRows = visRows;
|
||||||
|
g_pop.rowH = rowH;
|
||||||
|
g_pop.pad = pad;
|
||||||
|
if (sel >= 0 && n > visRows)
|
||||||
|
g_pop.scroll = std::max(0, std::min(sel - visRows / 2, n - visRows));
|
||||||
|
|
||||||
|
int h = visRows * rowH + 2 * pad;
|
||||||
|
int wdt = (int)anchor.Width; // use the anchor's width EXACTLY
|
||||||
|
|
||||||
|
int y = anchorTop - h - 2; // bottom edge sits just above the anchor row
|
||||||
|
if (y < mi.rcWork.top) y = mi.rcWork.top;
|
||||||
|
if (x + wdt > mi.rcWork.right) x = mi.rcWork.right - wdt;
|
||||||
|
if (x < mi.rcWork.left) x = mi.rcWork.left;
|
||||||
|
|
||||||
|
HWND p = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, L"DictPopup", L"",
|
||||||
|
WS_POPUP, x, y, wdt, h, owner, nullptr, hInst, nullptr);
|
||||||
|
if (!p) return;
|
||||||
|
|
||||||
|
int corner = DWMWCP_ROUND;
|
||||||
|
DwmSetWindowAttribute(p, DWMWA_WINDOW_CORNER_PREFERENCE, &corner, sizeof(corner));
|
||||||
|
ShowWindow(p, SW_SHOWNA);
|
||||||
|
SetFocus(p);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Deliberate changes vs Fix-03 — so nothing looks accidentally lost:
|
||||||
|
|
||||||
|
- The downward-first / flip-up `if/else` is **gone**: it now always computes
|
||||||
|
`y = anchorTop - h - 2` (upward).
|
||||||
|
- New shrink-to-fit block: if the selects row is near the top of the *monitor*, the
|
||||||
|
popup shows fewer rows rather than going off-screen. Scrolling still reaches all items
|
||||||
|
because `PopupProc` keys off `g_pop.visRows`.
|
||||||
|
- `int wdt = std::max((int)anchor.Width, (int)(260 * s));` became
|
||||||
|
`int wdt = (int)anchor.Width;` — the 260px minimum is no longer needed because the
|
||||||
|
anchor itself is now full content width (Step 3).
|
||||||
|
- Everything else (DPI row height, scroll-to-selected, monitor clamps, window style,
|
||||||
|
rounded corners, `SetFocus` for wheel/Esc) is unchanged.
|
||||||
|
|
||||||
|
## 5. Step 3 — Full-width anchor for the selects row
|
||||||
|
|
||||||
|
### 5a. Add a tiny helper
|
||||||
|
|
||||||
|
Paste this **immediately above** `void OnClick(HWND hWnd, WK kind)`:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// Full content-width anchor at the selects row: spans from the left edge of the
|
||||||
|
// mic select to the right edge of the History select. Used so the popups open
|
||||||
|
// as wide as the app's content area, not as wide as one button.
|
||||||
|
static RectF SelectsRowFullWidthAnchor() {
|
||||||
|
const RectF& a = g_w[(int)WK::SelAudio].r; // leftmost widget on the row
|
||||||
|
const RectF& b = g_w[(int)WK::History].r; // rightmost widget on the row
|
||||||
|
return RectF(a.X, b.Y, (b.X + b.Width) - a.X, b.Height);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
(These two rects are laid out by `LayoutWidgets`: SelAudio starts at the left margin,
|
||||||
|
History ends at the right margin, so the result is exactly the inner content width —
|
||||||
|
and it stays correct automatically when the window is resized or DPI changes.)
|
||||||
|
|
||||||
|
### 5b. Use it at all three call sites
|
||||||
|
|
||||||
|
**Call site 1 — `OnClick`, the History case.** Find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
ShowSelectPopup(hWnd, ID_SEL_HISTORY, labels, -1, g_w[(int)WK::History].r);
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
ShowSelectPopup(hWnd, ID_SEL_HISTORY, labels, -1, SelectsRowFullWidthAnchor());
|
||||||
|
```
|
||||||
|
|
||||||
|
**Call site 2 — `OnClick`, the mic selector case.** Find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case WK::SelAudio:
|
||||||
|
ShowSelectPopup(hWnd, ID_SEL_AUDIO, g_audioItems, g_audioSel, g_w[(int)WK::SelAudio].r);
|
||||||
|
break;
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace with:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case WK::SelAudio:
|
||||||
|
ShowSelectPopup(hWnd, ID_SEL_AUDIO, g_audioItems, g_audioSel, SelectsRowFullWidthAnchor());
|
||||||
|
break;
|
||||||
|
```
|
||||||
|
|
||||||
|
(Same row, same treatment — keeps the two popups visually consistent and stops long
|
||||||
|
device names like "Microphone (Realtek High Definition Audio)" being truncated.)
|
||||||
|
|
||||||
|
**Call site 3 — `WM_COMMAND`, near the bottom of the big switch.** Find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
case ID_SEL_AUDIO:
|
||||||
|
ShowSelectPopup(hWnd, ID_SEL_AUDIO, g_audioItems, g_audioSel, g_w[(int)WK::SelAudio].r);
|
||||||
|
break;
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace with the same `SelectsRowFullWidthAnchor()` version. (This branch is vestigial —
|
||||||
|
it belongs to a hidden legacy child button and never fires — but update it anyway so a
|
||||||
|
future grep doesn't find two different anchoring styles.)
|
||||||
|
|
||||||
|
## 6. Optional polish — longer previews (now that there's room)
|
||||||
|
|
||||||
|
`history.h` truncates each preview to 28 characters, which was sized for the old
|
||||||
|
half-width dropdown. With the full-width popup there's room for roughly double that.
|
||||||
|
|
||||||
|
In `src/history.h`, inside `LoadHistoryIndex()`, find:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::wstring preview = ReadFileUtf8(e.path).substr(0, 28);
|
||||||
|
```
|
||||||
|
|
||||||
|
Change `28` to `60`. No migration needed — labels are rebuilt from the files every time
|
||||||
|
`LoadHistoryIndex()` runs, so existing history files immediately show longer previews.
|
||||||
|
Anything that still doesn't fit ellipsizes on one line (thanks to Step 1).
|
||||||
|
|
||||||
|
## 7. Build & test checklist
|
||||||
|
|
||||||
|
1. **No more squash:** open History — every row is exactly ONE line; entries too long
|
||||||
|
for the row end in a clean `…`. No second clipped line anywhere.
|
||||||
|
2. **Full width:** the popup spans from the left edge of the Microphone select to the
|
||||||
|
right edge of the History select (the whole content width), at any window size.
|
||||||
|
Resize the window wider → reopen → popup matches the new width.
|
||||||
|
3. **Always upward:** the popup's bottom edge sits just above the selects row and the
|
||||||
|
list extends UP over the transcript. It never opens downward, no matter where the
|
||||||
|
window is on the screen (test with the window at the bottom, middle, and top of the
|
||||||
|
monitor).
|
||||||
|
4. **Near the top of the screen:** drag the window so the selects row is close to the
|
||||||
|
top of the monitor → the popup shows fewer rows instead of going off-screen, and the
|
||||||
|
wheel still scrolls through all entries.
|
||||||
|
5. **Scrolling regression (from Fix-03):** with 10+ entries — max 8 rows, thumb on the
|
||||||
|
right, wheel scrolls 3 rows/notch, hover highlight tracks correctly.
|
||||||
|
6. **Mic selector:** also opens full-width and upward; picking a device still works.
|
||||||
|
7. **Dismissal:** click-away and Esc still close the popup; clicking an entry loads it
|
||||||
|
("Loaded from history") and archives whatever was in the box.
|
||||||
|
8. **NoWrap regression sweep:** glance over the rest of the UI — status line, Record
|
||||||
|
pill, settings model rows, statistics lines. All should look identical to before
|
||||||
|
(none of them ever wrapped). If any text now shows `…` where it used to wrap onto a
|
||||||
|
second line, that was the same bug manifesting there — widen that box, don't remove
|
||||||
|
NoWrap.
|
||||||
|
9. **DPI sanity:** 125%/150% — rows align with the cursor, popup width matches the row.
|
||||||
|
|
||||||
|
## 8. Tuning knobs
|
||||||
|
|
||||||
|
| What | Where | Default |
|
||||||
|
|---|---|---|
|
||||||
|
| Visible rows before scrolling | `kPopupMaxVisible` | 8 |
|
||||||
|
| Gap between popup and the row | `y = anchorTop - h - 2` | 2 px |
|
||||||
|
| Rows per wheel notch | `PopupProc` (`steps * 3`) — unchanged | 3 |
|
||||||
|
| Preview length in labels | `history.h` `substr(0, 60)` (optional step) | 60 chars |
|
||||||
|
|
||||||
|
## 9. Do NOT touch
|
||||||
|
|
||||||
|
- **`PopupProc` and `PopupRowFromY`** — completely unchanged from Fix-03. The scroll,
|
||||||
|
wheel-accumulator, hover, Esc, and click-away logic all still work because they read
|
||||||
|
`g_pop.visRows` / `rowH` / `pad`, which this fix still populates.
|
||||||
|
- `PopupState`, `kPopupMaxVisible` — unchanged.
|
||||||
|
- The `WM_APP_SELECT` handler (including the `ID_SEL_HISTORY` branch) — unchanged.
|
||||||
|
- `LayoutWidgets` — unchanged; the helper in Step 3 derives the full-width rect from the
|
||||||
|
existing widget rects, so there is nothing new to lay out.
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 19 KiB |
@@ -0,0 +1,92 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
#include <winhttp.h>
|
||||||
|
#include <atomic>
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <algorithm>
|
||||||
|
#pragma comment(lib, "winhttp.lib")
|
||||||
|
|
||||||
|
#define WM_APP_DLPROGRESS (WM_USER + 7)
|
||||||
|
|
||||||
|
struct Downloader {
|
||||||
|
std::atomic<bool> active{false};
|
||||||
|
std::atomic<bool> cancel{false};
|
||||||
|
int itemIndex = -1;
|
||||||
|
std::thread th;
|
||||||
|
|
||||||
|
void start(HWND notify, int index, std::wstring url, std::wstring dest);
|
||||||
|
void requestCancel() { cancel = true; }
|
||||||
|
void join() { if (th.joinable()) th.join(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
static void DlThread(HWND notify, int index, std::wstring url, std::wstring dest, Downloader* dl) {
|
||||||
|
std::wstring tmp = dest + L".part";
|
||||||
|
int result = -1;
|
||||||
|
HINTERNET hSes = nullptr, hCon = nullptr, hReq = nullptr;
|
||||||
|
FILE* f = nullptr;
|
||||||
|
do {
|
||||||
|
URL_COMPONENTS uc{}; uc.dwStructSize = sizeof(uc);
|
||||||
|
wchar_t host[256] = {0}, path[2048] = {0};
|
||||||
|
uc.lpszHostName = host; uc.dwHostNameLength = _countof(host);
|
||||||
|
uc.lpszUrlPath = path; uc.dwUrlPathLength = _countof(path);
|
||||||
|
if (!WinHttpCrackUrl(url.c_str(), 0, 0, &uc)) break;
|
||||||
|
hSes = WinHttpOpen(L"win-dictation/1.0", WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY,
|
||||||
|
WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
|
||||||
|
if (!hSes) break;
|
||||||
|
hCon = WinHttpConnect(hSes, host, uc.nPort, 0);
|
||||||
|
if (!hCon) break;
|
||||||
|
hReq = WinHttpOpenRequest(hCon, L"GET", path, nullptr, WINHTTP_NO_REFERER,
|
||||||
|
WINHTTP_DEFAULT_ACCEPT_TYPES,
|
||||||
|
(uc.nScheme == INTERNET_SCHEME_HTTPS) ? WINHTTP_FLAG_SECURE : 0);
|
||||||
|
if (!hReq) break;
|
||||||
|
if (!WinHttpSendRequest(hReq, WINHTTP_NO_ADDITIONAL_HEADERS, 0,
|
||||||
|
WINHTTP_NO_REQUEST_DATA, 0, 0, 0)) break;
|
||||||
|
if (!WinHttpReceiveResponse(hReq, nullptr)) break;
|
||||||
|
DWORD status = 0, sz = sizeof(status);
|
||||||
|
WinHttpQueryHeaders(hReq, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
|
||||||
|
WINHTTP_HEADER_NAME_BY_INDEX, &status, &sz, WINHTTP_NO_HEADER_INDEX);
|
||||||
|
if (status != 200) break;
|
||||||
|
ULONGLONG total = 0;
|
||||||
|
{
|
||||||
|
wchar_t cl[40]; DWORD cls = sizeof(cl);
|
||||||
|
if (WinHttpQueryHeaders(hReq, WINHTTP_QUERY_CONTENT_LENGTH,
|
||||||
|
WINHTTP_HEADER_NAME_BY_INDEX, cl, &cls, WINHTTP_NO_HEADER_INDEX))
|
||||||
|
total = (ULONGLONG)_wtoi64(cl);
|
||||||
|
}
|
||||||
|
if (_wfopen_s(&f, tmp.c_str(), L"wb") != 0 || !f) break;
|
||||||
|
std::vector<char> buf(64 * 1024);
|
||||||
|
ULONGLONG got = 0; int lastPct = -1; bool ioOk = true;
|
||||||
|
for (;;) {
|
||||||
|
if (dl->cancel.load()) { result = -2; ioOk = false; break; }
|
||||||
|
DWORD avail = 0;
|
||||||
|
if (!WinHttpQueryDataAvailable(hReq, &avail)) { ioOk = false; break; }
|
||||||
|
if (avail == 0) break;
|
||||||
|
DWORD toRead = std::min<DWORD>(avail, (DWORD)buf.size()), rd = 0;
|
||||||
|
if (!WinHttpReadData(hReq, buf.data(), toRead, &rd) || rd == 0) { ioOk = false; break; }
|
||||||
|
if (fwrite(buf.data(), 1, rd, f) != rd) { ioOk = false; break; }
|
||||||
|
got += rd;
|
||||||
|
int pct = total ? (int)(got * 100 / total) : 0;
|
||||||
|
if (pct != lastPct) { lastPct = pct; PostMessage(notify, WM_APP_DLPROGRESS, index, pct); }
|
||||||
|
}
|
||||||
|
fclose(f); f = nullptr;
|
||||||
|
if (ioOk && (total == 0 || got == total))
|
||||||
|
if (MoveFileExW(tmp.c_str(), dest.c_str(), MOVEFILE_REPLACE_EXISTING))
|
||||||
|
result = 101;
|
||||||
|
} while (false);
|
||||||
|
if (f) fclose(f);
|
||||||
|
if (result != 101) DeleteFileW(tmp.c_str());
|
||||||
|
if (hReq) WinHttpCloseHandle(hReq);
|
||||||
|
if (hCon) WinHttpCloseHandle(hCon);
|
||||||
|
if (hSes) WinHttpCloseHandle(hSes);
|
||||||
|
PostMessage(notify, WM_APP_DLPROGRESS, index, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Downloader::start(HWND notify, int index, std::wstring url, std::wstring dest) {
|
||||||
|
if (active.exchange(true)) return;
|
||||||
|
cancel = false; itemIndex = index;
|
||||||
|
if (th.joinable()) th.join();
|
||||||
|
th = std::thread(DlThread, notify, index, std::move(url), std::move(dest), this);
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
struct HistoryEntry { std::wstring path; std::wstring label; };
|
||||||
|
|
||||||
|
inline std::wstring HistoryDir() {
|
||||||
|
wchar_t buf[MAX_PATH]; GetModuleFileNameW(nullptr, buf, MAX_PATH);
|
||||||
|
std::wstring p(buf); p = p.substr(0, p.find_last_of(L"\\/"));
|
||||||
|
return p + L"\\history";
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool WriteFileUtf8(const std::wstring& path, const std::wstring& text) {
|
||||||
|
int n = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), (int)text.size(), nullptr, 0, nullptr, nullptr);
|
||||||
|
std::string u8(n, '\0');
|
||||||
|
if (n) WideCharToMultiByte(CP_UTF8, 0, text.c_str(), (int)text.size(), &u8[0], n, nullptr, nullptr);
|
||||||
|
HANDLE h = CreateFileW(path.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||||
|
if (h == INVALID_HANDLE_VALUE) return false;
|
||||||
|
DWORD wr; const unsigned char bom[3] = {0xEF,0xBB,0xBF};
|
||||||
|
WriteFile(h, bom, 3, &wr, nullptr);
|
||||||
|
WriteFile(h, u8.data(), (DWORD)u8.size(), &wr, nullptr);
|
||||||
|
CloseHandle(h);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::wstring ReadFileUtf8(const std::wstring& path) {
|
||||||
|
HANDLE h = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
|
||||||
|
if (h == INVALID_HANDLE_VALUE) return L"";
|
||||||
|
DWORD size = GetFileSize(h, nullptr), rd = 0;
|
||||||
|
std::string u8(size, '\0');
|
||||||
|
if (size) ReadFile(h, &u8[0], size, &rd, nullptr);
|
||||||
|
CloseHandle(h);
|
||||||
|
size_t off = (u8.size() >= 3 && (unsigned char)u8[0]==0xEF && (unsigned char)u8[1]==0xBB && (unsigned char)u8[2]==0xBF) ? 3 : 0;
|
||||||
|
int n = MultiByteToWideChar(CP_UTF8, 0, u8.data()+off, (int)(u8.size()-off), nullptr, 0);
|
||||||
|
std::wstring w(n, L'\0');
|
||||||
|
if (n) MultiByteToWideChar(CP_UTF8, 0, u8.data()+off, (int)(u8.size()-off), &w[0], n);
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void PruneHistory(int keep) {
|
||||||
|
std::vector<std::wstring> files;
|
||||||
|
WIN32_FIND_DATAW fd;
|
||||||
|
HANDLE h = FindFirstFileW((HistoryDir() + L"\\*.txt").c_str(), &fd);
|
||||||
|
if (h == INVALID_HANDLE_VALUE) return;
|
||||||
|
do { files.push_back(HistoryDir() + L"\\" + fd.cFileName); } while (FindNextFileW(h, &fd));
|
||||||
|
FindClose(h);
|
||||||
|
std::sort(files.begin(), files.end());
|
||||||
|
for (int i = 0; i < (int)files.size() - keep; ++i) DeleteFileW(files[i].c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::wstring ArchiveSession(const std::wstring& text) {
|
||||||
|
bool any = false; for (wchar_t c : text) if (!iswspace(c)) { any = true; break; }
|
||||||
|
if (!any) return L"";
|
||||||
|
CreateDirectoryW(HistoryDir().c_str(), nullptr);
|
||||||
|
SYSTEMTIME t; GetLocalTime(&t);
|
||||||
|
wchar_t name[64];
|
||||||
|
swprintf_s(name, L"%04d-%02d-%02d_%02d%02d%02d.txt", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
|
||||||
|
std::wstring path = HistoryDir() + L"\\" + name;
|
||||||
|
WriteFileUtf8(path, text);
|
||||||
|
PruneHistory(100);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::vector<HistoryEntry> LoadHistoryIndex() {
|
||||||
|
std::vector<HistoryEntry> out;
|
||||||
|
WIN32_FIND_DATAW fd;
|
||||||
|
HANDLE h = FindFirstFileW((HistoryDir() + L"\\*.txt").c_str(), &fd);
|
||||||
|
if (h == INVALID_HANDLE_VALUE) return out;
|
||||||
|
do {
|
||||||
|
HistoryEntry e;
|
||||||
|
e.path = HistoryDir() + L"\\" + fd.cFileName;
|
||||||
|
std::wstring stem(fd.cFileName);
|
||||||
|
stem = stem.substr(0, stem.find(L'.'));
|
||||||
|
std::wstring preview = ReadFileUtf8(e.path).substr(0, 60);
|
||||||
|
for (wchar_t& c : preview) if (c == L'\r' || c == L'\n') c = L' ';
|
||||||
|
e.label = stem.substr(0, 10) + L" " + stem.substr(11, 2) + L":" + stem.substr(13, 2)
|
||||||
|
+ L" \u2014 " + preview + L"\u2026";
|
||||||
|
out.push_back(e);
|
||||||
|
} while (FindNextFileW(h, &fd));
|
||||||
|
FindClose(h);
|
||||||
|
std::sort(out.begin(), out.end(), [](auto& a, auto& b){ return a.path > b.path; });
|
||||||
|
return out;
|
||||||
|
}
|
||||||
+684
-91
File diff suppressed because it is too large
Load Diff
+60
@@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
#include <string>
|
||||||
|
#include <cwctype>
|
||||||
|
|
||||||
|
struct UsageStats {
|
||||||
|
double totalAudioSec = 0;
|
||||||
|
double totalProcSec = 0;
|
||||||
|
double totalWords = 0;
|
||||||
|
double totalClips = 0;
|
||||||
|
double longestClipSec = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline std::wstring StatsIniPath() {
|
||||||
|
wchar_t buf[MAX_PATH]; GetModuleFileNameW(nullptr, buf, MAX_PATH);
|
||||||
|
std::wstring p(buf); p = p.substr(0, p.find_last_of(L"\\/"));
|
||||||
|
return p + L"\\win-dictation.ini";
|
||||||
|
}
|
||||||
|
inline void StPut(const wchar_t* k, double v) {
|
||||||
|
wchar_t b[64]; swprintf_s(b, L"%.3f", v);
|
||||||
|
WritePrivateProfileStringW(L"stats", k, b, StatsIniPath().c_str());
|
||||||
|
}
|
||||||
|
inline double StGet(const wchar_t* k) {
|
||||||
|
wchar_t out[64];
|
||||||
|
GetPrivateProfileStringW(L"stats", k, L"0", out, 64, StatsIniPath().c_str());
|
||||||
|
return wcstod(out, nullptr);
|
||||||
|
}
|
||||||
|
inline void LoadStats(UsageStats& s) {
|
||||||
|
s.totalAudioSec = StGet(L"audioSec"); s.totalProcSec = StGet(L"procSec");
|
||||||
|
s.totalWords = StGet(L"words"); s.totalClips = StGet(L"clips");
|
||||||
|
s.longestClipSec= StGet(L"longest");
|
||||||
|
}
|
||||||
|
inline void SaveStats(const UsageStats& s) {
|
||||||
|
StPut(L"audioSec", s.totalAudioSec); StPut(L"procSec", s.totalProcSec);
|
||||||
|
StPut(L"words", s.totalWords); StPut(L"clips", s.totalClips);
|
||||||
|
StPut(L"longest", s.longestClipSec);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int CountWords(const std::wstring& s) {
|
||||||
|
int n = 0; bool in = false;
|
||||||
|
for (wchar_t c : s) { bool w = !iswspace(c); if (w && !in) ++n; in = w; }
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
inline void RecordUsage(UsageStats& st, double audioSec, double procSec, const std::wstring& text) {
|
||||||
|
st.totalAudioSec += audioSec;
|
||||||
|
st.totalProcSec += procSec;
|
||||||
|
st.totalWords += CountWords(text);
|
||||||
|
st.totalClips += 1;
|
||||||
|
if (audioSec > st.longestClipSec) st.longestClipSec = audioSec;
|
||||||
|
SaveStats(st);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::wstring FormatHMS(double sec) {
|
||||||
|
int s = (int)(sec + 0.5), h = s / 3600, m = (s % 3600) / 60; s %= 60;
|
||||||
|
wchar_t b[64];
|
||||||
|
if (h) swprintf_s(b, L"%dh %dm", h, m);
|
||||||
|
else if (m) swprintf_s(b, L"%dm %ds", m, s);
|
||||||
|
else swprintf_s(b, L"%ds", s);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
@@ -0,0 +1,520 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Win Dictation — Architecture & Engineering Review</title>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#0E1014; --card:#16191F; --card-hi:#1E222B; --card-lo:#12151B;
|
||||||
|
--text:#ECEEF2; --dim:#8A909C; --faint:#5A606C;
|
||||||
|
--accent:#6E8BFF; --accent-hi:#839CFF; --danger:#FF5C5C; --good:#46D39A; --warn:#E8B84B;
|
||||||
|
--border:#262B36; --hair:rgba(255,255,255,.06);
|
||||||
|
--mono:'JetBrains Mono',ui-monospace,SFMono-Regular,Menlo,monospace;
|
||||||
|
--sans:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
html{scroll-behavior:smooth}
|
||||||
|
body{margin:0; background:var(--bg); color:var(--text); font-family:var(--sans);
|
||||||
|
font-size:16.5px; line-height:1.72; -webkit-font-smoothing:antialiased; letter-spacing:.1px}
|
||||||
|
.wrap{max-width:960px; margin:0 auto; padding:0 6vw 140px}
|
||||||
|
a{color:var(--accent-hi); text-decoration:none} a:hover{text-decoration:underline}
|
||||||
|
|
||||||
|
.hero{padding:88px 0 34px; border-bottom:1px solid var(--border); margin-bottom:50px}
|
||||||
|
.eyebrow{font-family:var(--mono); font-size:12.5px; letter-spacing:.32em; text-transform:uppercase; color:var(--accent); margin:0 0 22px}
|
||||||
|
h1{font-size:clamp(32px,5.6vw,52px); line-height:1.05; margin:0; font-weight:800; letter-spacing:-1.2px; max-width:840px}
|
||||||
|
.sub{font-size:20px; color:var(--dim); max-width:720px; margin:20px 0 0; font-weight:400}
|
||||||
|
.metarow{display:flex; flex-wrap:wrap; gap:10px; margin-top:30px}
|
||||||
|
.chip{font-family:var(--mono); font-size:12.5px; color:var(--dim); background:var(--card); border:1px solid var(--border); border-radius:999px; padding:7px 15px}
|
||||||
|
.chip b{color:var(--text); font-weight:600}
|
||||||
|
|
||||||
|
.toc{background:linear-gradient(180deg,var(--card),var(--card-lo)); border:1px solid var(--border); border-radius:18px; padding:30px 34px; margin-bottom:60px}
|
||||||
|
.toc h4{margin:0 0 18px; font-family:var(--mono); font-size:12px; letter-spacing:.28em; text-transform:uppercase; color:var(--faint)}
|
||||||
|
.toc ol{margin:0; padding:0; list-style:none; counter-reset:t; columns:2; column-gap:46px}
|
||||||
|
.toc li{counter-increment:t; padding:7px 0; break-inside:avoid}
|
||||||
|
.toc li a{color:var(--text); font-weight:500; font-size:15.5px}
|
||||||
|
.toc li a::before{content:counter(t,decimal-leading-zero); font-family:var(--mono); color:var(--accent); font-size:12px; margin-right:13px; font-weight:600}
|
||||||
|
|
||||||
|
section{margin:0 0 72px; scroll-margin-top:30px}
|
||||||
|
.sec-h{display:flex; align-items:baseline; gap:16px; margin:0 0 10px}
|
||||||
|
.sec-n{font-family:var(--mono); font-size:14px; color:var(--accent); font-weight:600; flex:none}
|
||||||
|
h2{font-size:29px; font-weight:700; margin:0; letter-spacing:-.5px}
|
||||||
|
h3{font-size:19px; font-weight:650; margin:38px 0 12px; letter-spacing:-.2px}
|
||||||
|
.lead{color:var(--dim); font-size:18px; margin:0 0 26px; max-width:740px}
|
||||||
|
p{margin:0 0 17px} .muted{color:var(--dim)} strong{color:#fff; font-weight:650}
|
||||||
|
ul,ol{margin:0 0 18px; padding-left:22px} li{margin:9px 0}
|
||||||
|
|
||||||
|
code{font-family:var(--mono); font-size:14px; background:var(--card-hi); color:#cfe0ff; padding:2px 7px; border-radius:6px; border:1px solid var(--border)}
|
||||||
|
.path{font-family:var(--mono); font-size:13.5px; color:var(--good)}
|
||||||
|
pre{background:var(--card-lo); border:1px solid var(--border); border-radius:13px; padding:20px 22px; overflow-x:auto; margin:20px 0;
|
||||||
|
font-family:var(--mono); font-size:13.5px; line-height:1.7; color:#c8d2e0}
|
||||||
|
pre .c{color:var(--faint)} pre .k{color:#c98bff} pre .s{color:var(--good)} pre .n{color:var(--accent-hi)} pre .f{color:#ffd479}
|
||||||
|
|
||||||
|
/* verdict box */
|
||||||
|
.verdict{background:linear-gradient(135deg,rgba(110,139,255,.12),rgba(70,211,154,.06)); border:1px solid var(--border);
|
||||||
|
border-radius:18px; padding:30px 34px; margin:6px 0 10px; position:relative; overflow:hidden}
|
||||||
|
.verdict::before{content:""; position:absolute; left:0; top:0; bottom:0; width:4px; background:linear-gradient(180deg,var(--accent),var(--good))}
|
||||||
|
.verdict .vh{font-family:var(--mono); font-size:11.5px; letter-spacing:.2em; text-transform:uppercase; color:var(--accent); margin:0 0 12px}
|
||||||
|
.verdict p{font-size:18.5px; line-height:1.66; margin:0 0 14px; color:var(--text)}
|
||||||
|
.verdict p:last-child{margin:0}
|
||||||
|
.verdict .big{font-size:22px; font-weight:700; letter-spacing:-.3px}
|
||||||
|
|
||||||
|
/* pipeline */
|
||||||
|
.pipe{display:flex; flex-wrap:wrap; align-items:stretch; gap:0; margin:26px 0; border:1px solid var(--border); border-radius:14px; overflow:hidden; background:var(--card-lo)}
|
||||||
|
.stage{flex:1 1 120px; min-width:120px; padding:18px 16px; border-right:1px solid var(--border); position:relative}
|
||||||
|
.stage:last-child{border-right:0}
|
||||||
|
.stage .si{font-family:var(--mono); font-size:11px; color:var(--faint); margin:0 0 8px}
|
||||||
|
.stage .sn{font-weight:650; font-size:14.5px; margin:0 0 4px; color:var(--text)}
|
||||||
|
.stage .sd{font-size:12.5px; color:var(--dim); line-height:1.5; margin:0}
|
||||||
|
.stage.hot{background:linear-gradient(180deg,rgba(110,139,255,.1),transparent)}
|
||||||
|
.stage.work{background:linear-gradient(180deg,rgba(70,211,154,.1),transparent)}
|
||||||
|
|
||||||
|
.tbl{width:100%; border-collapse:collapse; margin:20px 0; font-size:14.5px; border-radius:12px; overflow:hidden; border:1px solid var(--border)}
|
||||||
|
.tbl th{text-align:left; font-family:var(--mono); font-size:11px; letter-spacing:.1em; text-transform:uppercase; color:var(--dim); padding:12px 15px; background:var(--card-lo); border-bottom:1px solid var(--border); font-weight:600}
|
||||||
|
.tbl td{padding:12px 15px; border-bottom:1px solid var(--border); vertical-align:top}
|
||||||
|
.tbl tr:last-child td{border-bottom:0}
|
||||||
|
.tbl td code{font-size:13px}
|
||||||
|
.tbl .r{color:var(--dim); font-size:13.5px}
|
||||||
|
|
||||||
|
.note{border:1px solid var(--border); border-left:3px solid var(--accent); background:linear-gradient(90deg,rgba(110,139,255,.08),transparent 60%); border-radius:12px; padding:17px 20px; margin:22px 0}
|
||||||
|
.note.warn{border-left-color:var(--warn); background:linear-gradient(90deg,rgba(232,184,75,.09),transparent 60%)}
|
||||||
|
.note.bad{border-left-color:var(--danger); background:linear-gradient(90deg,rgba(255,92,92,.08),transparent 60%)}
|
||||||
|
.note.good{border-left-color:var(--good); background:linear-gradient(90deg,rgba(70,211,154,.08),transparent 60%)}
|
||||||
|
.note .nt{font-family:var(--mono); font-size:11.5px; letter-spacing:.18em; text-transform:uppercase; color:var(--dim); margin:0 0 6px}
|
||||||
|
.note p:last-child{margin:0}
|
||||||
|
|
||||||
|
/* assessment cards */
|
||||||
|
.assess{display:grid; gap:14px; margin:22px 0}
|
||||||
|
.ac{border:1px solid var(--border); border-radius:13px; padding:18px 20px; background:var(--card)}
|
||||||
|
.ac .ah{display:flex; align-items:center; gap:11px; margin:0 0 7px}
|
||||||
|
.ac .dot{width:9px;height:9px;border-radius:50%; flex:none}
|
||||||
|
.ac.pos .dot{background:var(--good)} .ac.neg .dot{background:var(--danger)} .ac.neu .dot{background:var(--warn)}
|
||||||
|
.ac h4{margin:0; font-size:16.5px; font-weight:650}
|
||||||
|
.ac p{margin:0; color:var(--dim); font-size:14.5px; line-height:1.62}
|
||||||
|
.ac .ref{font-family:var(--mono); font-size:12px; color:var(--faint); margin-top:7px}
|
||||||
|
|
||||||
|
/* scorecard */
|
||||||
|
.score{background:var(--card); border:1px solid var(--border); border-radius:16px; padding:28px 30px; margin:24px 0}
|
||||||
|
.srow{display:grid; grid-template-columns:200px 1fr 50px; align-items:center; gap:18px; padding:11px 0; border-bottom:1px solid var(--border)}
|
||||||
|
.srow:last-child{border-bottom:0}
|
||||||
|
.srow .sl{font-size:14.5px; font-weight:500}
|
||||||
|
.srow .sb{height:9px; background:var(--card-hi); border-radius:99px; overflow:hidden}
|
||||||
|
.srow .sf{height:100%; border-radius:99px; background:linear-gradient(90deg,var(--accent),var(--accent-hi))}
|
||||||
|
.srow .sf.hi{background:linear-gradient(90deg,#46D39A,#6ee0b0)}
|
||||||
|
.srow .sf.lo{background:linear-gradient(90deg,#E8B84B,#f0cd77)}
|
||||||
|
.srow .sf.vlo{background:linear-gradient(90deg,#FF5C5C,#ff8585)}
|
||||||
|
.srow .sv{font-family:var(--mono); font-size:14px; font-weight:600; text-align:right; color:var(--text)}
|
||||||
|
.overall{display:flex; align-items:baseline; gap:16px; margin-top:22px; padding-top:22px; border-top:1px solid var(--border)}
|
||||||
|
.overall .num{font-size:46px; font-weight:800; letter-spacing:-2px; color:var(--accent-hi); font-family:var(--mono)}
|
||||||
|
.overall .ot{color:var(--dim); font-size:15px}
|
||||||
|
|
||||||
|
/* recommendations */
|
||||||
|
.rec{counter-reset:r; margin:22px 0; padding:0; list-style:none}
|
||||||
|
.rec li{counter-increment:r; position:relative; padding:16px 18px 16px 60px; margin:0 0 12px; background:var(--card); border:1px solid var(--border); border-radius:12px}
|
||||||
|
.rec li::before{content:counter(r); position:absolute; left:16px; top:16px; width:30px;height:30px;border-radius:9px; background:var(--card-hi); color:var(--accent); font-family:var(--mono); font-weight:700; display:flex; align-items:center; justify-content:center; font-size:14px}
|
||||||
|
.rec h4{margin:0 0 4px; font-size:16px; font-weight:650}
|
||||||
|
.rec p{margin:0; color:var(--dim); font-size:14.5px}
|
||||||
|
.pri{font-family:var(--mono); font-size:10.5px; letter-spacing:.1em; text-transform:uppercase; padding:2px 8px; border-radius:5px; margin-left:9px; vertical-align:middle}
|
||||||
|
.pri.hi{background:rgba(255,92,92,.16); color:var(--danger)}
|
||||||
|
.pri.md{background:rgba(232,184,75,.16); color:var(--warn)}
|
||||||
|
.pri.lo{background:rgba(138,144,156,.16); color:var(--dim)}
|
||||||
|
|
||||||
|
.stackgrid{display:grid; grid-template-columns:repeat(2,1fr); gap:14px; margin:22px 0}
|
||||||
|
.scell{background:var(--card); border:1px solid var(--border); border-radius:12px; padding:16px 18px}
|
||||||
|
.scell .sk{font-family:var(--mono); font-size:11px; letter-spacing:.12em; text-transform:uppercase; color:var(--faint); margin:0 0 6px}
|
||||||
|
.scell .sv{font-size:15px; color:var(--text); font-weight:500}
|
||||||
|
.scell .sv span{color:var(--dim); font-weight:400; font-size:13.5px}
|
||||||
|
|
||||||
|
.footer{border-top:1px solid var(--border); margin-top:80px; padding-top:30px; color:var(--faint); font-size:13.5px; font-family:var(--mono)}
|
||||||
|
.footer b{color:var(--dim); font-weight:500}
|
||||||
|
|
||||||
|
@media(max-width:680px){
|
||||||
|
.toc ol,.stackgrid{columns:1; grid-template-columns:1fr}
|
||||||
|
.srow{grid-template-columns:1fr; gap:6px}
|
||||||
|
.srow .sv{text-align:left}
|
||||||
|
.pipe .stage{flex-basis:100%; border-right:0; border-bottom:1px solid var(--border)}
|
||||||
|
body{font-size:16px}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<style>
|
||||||
|
.ha-img-placeholder{display:flex;align-items:center;justify-content:center;flex-direction:column;gap:6px;background:#f4f4f5;border:1px dashed #d4d4d8;border-radius:8px;color:#71717a;font-size:12px;font-family:system-ui,sans-serif;min-height:80px;padding:16px;box-sizing:border-box;animation:ha-img-pulse 1.5s ease-in-out infinite}
|
||||||
|
.ha-img-placeholder.ha-failed{animation:none;opacity:.7}
|
||||||
|
@keyframes ha-img-pulse{0%,100%{opacity:1}50%{opacity:.5}}
|
||||||
|
@media(prefers-color-scheme:dark){.ha-img-placeholder{background:#27272a;border-color:#3f3f46;color:#a1a1aa}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="wrap">
|
||||||
|
|
||||||
|
<header class="hero">
|
||||||
|
<p class="eyebrow">Architecture · Code Analysis · Engineering Verdict</p>
|
||||||
|
<h1>Win Dictation: under the hood</h1>
|
||||||
|
<p class="sub">A guided walk through a native Win32 C++ speech-to-text app — how it's built, why it's built that way, and an honest assessment of the code for anyone picking it up for the first time.</p>
|
||||||
|
<div class="metarow">
|
||||||
|
<span class="chip"><b>~3,400</b> lines C++ (app)</span>
|
||||||
|
<span class="chip"><b>Win32</b> + GDI+ + SDL2 + whisper.cpp</span>
|
||||||
|
<span class="chip"><b>Single .exe</b>, no runtime deps</span>
|
||||||
|
<span class="chip"><b>Target</b> 2-core i5, CPU-only</span>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<nav class="toc">
|
||||||
|
<h4>Contents</h4>
|
||||||
|
<ol>
|
||||||
|
<li><a href="#tldr">The verdict, up front</a></li>
|
||||||
|
<li><a href="#stack">Stack at a glance</a></li>
|
||||||
|
<li><a href="#arch">Architecture & data flow</a></li>
|
||||||
|
<li><a href="#decision">The defining decision</a></li>
|
||||||
|
<li><a href="#threads">Threading model</a></li>
|
||||||
|
<li><a href="#map">Source map, file by file</a></li>
|
||||||
|
<li><a href="#ui">Deep dive: the UI engine</a></li>
|
||||||
|
<li><a href="#timing">Deep dive: the progress estimator</a></li>
|
||||||
|
<li><a href="#transcriber">Deep dive: the transcriber</a></li>
|
||||||
|
<li><a href="#persistence">History, downloads & persistence</a></li>
|
||||||
|
<li><a href="#anatomy">Anatomy of one dictation</a></li>
|
||||||
|
<li><a href="#strengths">What's done well</a></li>
|
||||||
|
<li><a href="#weaknesses">What holds it back</a></li>
|
||||||
|
<li><a href="#recs">Recommendations</a></li>
|
||||||
|
<li><a href="#scorecard">Scorecard & final word</a></li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- 1 -->
|
||||||
|
<section id="tldr">
|
||||||
|
<div class="sec-h"><span class="sec-n">01</span><h2>The verdict, up front</h2></div>
|
||||||
|
<div class="verdict">
|
||||||
|
<p class="vh">Bottom line</p>
|
||||||
|
<p class="big">A genuinely strong, characterful single-purpose tool that punches well above hobby grade.</p>
|
||||||
|
<p>The hard engineering — the architecture choice, the self-calibrating progress estimator, the seam-free single-surface renderer — is thoughtful and well-executed. The app does exactly one thing and does it well on hardware most tools would choke on.</p>
|
||||||
|
<p>What holds it back is <strong>organizational debt, not algorithmic weakness</strong>: a 1,500-line <code>main.cpp</code>, a layer of vestigial child-window controls left over from an earlier design, and a pile of stale documentation that describes a GPU-streaming app this no longer is. None of it breaks the running product — but all of it raises the cost of the next person walking in.</p>
|
||||||
|
</div>
|
||||||
|
<p class="muted">The sections below back up every part of that judgement with specifics from the source.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 2 -->
|
||||||
|
<section id="stack">
|
||||||
|
<div class="sec-h"><span class="sec-n">02</span><h2>Stack at a glance</h2></div>
|
||||||
|
<p class="lead">Deliberately lean. No UI framework, no managed runtime, no garbage collector — just the OS and three libraries.</p>
|
||||||
|
<div class="stackgrid">
|
||||||
|
<div class="scell"><p class="sk">Language</p><p class="sv">C++ <span>(MSVC, Release /O2 /GL /LTCG, AVX2/FMA/F16C)</span></p></div>
|
||||||
|
<div class="scell"><p class="sk">UI</p><p class="sv">Raw Win32 + GDI+ <span>immediate-mode painted surface</span></p></div>
|
||||||
|
<div class="scell"><p class="sk">Audio capture</p><p class="sv">SDL2 <span>16 kHz mono, F32</span></p></div>
|
||||||
|
<div class="scell"><p class="sk">Inference</p><p class="sv">whisper.cpp <span>whisper_full, CPU backend</span></p></div>
|
||||||
|
<div class="scell"><p class="sk">Networking</p><p class="sv">WinHTTP <span>model downloads, system proxy aware</span></p></div>
|
||||||
|
<div class="scell"><p class="sk">Persistence</p><p class="sv">Plain INI + UTF-8 text files <span>no database</span></p></div>
|
||||||
|
<div class="scell"><p class="sk">Build</p><p class="sv">CMake <span>+ a PowerShell convenience script</span></p></div>
|
||||||
|
<div class="scell"><p class="sk">Footprint</p><p class="sv">One .exe + a few DLLs + model <span>tiny RAM, no install</span></p></div>
|
||||||
|
</div>
|
||||||
|
<p>The whole product is native code with no framework abstraction between it and the Win32 API. That's the source of both its biggest strength (a tiny, fast, dependency-light binary) and its biggest cost (everything is hand-rolled, including the widgets).</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 3 -->
|
||||||
|
<section id="arch">
|
||||||
|
<div class="sec-h"><span class="sec-n">03</span><h2>Architecture & data flow</h2></div>
|
||||||
|
<p class="lead">A linear pipeline with a single inference step. Audio in, text out, no streaming loop.</p>
|
||||||
|
<div class="pipe">
|
||||||
|
<div class="stage hot"><p class="si">trigger</p><p class="sn">Hotkey</p><p class="sd">Global <code>RegisterHotKey</code>. Captures the previously focused window.</p></div>
|
||||||
|
<div class="stage"><p class="si">capture</p><p class="sn">SDL2 mic</p><p class="sd">16 kHz mono into an in-memory buffer. Near-zero CPU.</p></div>
|
||||||
|
<div class="stage"><p class="si">buffer</p><p class="sn">PCM in RAM</p><p class="sd">Accumulated under a mutex; RMS energy tracked for the meter.</p></div>
|
||||||
|
<div class="stage work"><p class="si">inference</p><p class="sn">whisper_full</p><p class="sd">One pass on a worker thread when you stop. Trim → transcribe → clean.</p></div>
|
||||||
|
<div class="stage"><p class="si">deliver</p><p class="sn">Insert + paste</p><p class="sd">Text to caret, to clipboard, into the prior window.</p></div>
|
||||||
|
</div>
|
||||||
|
<p>Two side channels run alongside the main pipeline: a <strong>progress estimator</strong> that predicts and smooths the transcription countdown, and a <strong>timing model</strong> that learns this machine's speed and feeds back into the next prediction. Results return to the UI thread exclusively via <code>PostMessage</code>; shared flags are <code>std::atomic</code>.</p>
|
||||||
|
<div class="note">
|
||||||
|
<p class="nt">Mental model</p>
|
||||||
|
<p>Think of it as a tape recorder with a transcription button, not a live captioner. The architecture has no per-frame transcription loop at all — which, on a 2-core CPU, is the whole point.</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 4 -->
|
||||||
|
<section id="decision">
|
||||||
|
<div class="sec-h"><span class="sec-n">04</span><h2>The defining decision</h2></div>
|
||||||
|
<p class="lead">The single most important thing to understand: this app was rebuilt from a live-streaming design into a push-to-talk batch design — and that was the right call.</p>
|
||||||
|
<p>An earlier version used the classic whisper.cpp streaming approach: a rolling 5–6 second window re-transcribed every ~0.4 seconds. That technique <em>assumes</em> spare cores. On the target machine — an Intel i5-7th-gen with two physical cores — the buffer backlogged, audio was re-transcribed, and the UI starved. The symptom looked like "the model is slow"; the real cause was an architecture that needed hardware the target didn't have.</p>
|
||||||
|
<p>The fix wasn't a faster model. It was removing the streaming loop entirely:</p>
|
||||||
|
<table class="tbl">
|
||||||
|
<tr><th>Aspect</th><th>Old: streaming window</th><th>New: push-to-talk batch</th></tr>
|
||||||
|
<tr><td>CPU while speaking</td><td class="r">Pinned — constant re-inference</td><td>Near idle — just buffering</td></tr>
|
||||||
|
<tr><td>Inference calls</td><td class="r">Many per second</td><td>Exactly one, on stop</td></tr>
|
||||||
|
<tr><td>Accuracy</td><td class="r">Lower — partial context windows</td><td>Higher — full clip, full context</td></tr>
|
||||||
|
<tr><td>UI responsiveness</td><td class="r">Starved under load</td><td>Free until the single pass</td></tr>
|
||||||
|
<tr><td>Predictability</td><td class="r">Variable lag</td><td>Predictable few-second wait</td></tr>
|
||||||
|
</table>
|
||||||
|
<p>This is textbook root-cause engineering: the team correctly diagnosed that the bottleneck was the <em>shape</em> of the work, not its size, and changed the shape. Everything else in the codebase — the batch worker, the progress estimator, the physical-core thread default — follows from this one decision.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 5 -->
|
||||||
|
<section id="threads">
|
||||||
|
<div class="sec-h"><span class="sec-n">05</span><h2>Threading model</h2></div>
|
||||||
|
<p class="lead">Four threads, one rule: only the UI thread touches the UI. Everything else reports back by message.</p>
|
||||||
|
<table class="tbl">
|
||||||
|
<tr><th>Thread</th><th>Lifetime</th><th>Job</th></tr>
|
||||||
|
<tr><td><b>UI thread</b></td><td class="r">Whole app</td><td>Message loop, all painting, the 16 ms animation timer and 50 ms update timer.</td></tr>
|
||||||
|
<tr><td><b>Model preload</b></td><td class="r">Detached, once</td><td>Loads the Whisper context off the UI thread at startup so the window appears instantly.</td></tr>
|
||||||
|
<tr><td><b>Transcribe worker</b></td><td class="r">Per clip</td><td>Runs <code>whisper_full</code>; posts <code>WM_APP_PROGRESS</code> during and <code>WM_APP_RESULT</code> when done.</td></tr>
|
||||||
|
<tr><td><b>Downloader</b></td><td class="r">Per download</td><td>WinHTTP fetch on its own thread; posts <code>WM_APP_DLPROGRESS</code>.</td></tr>
|
||||||
|
</table>
|
||||||
|
<p>Cross-thread state is handled with discipline rather than locks where possible: <code>std::atomic</code> booleans (<code>m_recording</code>, <code>m_busy</code>, <code>m_abort</code>, <code>g_modelLoaded</code>, <code>g_modelOk</code>) gate state transitions, and the only shared buffer — the captured PCM — is protected by a dedicated mutex. The audio callback (driven by SDL's own thread) appends under that mutex; <code>stop_and_transcribe</code> swaps the buffer out under the same lock before handing it to the worker. That swap-not-copy handoff is a nice touch.</p>
|
||||||
|
<pre><span class="c">// transcriber.cpp — physical cores, not logical, by design</span>
|
||||||
|
<span class="k">int</span> Transcriber::<span class="f">default_threads</span>() {
|
||||||
|
<span class="k">unsigned</span> hc = std::thread::<span class="f">hardware_concurrency</span>();
|
||||||
|
<span class="k">if</span> (hc <= 2) <span class="k">return</span> (<span class="k">int</span>)std::<span class="f">max</span>(1u, hc);
|
||||||
|
<span class="k">return</span> (<span class="k">int</span>)(hc / 2); <span class="c">// 4 logical → 2 worker threads</span>
|
||||||
|
}</pre>
|
||||||
|
<p>Defaulting to physical cores rather than <code>hardware_concurrency()</code> is the correct choice for compute-bound SIMD inference — hyperthreads contend for the same execution units and would only add scheduling overhead.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 6 -->
|
||||||
|
<section id="map">
|
||||||
|
<div class="sec-h"><span class="sec-n">06</span><h2>Source map, file by file</h2></div>
|
||||||
|
<p class="lead">The app is small and mostly header-only outside the two big translation units. Here's where everything lives.</p>
|
||||||
|
<table class="tbl">
|
||||||
|
<tr><th>File</th><th>Role</th><th>Notes</th></tr>
|
||||||
|
<tr><td><code>main.cpp</code></td><td>Window, painting, interaction, settings view, clipboard, paste, model selection, popups</td><td class="r">~1,500 lines. The monolith — see §13.</td></tr>
|
||||||
|
<tr><td><code>transcriber.{h,cpp}</code></td><td>SDL capture, Whisper preload/inference, progress & abort callbacks</td><td class="r">Clean, well-scoped class. The model layer.</td></tr>
|
||||||
|
<tr><td><code>timing.h</code></td><td>Per-model least-squares timing model + live progress estimator + INI persistence</td><td class="r">The standout module. See §08.</td></tr>
|
||||||
|
<tr><td><code>history.h</code></td><td>Session text files, UTF-8 r/w with BOM, index, pruning to 100</td><td class="r">Self-contained, header-only.</td></tr>
|
||||||
|
<tr><td><code>downloader.h</code></td><td>WinHTTP model downloader on a background thread</td><td class="r">.part + atomic rename, cancel, proxy-aware.</td></tr>
|
||||||
|
<tr><td><code>stats.h</code></td><td>Lifetime usage totals + derived figures (wpm, real-time factor, time saved)</td><td class="r">INI-backed, header-only.</td></tr>
|
||||||
|
<tr><td><code>settings.h</code></td><td>App settings read/write via <code>GetPrivateProfile*</code></td><td class="r">Simple and transparent.</td></tr>
|
||||||
|
<tr><td><code>text_util.h</code> · <code>logging.h</code></td><td>Transcript concatenation; timestamped file log</td><td class="r">Tiny helpers.</td></tr>
|
||||||
|
<tr><td><code>tests/test_core.cpp</code></td><td>Unit checks: append logic, bad-model handling, real-WAV transcription, progress monotonicity</td><td class="r">Modest but meaningful. Built as <code>test-core</code>.</td></tr>
|
||||||
|
</table>
|
||||||
|
<p>The decision to make most subsystems <strong>header-only and independent</strong> (<code>timing.h</code>, <code>stats.h</code>, <code>history.h</code>, <code>downloader.h</code>, <code>settings.h</code>) is a good one for a project this size: each is cohesive, individually readable, and free of cross-dependencies. The contrast with <code>main.cpp</code> — which absorbs everything else — is stark.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 7 -->
|
||||||
|
<section id="ui">
|
||||||
|
<div class="sec-h"><span class="sec-n">07</span><h2>Deep dive: the single-surface UI engine</h2></div>
|
||||||
|
<p class="lead">There are no buttons. Everything you see is painted onto one double-buffered surface — and that's a deliberate fix, not a shortcut.</p>
|
||||||
|
<p>The previous UI composited around nine separate themed child windows (buttons, statics, an edit). That produced thin hairline seams around every control — the hard-edged holes <code>WS_CLIPCHILDREN</code> punches per child, plus the edit's themed border. Rather than chase pixel borders, the rebuild eliminated the cause: <strong>collapse the controls into one painted region.</strong></p>
|
||||||
|
<p>The model is a small immediate-mode system:</p>
|
||||||
|
<ul>
|
||||||
|
<li>A flat <code>Widget g_w[]</code> array — each entry is a <em>kind</em>, a rectangle, and <code>hover/pressed/anim</code> state. No HWNDs.</li>
|
||||||
|
<li><code>LayoutWidgets()</code> positions them; <code>PaintSurface()</code> draws each into an off-screen DC with GDI+, then blits once (no flicker).</li>
|
||||||
|
<li><code>HitTest()</code> maps a click point to a widget; <code>OnClick()</code> dispatches the action.</li>
|
||||||
|
<li>An animation clock eases each widget's <code>anim</code> toward a target (hover 0.6, active 1.0) on a 16 ms timer that <em>stops itself</em> when nothing is moving — no idle CPU burn.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Two "views" — Main and Settings — render onto the same surface, toggled by <code>SwitchView()</code>. Dropdowns (mic, history) are the one exception: they're real top-level <code>WS_POPUP</code> windows, because a surface-painted dropdown would render <em>behind</em> the transcript edit (a child HWND always paints above its parent's surface). That's a correct, well-reasoned exception.</p>
|
||||||
|
<div class="note good">
|
||||||
|
<p class="nt">A sign of maturity</p>
|
||||||
|
<p>The popup code carries a comment never to open a <code>MessageBox</code> from inside it — because <code>WA_INACTIVE</code> self-destroys the popup mid-handler, causing a use-after-free. Recognising that class of Win32 lifetime bug, and the GDI+ "<code>GetHDC</code> locks the Graphics object" trap documented elsewhere, shows real depth.</p>
|
||||||
|
</div>
|
||||||
|
<p>The one real child window that survives is the transcript <code>EDIT</code> — kept because a hand-rolled text editor with selection, scrolling, IME and undo is genuinely not worth rebuilding. Pragmatic.</p>
|
||||||
|
<h3>The cost of this approach</h3>
|
||||||
|
<p>Custom-painted controls are invisible to screen readers and UI Automation, and the app explicitly hides focus rectangles. The transcript box is accessible; the buttons are not. For a personal productivity tool this is a defensible trade, but it's the kind of thing worth stating out loud.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 8 -->
|
||||||
|
<section id="timing">
|
||||||
|
<div class="sec-h"><span class="sec-n">08</span><h2>Deep dive: the progress estimator</h2></div>
|
||||||
|
<p class="lead">The crown jewel. Most apps fake a progress bar; this one runs a small statistical model that learns your machine.</p>
|
||||||
|
<p>Whisper only reports coarse progress (per 30-second chunk), so a naive bar jumps — 0, 34, 72, 100 — and a naive "time left" computed from stale percentages actually counts <em>up</em>. <code>timing.h</code> solves both. It has two parts.</p>
|
||||||
|
<h3>1 — A learned timing model</h3>
|
||||||
|
<p>Processing time is modelled as a linear function of audio length, <code>proc = a + b·audio</code>, fitted by <strong>decayed online least-squares</strong>. Each completed transcription feeds back a real sample; older samples decay (factor 0.97) so the model tracks the current machine state. Defaults are seeded per model family (tiny/base/small) so even the very first clip has a sane estimate, and the accumulators persist per-model in the INI.</p>
|
||||||
|
<pre><span class="k">void</span> <span class="f">add_sample</span>(<span class="k">double</span> audio_sec, <span class="k">double</span> proc_sec) {
|
||||||
|
<span class="k">const double</span> decay = <span class="n">0.97</span>;
|
||||||
|
n*=decay; sx*=decay; sy*=decay; sxx*=decay; sxy*=decay;
|
||||||
|
n+=<span class="n">1</span>; sx+=audio_sec; sy+=proc_sec;
|
||||||
|
sxx+=audio_sec*audio_sec; sxy+=audio_sec*proc_sec;
|
||||||
|
<span class="f">recompute</span>(); <span class="c">// closed-form slope/intercept</span>
|
||||||
|
}</pre>
|
||||||
|
<h3>2 — A live estimator that only counts down</h3>
|
||||||
|
<p>On stop, <code>begin(predict)</code> seeds a predicted total. As Whisper reports chunk progress, <code>on_whisper()</code> folds it in as a <em>measurement</em> via an EMA (α = 0.5) — nudging the estimate without the jumpy jumps. Meanwhile <code>tick()</code> advances a displayed "remaining" value that is <strong>strictly monotonic downward</strong>, with a clamped catch-up rate so it can speed up but never lurch backward, easing to 95% and snapping to 100% only on the real result.</p>
|
||||||
|
<pre><span class="k">void</span> <span class="f">tick</span>(<span class="k">double</span> dt, <span class="k">float</span>& out_frac, <span class="k">float</span>& out_remaining) {
|
||||||
|
t += dt; disp_rem -= dt;
|
||||||
|
<span class="k">double</span> raw_rem = std::<span class="f">max</span>(<span class="n">0.0</span>, T_hat - t);
|
||||||
|
<span class="k">double</span> err = raw_rem - disp_rem;
|
||||||
|
<span class="k">if</span> (err < <span class="n">0</span>) disp_rem += std::<span class="f">max</span>(err, -maxCatchUp*dt); <span class="c">// catch up, never jump back</span>
|
||||||
|
<span class="k">double</span> frac = t/(t+disp_rem);
|
||||||
|
<span class="k">if</span> (frac > <span class="n">0.95</span>) frac = <span class="n">0.95</span>; <span class="c">// park at 95% until done</span>
|
||||||
|
out_frac = (<span class="k">float</span>)frac; out_remaining = (<span class="k">float</span>)disp_rem;
|
||||||
|
}</pre>
|
||||||
|
<p>This is more thought than most commercial apps put into a progress bar, and the test suite even asserts the progress is non-decreasing. It's the clearest signal in the codebase that someone cared about the <em>feel</em> of the product, not just its function.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 9 -->
|
||||||
|
<section id="transcriber">
|
||||||
|
<div class="sec-h"><span class="sec-n">09</span><h2>Deep dive: the transcriber</h2></div>
|
||||||
|
<p class="lead">The cleanest class in the project — a tidy boundary between the OS/model and the rest of the app.</p>
|
||||||
|
<p><code>Transcriber</code> owns the Whisper context and the SDL device, and exposes a small, sensible surface: <code>preload</code>, <code>reload</code>, <code>start_recording</code>, <code>stop_and_transcribe</code>, <code>cancel</code>, plus state queries and two callbacks (<code>result</code>, <code>progress</code>). Inference parameters are configured sensibly for dictation — greedy sampling, no timestamps, no prior context, blank/non-speech suppression, temperature 0 — and an <code>abort_callback</code> lets a long transcription be cancelled mid-flight.</p>
|
||||||
|
<p>Two small details worth calling out:</p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Silence trimming.</strong> Before inference, leading/trailing silence is trimmed from the clip — cheaper and more accurate than transcribing dead air. (Note: this trims the <em>buffer</em>; it does not auto-stop recording — see the doc-drift note in §13.)</li>
|
||||||
|
<li><strong>Output cleanup.</strong> <code>clean_text()</code> strips Whisper's <code>[BLANK_AUDIO]</code> / <code>[NOISE]</code> artifacts and trims whitespace, so the user never sees model noise.</li>
|
||||||
|
</ul>
|
||||||
|
<p>The class is also defensively coded: a missing model file makes <code>preload</code> return false cleanly (the test suite verifies this), <code>start_recording</code> bails if a device won't open, and clips under ~0.3 s short-circuit to an empty result rather than invoking the model.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 10 -->
|
||||||
|
<section id="persistence">
|
||||||
|
<div class="sec-h"><span class="sec-n">10</span><h2>History, downloads & persistence</h2></div>
|
||||||
|
<p class="lead">No database, no registry sprawl — everything is a file next to the executable. Transparent and portable.</p>
|
||||||
|
<h3>Session history</h3>
|
||||||
|
<p>Each session is one UTF-8 text file in <span class="path">history\</span>, named by timestamp. The clever bit is <em>live</em> archiving: the first clip of a session creates the file; subsequent clips rewrite the <em>same</em> file with the full text. So a session is always one tidy, crash-safe file — not a scatter of fragments — and it appears in the History popup immediately. A <code>g_sessionPath</code> global plus a <code>FinalizeSession()</code> helper handle the edge cases (manual edits, typed-only sessions, loading an old entry without resurrecting it). The list is capped at 100 with automatic pruning.</p>
|
||||||
|
<div class="note">
|
||||||
|
<p class="nt">A real bug was fixed here</p>
|
||||||
|
<p>An earlier version stamped every fresh transcription as "loaded from history," so the duplicate-guard silently skipped archiving — sessions never reached disk while the UI claimed "Saved." The fix (live archiving + a corrected guard) is documented and shows the team chasing subtle state bugs to ground.</p>
|
||||||
|
</div>
|
||||||
|
<h3>Model downloads</h3>
|
||||||
|
<p>The downloader is more robust than it needed to be, in a good way: it streams to a <code>.part</code> file then does an atomic rename on success (no half-files), honors the system proxy, follows the Hugging Face → CDN redirects, supports cancellation, allows only one download at a time, and sweeps up stray <code>.part</code> files at startup.</p>
|
||||||
|
<h3>Settings, timing & stats</h3>
|
||||||
|
<p>All three live in a single <span class="path">win-dictation.ini</span> under different sections — app settings, per-model timing accumulators, and lifetime stats. Using the OS's own <code>GetPrivateProfile*</code> API means zero parsing code and a file a user can read and edit by hand. For an app of this scope, that's exactly the right level of machinery.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 11 -->
|
||||||
|
<section id="anatomy">
|
||||||
|
<div class="sec-h"><span class="sec-n">11</span><h2>Anatomy of one dictation</h2></div>
|
||||||
|
<p class="lead">Following a single clip end-to-end ties the whole system together.</p>
|
||||||
|
<ol>
|
||||||
|
<li><code>WM_HOTKEY</code> fires → the app records <code>g_prevForeground</code> and the current selection (<code>EM_GETSEL</code>) so it knows where to paste and where to insert.</li>
|
||||||
|
<li><code>g_tx.start_recording()</code> opens the SDL device; the audio callback appends PCM under the capture mutex and updates the RMS energy meter.</li>
|
||||||
|
<li>The 50 ms UI timer animates the level meter and ticks the on-screen recording clock.</li>
|
||||||
|
<li>Second <code>WM_HOTKEY</code> → <code>g_est.begin(g_timing.predict(len))</code> seeds the progress estimate; <code>g_tx.stop_and_transcribe()</code> swaps the buffer to a worker thread.</li>
|
||||||
|
<li>The worker runs <code>run_inference()</code> → <code>whisper_full</code>. Whisper's progress callback posts <code>WM_APP_PROGRESS</code>; the estimator's <code>on_whisper()</code> EMA-folds it in.</li>
|
||||||
|
<li>On completion the worker posts <code>WM_APP_RESULT</code>.</li>
|
||||||
|
<li>The UI thread then, in order: snaps progress to 100%, records a real timing sample (<code>add_sample</code> + <code>SaveTiming</code>), updates lifetime stats, inserts the text at the saved caret with smart spacing via <code>EM_REPLACESEL</code> (undoable), archives the session, copies to the clipboard, and pastes into <code>g_prevForeground</code>.</li>
|
||||||
|
</ol>
|
||||||
|
<p>Every piece of the architecture shows up in that one trip: the atomics, the message hand-back, the estimator, the learned timing feedback loop, the editable transcript, the live history. It's a coherent design.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 12 -->
|
||||||
|
<section id="strengths">
|
||||||
|
<div class="sec-h"><span class="sec-n">12</span><h2>What's done well</h2></div>
|
||||||
|
<div class="assess">
|
||||||
|
<div class="ac pos"><div class="ah"><span class="dot"></span><h4>The architecture fits the hardware</h4></div><p>Push-to-talk batch over streaming is the correct response to a 2-core CPU, reached by genuine root-cause analysis rather than knob-twiddling.</p></div>
|
||||||
|
<div class="ac pos"><div class="ah"><span class="dot"></span><h4>The progress estimator is exceptional</h4></div><p>Decayed online least-squares + EMA fusion + a strictly monotonic countdown is far beyond what the task demanded — and it shows in the feel.</p></div>
|
||||||
|
<div class="ac pos"><div class="ah"><span class="dot"></span><h4>Seam-free UI by elimination, not patching</h4></div><p>Collapsing nine child windows into one painted, double-buffered, DPI-aware, self-throttling surface removed the problem at its source.</p></div>
|
||||||
|
<div class="ac pos"><div class="ah"><span class="dot"></span><h4>Clean module boundaries (outside main)</h4></div><p>Header-only, dependency-free subsystems (timing, history, downloader, stats, settings) are each individually readable and testable.</p></div>
|
||||||
|
<div class="ac pos"><div class="ah"><span class="dot"></span><h4>Robustness in the right places</h4></div><p>Atomic rename downloads, crash-safe live history, graceful missing-model handling, cancellable inference, single-instance mutex, model preload off the UI thread.</p></div>
|
||||||
|
<div class="ac pos"><div class="ah"><span class="dot"></span><h4>Real product thoughtfulness</h4></div><p>Smart insertion spacing, undoable edits, auto-paste into the prior window, auto-hide, learned timing, friendly stats. These are details a careful builder adds.</p></div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 13 -->
|
||||||
|
<section id="weaknesses">
|
||||||
|
<div class="sec-h"><span class="sec-n">13</span><h2>What holds it back</h2></div>
|
||||||
|
<p class="lead">All fixable, and none of it affects the running app. But it's exactly what a newcomer trips over.</p>
|
||||||
|
<div class="assess">
|
||||||
|
<div class="ac neu"><div class="ah"><span class="dot"></span><h4><code>main.cpp</code> is a 1,500-line god object</h4></div><p>UI, layout, painting, the entire settings screen, clipboard, paste mechanics, model selection, the popup window class, and stats formatting all live in one translation unit with dozens of globals. It works, but it's the hardest part of the codebase to onboard into. Splitting the settings view, the popup, and the painting helpers into their own files would pay for itself quickly.</p></div>
|
||||||
|
<div class="ac neu"><div class="ah"><span class="dot"></span><h4>Vestigial child windows & duplicate code paths</h4></div><p>Startup still creates ~9 owner-draw child controls (record, pin, copy, paste, clear, two selects, two statics) and then immediately hides all but the transcript edit. Their dead <code>WM_COMMAND</code> handlers duplicate the painted-widget <code>OnClick</code> logic — e.g. the Copy action exists in two near-identical places. Leftovers from the rebuild that should be deleted.</p><p class="ref">main.cpp — CreateWindow(...) blocks then ShowWindow(..., SW_HIDE)</p></div>
|
||||||
|
<div class="ac neg"><div class="ah"><span class="dot"></span><h4>Documentation describes a different app</h4></div><p>This is the most actively misleading issue. <code>CUDA-SETUP.md</code>, <code>QUICK-REBUILD-GPU.md</code> and <code>FIXES-APPLIED.md</code> describe a streaming, VAD, ring-buffer, 24-thread, RTX 3090 design that no longer exists. <code>build.ps1</code> still hunts for CUDA and downloads <code>base.en</code> though the product is a CPU-only <code>tiny.en</code> app. <code>TESTING.md</code> references a <code>test-audio.exe</code> the CMake doesn't build (it builds <code>test-core</code>). A newcomer reading the docs would form a completely wrong mental model.</p></div>
|
||||||
|
<div class="ac neg"><div class="ah"><span class="dot"></span><h4>The README claims a feature that isn't there</h4></div><p>Both <code>README.md</code> and <code>CHANGES.md</code> describe a "500 ms silence auto-end timer." The recording loop has no such logic — it only auto-stops at the 10-minute safety cap. (Silence is <em>trimmed</em> before inference, which is likely the source of the confusion.) Either implement it or remove the claim.</p><p class="ref">main.cpp WM_TIMER recording branch vs README "Audio Processing"</p></div>
|
||||||
|
<div class="ac neu"><div class="ah"><span class="dot"></span><h4>Heavy reliance on global mutable state</h4></div><p>The UI is coordinated through dozens of file-scope globals (<code>g_*</code>), a mix of atomics and plain values. It's manageable at this size and the threading is disciplined, but it makes the code hard to reason about in isolation and easy to break with a careless edit.</p></div>
|
||||||
|
<div class="ac neu"><div class="ah"><span class="dot"></span><h4>Build declares C++11 but uses C++17</h4></div><p><code>CMakeLists.txt</code> sets <code>CMAKE_CXX_STANDARD 11</code>, yet the code uses <code>std::size()</code> (C++17). It compiles only because MSVC's default is newer. Set the standard to 17 explicitly so the build is honest and portable.</p></div>
|
||||||
|
<div class="ac neu"><div class="ah"><span class="dot"></span><h4>Minor: redundant color systems & no in-app hotkey editor</h4></div><p>Three overlapping palettes coexist (<code>CR_*</code> COLORREF, <code>T_*</code> GDI+ Color, <code>C_*</code> aliases). And changing the hotkey requires hand-editing the INI — a natural gap given the polished Settings screen already exists.</p></div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 14 -->
|
||||||
|
<section id="recs">
|
||||||
|
<div class="sec-h"><span class="sec-n">14</span><h2>Recommendations</h2></div>
|
||||||
|
<p class="lead">If the next session had a short to-do list, this would be it — ordered by payoff for effort.</p>
|
||||||
|
<ol class="rec">
|
||||||
|
<li><h4>Purge or archive the stale docs <span class="pri hi">high</span></h4><p>Delete or clearly mark <code>CUDA-SETUP.md</code>, <code>QUICK-REBUILD-GPU.md</code>, <code>FIXES-APPLIED.md</code>, <code>TESTING.md</code> and <code>DESIGN.md</code> as describing the retired streaming design. This is the single biggest improvement to onboarding, and it's nearly free.</p></li>
|
||||||
|
<li><h4>Reconcile the README with reality <span class="pri hi">high</span></h4><p>Remove the "500 ms silence auto-end" claim (or implement it). Update the model table and build commands to match the CPU-only product.</p></li>
|
||||||
|
<li><h4>Delete the vestigial child windows <span class="pri md">medium</span></h4><p>Remove the hidden owner-draw controls and their dead <code>WM_COMMAND</code> handlers so there's exactly one code path per action. De-duplicate Copy.</p></li>
|
||||||
|
<li><h4>Break up <code>main.cpp</code> <span class="pri md">medium</span></h4><p>Lift the Settings view, the popup window, and the GDI+ drawing helpers into their own files. Even a mechanical split dramatically improves navigability.</p></li>
|
||||||
|
<li><h4>Fix the build standard & align <code>build.ps1</code> <span class="pri md">medium</span></h4><p>Set <code>CMAKE_CXX_STANDARD 17</code>. Strip the CUDA detection from the build script and default it to fetching <code>tiny.en</code>.</p></li>
|
||||||
|
<li><h4>Add an in-app hotkey picker <span class="pri lo">low</span></h4><p>The Settings surface already exists; surfacing the hotkey there closes an obvious UX gap and removes a troubleshooting step.</p></li>
|
||||||
|
</ol>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 15 -->
|
||||||
|
<section id="scorecard">
|
||||||
|
<div class="sec-h"><span class="sec-n">15</span><h2>Scorecard & final word</h2></div>
|
||||||
|
<div class="score">
|
||||||
|
<div class="srow"><span class="sl">Architecture & design</span><span class="sb"><span class="sf hi" style="width:92%"></span></span><span class="sv">9.2</span></div>
|
||||||
|
<div class="srow"><span class="sl">Performance fit for target</span><span class="sb"><span class="sf hi" style="width:93%"></span></span><span class="sv">9.3</span></div>
|
||||||
|
<div class="srow"><span class="sl">UX & polish</span><span class="sb"><span class="sf hi" style="width:87%"></span></span><span class="sv">8.7</span></div>
|
||||||
|
<div class="srow"><span class="sl">Robustness & error handling</span><span class="sb"><span class="sf" style="width:75%"></span></span><span class="sv">7.5</span></div>
|
||||||
|
<div class="srow"><span class="sl">Code organization</span><span class="sb"><span class="sf lo" style="width:55%"></span></span><span class="sv">5.5</span></div>
|
||||||
|
<div class="srow"><span class="sl">Maintainability</span><span class="sb"><span class="sf lo" style="width:58%"></span></span><span class="sv">5.8</span></div>
|
||||||
|
<div class="srow"><span class="sl">Testing</span><span class="sb"><span class="sf lo" style="width:48%"></span></span><span class="sv">4.8</span></div>
|
||||||
|
<div class="srow"><span class="sl">Documentation accuracy</span><span class="sb"><span class="sf vlo" style="width:38%"></span></span><span class="sv">3.8</span></div>
|
||||||
|
<div class="overall"><span class="num">7.1</span><span class="ot"><strong style="color:var(--text)">Strong, with cleanup debt.</strong><br>An impressive core wrapped in organizational and documentation drift. The engineering earns a high mark; the housekeeping pulls the average down.</span></div>
|
||||||
|
</div>
|
||||||
|
<div class="verdict" style="margin-top:30px">
|
||||||
|
<p class="vh">Final word</p>
|
||||||
|
<p>Win Dictation is a <strong>good codebase — at its core, an impressive one</strong>. The architectural judgement (batch over streaming), the standout progress estimator, and the seam-free renderer are the work of someone who diagnoses root causes and cares about how software feels. Those are the hard parts, and they're done right.</p>
|
||||||
|
<p>What separates it from "great" is entirely recoverable: a monolithic main file, dead code from a prior design, and documentation that actively describes a different application. A focused day of cleanup — most of it deletion — would lift this from "strong for its niche" to "exemplary small-app code." The good news for anyone inheriting it: the bones are excellent, and the to-do list is short.</p>
|
||||||
|
</div>
|
||||||
|
<div class="footer">
|
||||||
|
<b>Win Dictation — Architecture & Engineering Review</b><br>
|
||||||
|
Native Win32 C++ · GDI+ · SDL2 · whisper.cpp · CPU-only · target Intel i5-7th-gen (2C/4T)<br>
|
||||||
|
Assessment based on a full read of the current source tree.
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('keydown', function(e) {
|
||||||
|
if (e.key === 'Escape' && window.parent !== window) {
|
||||||
|
window.parent.postMessage({ type: 'close-fullscreen' }, '*');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<!-- broken-img-handler -->
|
||||||
|
<script>
|
||||||
|
(function(){
|
||||||
|
if(window.__brokenImgHandler)return;
|
||||||
|
window.__brokenImgHandler=true;
|
||||||
|
var MAX=5,DELAYS=[2000,4000,8000,16000,32000];
|
||||||
|
document.addEventListener('error',function(e){
|
||||||
|
var img=e.target;
|
||||||
|
if(!img||img.tagName!=='IMG')return;
|
||||||
|
var liveSrc=img.getAttribute('src');
|
||||||
|
var src=img.dataset.haOriginalSrc||liveSrc;
|
||||||
|
if(!src)return;
|
||||||
|
if(img.dataset.haOriginalSrc&&liveSrc&&liveSrc!==img.dataset.haOriginalSrc&&liveSrc.indexOf('_r=')<0){src=liveSrc;img.dataset.haOriginalSrc=src;img.dataset.haRetryCount='0'}
|
||||||
|
else if(!img.dataset.haOriginalSrc){img.dataset.haOriginalSrc=src}
|
||||||
|
var attempt=parseInt(img.dataset.haRetryCount||'0',10);
|
||||||
|
if(img.dataset.haPhId){var old=document.getElementById(img.dataset.haPhId);if(old)old.remove()}
|
||||||
|
var ph=document.createElement('div');
|
||||||
|
ph.className='ha-img-placeholder'+(attempt>=MAX?' ha-failed':'');
|
||||||
|
ph.id='ha-ph-'+Math.random().toString(36).slice(2,9);
|
||||||
|
var w=img.getAttribute('width');var h=img.getAttribute('height');
|
||||||
|
if(w)ph.style.width=w+(isNaN(Number(w))?'':'px');
|
||||||
|
else if(img.style.width)ph.style.width=img.style.width;
|
||||||
|
else if(img.width>1)ph.style.width=img.width+'px';
|
||||||
|
if(h)ph.style.height=h+(isNaN(Number(h))?'':'px');
|
||||||
|
else if(img.style.height)ph.style.height=img.style.height;
|
||||||
|
else if(img.height>1)ph.style.height=img.height+'px';
|
||||||
|
ph.textContent=attempt>=MAX?'Image unavailable':'Loading image\u2026';
|
||||||
|
img.dataset.haPhId=ph.id;
|
||||||
|
if(img.dataset.haOrigDisplay==null)img.dataset.haOrigDisplay=img.style.display||'';
|
||||||
|
img.style.display='none';
|
||||||
|
img.insertAdjacentElement('afterend',ph);
|
||||||
|
if(attempt<MAX){
|
||||||
|
img.dataset.haRetryCount=String(attempt+1);
|
||||||
|
setTimeout(function(){
|
||||||
|
if(!img.isConnected)return;
|
||||||
|
if(img.dataset.haOriginalSrc!==src)return;
|
||||||
|
if(img.complete&&img.naturalWidth>0)return;
|
||||||
|
var curSrc=img.getAttribute('src');
|
||||||
|
if(curSrc&&curSrc.indexOf(src)!==0)return;
|
||||||
|
var fresh=src+(src.indexOf('?')>=0?'&':'?')+'_r='+(attempt+1)+'_'+Date.now();
|
||||||
|
img.src=fresh;
|
||||||
|
},DELAYS[attempt]);
|
||||||
|
}
|
||||||
|
},true);
|
||||||
|
document.addEventListener('load',function(e){
|
||||||
|
var img=e.target;
|
||||||
|
if(!img||img.tagName!=='IMG')return;
|
||||||
|
if(img.dataset.haPhId){
|
||||||
|
var ph=document.getElementById(img.dataset.haPhId);
|
||||||
|
if(ph)ph.remove();
|
||||||
|
delete img.dataset.haPhId;
|
||||||
|
img.style.display=img.dataset.haOrigDisplay||'';
|
||||||
|
delete img.dataset.haOrigDisplay;
|
||||||
|
delete img.dataset.haOriginalSrc;
|
||||||
|
delete img.dataset.haRetryCount;
|
||||||
|
}
|
||||||
|
},true);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,567 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Win Dictation — User Manual</title>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#0E1014; --card:#16191F; --card-hi:#1E222B; --card-lo:#12151B;
|
||||||
|
--text:#ECEEF2; --dim:#8A909C; --faint:#5A606C;
|
||||||
|
--accent:#6E8BFF; --accent-hi:#839CFF; --danger:#FF5C5C; --good:#46D39A;
|
||||||
|
--border:#262B36; --hair:rgba(255,255,255,.06);
|
||||||
|
--mono:'JetBrains Mono',ui-monospace,SFMono-Regular,Menlo,monospace;
|
||||||
|
--sans:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
html{scroll-behavior:smooth}
|
||||||
|
body{
|
||||||
|
margin:0; background:var(--bg); color:var(--text);
|
||||||
|
font-family:var(--sans); font-size:16.5px; line-height:1.72;
|
||||||
|
-webkit-font-smoothing:antialiased; letter-spacing:.1px;
|
||||||
|
}
|
||||||
|
.wrap{max-width:940px; margin:0 auto; padding:0 6vw 140px;}
|
||||||
|
a{color:var(--accent-hi); text-decoration:none}
|
||||||
|
a:hover{text-decoration:underline}
|
||||||
|
|
||||||
|
/* Hero */
|
||||||
|
.hero{padding:88px 0 30px; border-bottom:1px solid var(--border); margin-bottom:54px}
|
||||||
|
.eyebrow{font-family:var(--mono); font-size:12.5px; letter-spacing:.32em; text-transform:uppercase; color:var(--accent); margin:0 0 20px}
|
||||||
|
.brandrow{display:flex; align-items:center; gap:18px; margin-bottom:22px}
|
||||||
|
.glyph{width:54px;height:54px;border-radius:14px;flex:none;
|
||||||
|
background:linear-gradient(150deg,#6E8BFF,#4D67E0);
|
||||||
|
display:flex;align-items:center;justify-content:center;
|
||||||
|
box-shadow:0 8px 30px rgba(110,139,255,.35), inset 0 1px 0 rgba(255,255,255,.25)}
|
||||||
|
.glyph svg{width:28px;height:28px}
|
||||||
|
h1{font-size:clamp(34px,6vw,54px); line-height:1.04; margin:0; font-weight:800; letter-spacing:-1.2px}
|
||||||
|
.sub{font-size:20px; color:var(--dim); max-width:660px; margin:18px 0 0; font-weight:400}
|
||||||
|
.metarow{display:flex; flex-wrap:wrap; gap:10px; margin-top:30px}
|
||||||
|
.chip{font-family:var(--mono); font-size:12.5px; color:var(--dim);
|
||||||
|
background:var(--card); border:1px solid var(--border); border-radius:999px; padding:7px 15px}
|
||||||
|
.chip b{color:var(--text); font-weight:600}
|
||||||
|
|
||||||
|
/* TOC */
|
||||||
|
.toc{background:linear-gradient(180deg,var(--card),var(--card-lo));
|
||||||
|
border:1px solid var(--border); border-radius:18px; padding:30px 34px; margin-bottom:62px;
|
||||||
|
box-shadow:0 1px 0 var(--hair) inset}
|
||||||
|
.toc h4{margin:0 0 18px; font-family:var(--mono); font-size:12px; letter-spacing:.28em; text-transform:uppercase; color:var(--faint)}
|
||||||
|
.toc ol{margin:0; padding:0; list-style:none; counter-reset:t;
|
||||||
|
columns:2; column-gap:46px}
|
||||||
|
.toc li{counter-increment:t; padding:7px 0; break-inside:avoid}
|
||||||
|
.toc li a{color:var(--text); font-weight:500; font-size:15.5px}
|
||||||
|
.toc li a::before{content:counter(t,decimal-leading-zero); font-family:var(--mono); color:var(--accent);
|
||||||
|
font-size:12px; margin-right:13px; font-weight:600}
|
||||||
|
|
||||||
|
/* Sections */
|
||||||
|
section{margin:0 0 70px; scroll-margin-top:30px}
|
||||||
|
.sec-h{display:flex; align-items:baseline; gap:16px; margin:0 0 8px}
|
||||||
|
.sec-n{font-family:var(--mono); font-size:14px; color:var(--accent); font-weight:600; flex:none}
|
||||||
|
h2{font-size:29px; font-weight:700; margin:0; letter-spacing:-.5px}
|
||||||
|
h3{font-size:19px; font-weight:650; margin:36px 0 12px; letter-spacing:-.2px; color:var(--text)}
|
||||||
|
.lead{color:var(--dim); font-size:18px; margin:0 0 26px; max-width:720px}
|
||||||
|
p{margin:0 0 17px}
|
||||||
|
.muted{color:var(--dim)}
|
||||||
|
strong{color:#fff; font-weight:650}
|
||||||
|
ul,ol{margin:0 0 18px; padding-left:22px}
|
||||||
|
li{margin:9px 0}
|
||||||
|
hr.soft{border:0;border-top:1px solid var(--border);margin:42px 0}
|
||||||
|
|
||||||
|
kbd{font-family:var(--mono); font-size:13px; background:var(--card-hi);
|
||||||
|
border:1px solid var(--border); border-bottom-color:#000; border-radius:7px;
|
||||||
|
padding:3px 9px; color:var(--text); white-space:nowrap; box-shadow:0 2px 0 rgba(0,0,0,.4)}
|
||||||
|
code{font-family:var(--mono); font-size:14px; background:var(--card-hi); color:#cfe0ff;
|
||||||
|
padding:2px 7px; border-radius:6px; border:1px solid var(--border)}
|
||||||
|
.path{font-family:var(--mono); font-size:13.5px; color:var(--good)}
|
||||||
|
|
||||||
|
/* App mockup */
|
||||||
|
.stage{background:radial-gradient(120% 120% at 50% 0%, #1a1d26 0%, #0b0d11 70%);
|
||||||
|
border:1px solid var(--border); border-radius:20px; padding:46px 30px; margin:8px 0 14px;
|
||||||
|
display:flex; justify-content:center}
|
||||||
|
.appwin{width:380px; max-width:100%; background:var(--bg); border:1px solid #2a2f3a;
|
||||||
|
border-radius:12px; overflow:hidden; box-shadow:0 30px 70px rgba(0,0,0,.6); font-size:14px}
|
||||||
|
.titlebar{display:flex; align-items:center; gap:9px; padding:9px 12px; background:#0b0d11; border-bottom:1px solid #1c2027}
|
||||||
|
.titlebar .ic{width:15px;height:15px;border-radius:4px;background:linear-gradient(150deg,#6E8BFF,#4D67E0)}
|
||||||
|
.titlebar .tt{color:var(--dim); font-size:12.5px}
|
||||||
|
.titlebar .tw{margin-left:auto; color:var(--faint); letter-spacing:3px; font-size:12px}
|
||||||
|
.appbody{padding:16px}
|
||||||
|
.rrow{display:flex; gap:9px; margin-bottom:13px}
|
||||||
|
.rec{flex:1; background:linear-gradient(180deg,#7a93ff,#6E8BFF); border-radius:999px;
|
||||||
|
display:flex; align-items:center; gap:11px; padding:11px 18px; color:#fff; font-weight:600; position:relative}
|
||||||
|
.rec .d{width:13px;height:13px;border-radius:50%;background:#fff}
|
||||||
|
.chipbtn{width:42px; border-radius:10px; background:var(--card); border:1px solid var(--border);
|
||||||
|
display:flex; align-items:center; justify-content:center; position:relative}
|
||||||
|
.chipbtn svg{width:17px;height:17px}
|
||||||
|
.chipbtn.on svg{color:var(--accent)}
|
||||||
|
.stat{color:var(--dim); font-size:12.5px; margin:2px 2px 13px; position:relative}
|
||||||
|
.tbox{background:var(--card); border:1px solid var(--border); border-radius:12px;
|
||||||
|
padding:14px 15px; min-height:104px; color:var(--text); font-size:13.5px; line-height:1.5; position:relative;
|
||||||
|
box-shadow:0 1px 0 var(--hair) inset}
|
||||||
|
.srow{display:flex; gap:9px; margin:13px 0}
|
||||||
|
.sel{flex:1; background:var(--card); border:1px solid var(--border); border-radius:10px;
|
||||||
|
padding:10px 13px; color:var(--text); font-size:12.5px; display:flex; align-items:center; position:relative}
|
||||||
|
.sel .cv{margin-left:auto; color:var(--dim)}
|
||||||
|
.arow{display:flex; justify-content:space-around; padding:8px 0 2px; color:var(--dim); font-size:13.5px; position:relative}
|
||||||
|
.anno{position:absolute; top:-9px; right:-9px; width:21px;height:21px; border-radius:50%;
|
||||||
|
background:var(--accent); color:#fff; font-family:var(--mono); font-size:11.5px; font-weight:700;
|
||||||
|
display:flex; align-items:center; justify-content:center; box-shadow:0 2px 8px rgba(0,0,0,.5); z-index:3}
|
||||||
|
.anno.l{left:-9px; right:auto}
|
||||||
|
.arow .anno{top:-4px; right:8px}
|
||||||
|
|
||||||
|
.legend{display:grid; grid-template-columns:1fr 1fr; gap:13px 30px; margin:24px 0 0}
|
||||||
|
.legend .li{display:flex; gap:13px; align-items:flex-start}
|
||||||
|
.legend .bn{flex:none; width:22px;height:22px;border-radius:50%; background:var(--accent); color:#fff;
|
||||||
|
font-family:var(--mono); font-size:12px; font-weight:700; display:flex; align-items:center; justify-content:center; margin-top:2px}
|
||||||
|
.legend .lt{font-size:14.5px; color:var(--dim)}
|
||||||
|
.legend .lt b{display:block; color:var(--text); font-weight:600; margin-bottom:1px; font-size:15px}
|
||||||
|
|
||||||
|
/* Steps */
|
||||||
|
.steps{counter-reset:s; margin:0; padding:0; list-style:none}
|
||||||
|
.steps li{counter-increment:s; position:relative; padding:0 0 26px 60px; margin:0}
|
||||||
|
.steps li:not(:last-child)::after{content:""; position:absolute; left:21px; top:42px; bottom:6px; width:2px; background:var(--border)}
|
||||||
|
.steps li::before{content:counter(s); position:absolute; left:0; top:0; width:43px;height:43px;border-radius:12px;
|
||||||
|
background:var(--card); border:1px solid var(--border); color:var(--accent); font-family:var(--mono); font-weight:700; font-size:17px;
|
||||||
|
display:flex; align-items:center; justify-content:center}
|
||||||
|
.steps h4{margin:6px 0 5px; font-size:17.5px; font-weight:650}
|
||||||
|
.steps p{margin:0; color:var(--dim); font-size:15.5px}
|
||||||
|
|
||||||
|
/* Callouts */
|
||||||
|
.note{border:1px solid var(--border); border-left:3px solid var(--accent);
|
||||||
|
background:linear-gradient(90deg,rgba(110,139,255,.08),transparent 60%); border-radius:12px; padding:17px 20px; margin:22px 0}
|
||||||
|
.note.warn{border-left-color:var(--danger); background:linear-gradient(90deg,rgba(255,92,92,.08),transparent 60%)}
|
||||||
|
.note.good{border-left-color:var(--good); background:linear-gradient(90deg,rgba(70,211,154,.08),transparent 60%)}
|
||||||
|
.note .nt{font-family:var(--mono); font-size:11.5px; letter-spacing:.18em; text-transform:uppercase; color:var(--dim); margin:0 0 6px}
|
||||||
|
.note p:last-child{margin:0}
|
||||||
|
|
||||||
|
/* Tables */
|
||||||
|
.tbl{width:100%; border-collapse:collapse; margin:18px 0; font-size:15px; overflow:hidden; border-radius:12px; border:1px solid var(--border)}
|
||||||
|
.tbl th{text-align:left; font-family:var(--mono); font-size:11.5px; letter-spacing:.12em; text-transform:uppercase;
|
||||||
|
color:var(--dim); padding:13px 16px; background:var(--card-lo); border-bottom:1px solid var(--border); font-weight:600}
|
||||||
|
.tbl td{padding:13px 16px; border-bottom:1px solid var(--border); vertical-align:top; color:var(--text)}
|
||||||
|
.tbl tr:last-child td{border-bottom:0}
|
||||||
|
.tbl tr:nth-child(even) td{background:rgba(255,255,255,.012)}
|
||||||
|
.tbl td .sm{color:var(--dim); font-size:13.5px}
|
||||||
|
.tag{font-family:var(--mono); font-size:12px; padding:2px 9px; border-radius:6px; white-space:nowrap}
|
||||||
|
.tag.fast{background:rgba(70,211,154,.14); color:var(--good)}
|
||||||
|
.tag.bal{background:rgba(110,139,255,.14); color:var(--accent-hi)}
|
||||||
|
.tag.slow{background:rgba(255,92,92,.14); color:var(--danger)}
|
||||||
|
|
||||||
|
/* Feature grid */
|
||||||
|
.grid{display:grid; grid-template-columns:1fr 1fr; gap:16px; margin:24px 0}
|
||||||
|
.fcard{background:var(--card); border:1px solid var(--border); border-radius:14px; padding:22px; box-shadow:0 1px 0 var(--hair) inset}
|
||||||
|
.fcard .fi{width:38px;height:38px;border-radius:10px;background:var(--card-hi); display:flex;align-items:center;justify-content:center; margin-bottom:14px}
|
||||||
|
.fcard .fi svg{width:20px;height:20px;color:var(--accent)}
|
||||||
|
.fcard h4{margin:0 0 7px; font-size:16.5px; font-weight:650}
|
||||||
|
.fcard p{margin:0; color:var(--dim); font-size:14.5px; line-height:1.6}
|
||||||
|
|
||||||
|
.kv{display:flex; gap:14px; padding:14px 0; border-bottom:1px solid var(--border)}
|
||||||
|
.kv:last-child{border-bottom:0}
|
||||||
|
.kv .k{flex:none; width:190px}
|
||||||
|
.kv .k kbd{font-size:13px}
|
||||||
|
.kv .v{color:var(--dim); font-size:15.5px}
|
||||||
|
|
||||||
|
.footer{border-top:1px solid var(--border); margin-top:80px; padding-top:30px; color:var(--faint); font-size:13.5px; font-family:var(--mono)}
|
||||||
|
.footer b{color:var(--dim); font-weight:500}
|
||||||
|
|
||||||
|
@media(max-width:680px){
|
||||||
|
.toc ol{columns:1}
|
||||||
|
.grid,.legend{grid-template-columns:1fr}
|
||||||
|
.kv{flex-direction:column; gap:4px}
|
||||||
|
.kv .k{width:auto}
|
||||||
|
body{font-size:16px}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<style>
|
||||||
|
.ha-img-placeholder{display:flex;align-items:center;justify-content:center;flex-direction:column;gap:6px;background:#f4f4f5;border:1px dashed #d4d4d8;border-radius:8px;color:#71717a;font-size:12px;font-family:system-ui,sans-serif;min-height:80px;padding:16px;box-sizing:border-box;animation:ha-img-pulse 1.5s ease-in-out infinite}
|
||||||
|
.ha-img-placeholder.ha-failed{animation:none;opacity:.7}
|
||||||
|
@keyframes ha-img-pulse{0%,100%{opacity:1}50%{opacity:.5}}
|
||||||
|
@media(prefers-color-scheme:dark){.ha-img-placeholder{background:#27272a;border-color:#3f3f46;color:#a1a1aa}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="wrap">
|
||||||
|
|
||||||
|
<!-- HERO -->
|
||||||
|
<header class="hero">
|
||||||
|
<p class="eyebrow">User Manual · v3</p>
|
||||||
|
<div class="brandrow">
|
||||||
|
<div class="glyph">
|
||||||
|
<svg viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/></svg>
|
||||||
|
</div>
|
||||||
|
<h1>Win Dictation</h1>
|
||||||
|
</div>
|
||||||
|
<p class="sub">A push-to-talk speech-to-text utility for Windows. Press a hotkey, speak, and your words land in whatever app you were just using — fully offline, powered by Whisper.</p>
|
||||||
|
<div class="metarow">
|
||||||
|
<span class="chip"><b>Offline</b> · runs on your machine</span>
|
||||||
|
<span class="chip"><b>Hotkey</b> Ctrl+Shift+Space</span>
|
||||||
|
<span class="chip"><b>CPU-only</b> · no GPU required</span>
|
||||||
|
<span class="chip"><b>Whisper</b> · tiny.en → small.en</span>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- TOC -->
|
||||||
|
<nav class="toc">
|
||||||
|
<h4>Contents</h4>
|
||||||
|
<ol>
|
||||||
|
<li><a href="#what">What Win Dictation is</a></li>
|
||||||
|
<li><a href="#quick">Quick start in 60 seconds</a></li>
|
||||||
|
<li><a href="#tour">The interface, explained</a></li>
|
||||||
|
<li><a href="#workflow">How dictation works</a></li>
|
||||||
|
<li><a href="#hotkeys">Keyboard & hotkeys</a></li>
|
||||||
|
<li><a href="#autopaste">Auto-paste & the active window</a></li>
|
||||||
|
<li><a href="#history">History & sessions</a></li>
|
||||||
|
<li><a href="#models">Models & the Settings screen</a></li>
|
||||||
|
<li><a href="#tray">System tray & options</a></li>
|
||||||
|
<li><a href="#stats">Your statistics</a></li>
|
||||||
|
<li><a href="#tips">Tips for best results</a></li>
|
||||||
|
<li><a href="#trouble">Troubleshooting</a></li>
|
||||||
|
<li><a href="#faq">FAQ & where things live</a></li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- 1 -->
|
||||||
|
<section id="what">
|
||||||
|
<div class="sec-h"><span class="sec-n">01</span><h2>What Win Dictation is</h2></div>
|
||||||
|
<p class="lead">A small, focused desktop tool that turns your voice into text anywhere on Windows — no browser, no cloud, no account.</p>
|
||||||
|
<p>Win Dictation sits quietly in your system tray. When you want to dictate, you press a global hotkey, speak a sentence or a paragraph, then press the hotkey again. A second or two later the transcribed text is copied to your clipboard and — by default — automatically pasted into whatever window you were using: your email, a chat box, a code editor, a document.</p>
|
||||||
|
<p>Everything happens <strong>on your computer</strong>. The audio never leaves the machine; transcription runs locally using <a href="https://github.com/ggerganov/whisper.cpp" target="_blank" rel="noopener noreferrer">whisper.cpp</a>, a compact build of OpenAI's Whisper model. That means it works on a plane, behind a firewall, or anywhere with no internet at all.</p>
|
||||||
|
<div class="note good">
|
||||||
|
<p class="nt">Built for modest hardware</p>
|
||||||
|
<p>This build is tuned for an ordinary CPU-only laptop — the kind with two physical cores and no graphics card. It uses a fast, lightweight model by default and keeps your processor nearly idle while you speak, only working hard for a brief moment after you stop.</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 2 -->
|
||||||
|
<section id="quick">
|
||||||
|
<div class="sec-h"><span class="sec-n">02</span><h2>Quick start in 60 seconds</h2></div>
|
||||||
|
<p class="lead">Three steps. No setup, no sign-in.</p>
|
||||||
|
<ol class="steps">
|
||||||
|
<li>
|
||||||
|
<h4>Launch <span class="path">win-dictation.exe</span></h4>
|
||||||
|
<p>The window opens and a microphone icon appears in your system tray. Wait a moment for the status line to change from <em>“Loading model…”</em> to <strong>“Ready”</strong>.</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<h4>Click into wherever you want the text, then press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Space</kbd></h4>
|
||||||
|
<p>Put your cursor in the email, chat box, or document first. Then hit the hotkey. The Record button turns red and a green level meter shows it’s hearing you.</p>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<h4>Speak, then press the hotkey again</h4>
|
||||||
|
<p>Talk naturally. When you’re done, press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Space</kbd> once more. A short progress bar runs, and your words appear — pasted straight into the app you were using.</p>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
<div class="note">
|
||||||
|
<p class="nt">That's the whole loop</p>
|
||||||
|
<p>Press to start, speak, press to finish. The text is on your clipboard <em>and</em> dropped into your previous window. You never have to click back into Win Dictation.</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 3 -->
|
||||||
|
<section id="tour">
|
||||||
|
<div class="sec-h"><span class="sec-n">03</span><h2>The interface, explained</h2></div>
|
||||||
|
<p class="lead">The whole app is a single window. Here is every control on it.</p>
|
||||||
|
|
||||||
|
<div class="stage">
|
||||||
|
<div class="appwin">
|
||||||
|
<div class="titlebar"><span class="ic"></span><span class="tt">Dictation</span><span class="tw">— ▢ ✕</span></div>
|
||||||
|
<div class="appbody">
|
||||||
|
<div class="rrow">
|
||||||
|
<div class="rec"><span class="d"></span>Record<span class="anno">1</span></div>
|
||||||
|
<div class="chipbtn on"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 4v6l-2 4v2h10v-2l-2-4V4"/><line x1="12" y1="16" x2="12" y2="22"/><line x1="8" y1="4" x2="16" y2="4"/></svg><span class="anno">2</span></div>
|
||||||
|
<div class="chipbtn"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg><span class="anno">3</span></div>
|
||||||
|
</div>
|
||||||
|
<div class="stat">Ready • 2 threads<span class="anno">4</span></div>
|
||||||
|
<div class="tbox">Win-dictate is a desktop, whisper powered, speech to text application!<span class="anno">5</span></div>
|
||||||
|
<div class="srow">
|
||||||
|
<div class="sel">Microphone (Realtek Audio)<span class="cv">⌄</span><span class="anno">6</span></div>
|
||||||
|
<div class="sel">History<span class="cv">⌄</span><span class="anno">7</span></div>
|
||||||
|
</div>
|
||||||
|
<div class="arow"><span>Copy</span><span>Paste</span><span>Clear</span><span class="anno">8</span></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="legend">
|
||||||
|
<div class="li"><span class="bn">1</span><span class="lt"><b>Record / Stop</b>The big pill. Click to start; it turns red and reads “Stop” while recording. Same as the hotkey.</span></div>
|
||||||
|
<div class="li"><span class="bn">2</span><span class="lt"><b>Pin</b>Keeps the window always on top. Blue when active. On by default.</span></div>
|
||||||
|
<div class="li"><span class="bn">3</span><span class="lt"><b>Settings (cog)</b>Opens the Settings screen for choosing and downloading models, and viewing your stats.</span></div>
|
||||||
|
<div class="li"><span class="bn">4</span><span class="lt"><b>Status line</b>Shows “Ready” and the thread count when idle, a timer while recording, and a live countdown while transcribing.</span></div>
|
||||||
|
<div class="li"><span class="bn">5</span><span class="lt"><b>Transcript box</b>Where text appears. You can <strong>edit it freely</strong> — click in and type, fix, or delete.</span></div>
|
||||||
|
<div class="li"><span class="bn">6</span><span class="lt"><b>Microphone selector</b>Choose which input device to record from. Opens a dropdown of all your mics.</span></div>
|
||||||
|
<div class="li"><span class="bn">7</span><span class="lt"><b>History</b>Opens a list of past dictation sessions you can reload — or delete individually.</span></div>
|
||||||
|
<div class="li"><span class="bn">8</span><span class="lt"><b>Copy · Paste · Clear</b>Copy the transcript, paste it into your last window, or clear the box (saving it to history first).</span></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>The status line is your dashboard</h3>
|
||||||
|
<p>That one line of dim text under the Record button tells you everything about the app's state:</p>
|
||||||
|
<table class="tbl">
|
||||||
|
<tr><th>You see</th><th>It means</th></tr>
|
||||||
|
<tr><td><code>Loading model…</code></td><td>Starting up — the speech model is being read into memory. Wait a second.</td></tr>
|
||||||
|
<tr><td><code>Ready · 2 threads</code></td><td>Idle and ready to record. The number is how many CPU threads it will use.</td></tr>
|
||||||
|
<tr><td><code>Recording 0:14</code></td><td>Listening. The timer counts how long you've been speaking. A green level meter pulses with your voice.</td></tr>
|
||||||
|
<tr><td><code>Transcribing 0:14 · 62% · 3s left</code></td><td>Working on your audio. The bar fills and the countdown ticks <em>down</em> to zero.</td></tr>
|
||||||
|
<tr><td><code>Pasted</code> / <code>Copied</code></td><td>Done. Your text went to the clipboard (and into your previous window if auto-paste is on).</td></tr>
|
||||||
|
<tr><td><code>No speech detected</code></td><td>The clip was silent or too short to transcribe. Nothing was added.</td></tr>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 4 -->
|
||||||
|
<section id="workflow">
|
||||||
|
<div class="sec-h"><span class="sec-n">04</span><h2>How dictation works</h2></div>
|
||||||
|
<p class="lead">Win Dictation is <strong>push-to-talk</strong>, not live streaming. You record a whole clip, then it transcribes the whole thing at once.</p>
|
||||||
|
<p>This is a deliberate design choice. Instead of trying to transcribe word-by-word as you speak (which pins a CPU at 100% and stutters on a modest laptop), Win Dictation simply records your audio cheaply while you talk, then does one fast transcription pass the moment you stop. The result is calmer, more accurate, and far lighter on your battery.</p>
|
||||||
|
|
||||||
|
<h3>What happens when you record</h3>
|
||||||
|
<ol>
|
||||||
|
<li><strong>You press the hotkey.</strong> The app remembers which window you were in, and where your text cursor was sitting inside the transcript box.</li>
|
||||||
|
<li><strong>It records.</strong> Audio is captured at 16 kHz and held in memory. CPU use stays near zero. The level meter shows it's hearing you.</li>
|
||||||
|
<li><strong>You press the hotkey again.</strong> Recording stops. Silence at the start and end of your clip is trimmed away automatically.</li>
|
||||||
|
<li><strong>It transcribes.</strong> The full clip is run through Whisper once. The progress bar shows a smooth, self-calibrating estimate of how long it will take.</li>
|
||||||
|
<li><strong>The text lands.</strong> It's inserted at your cursor (with smart spacing so words don't run together), copied to the clipboard, and pasted into your previous window.</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<div class="note">
|
||||||
|
<p class="nt">There is no “stop on silence”</p>
|
||||||
|
<p>Recording continues until <em>you</em> press the hotkey again (or click Stop). Pausing to think won't end the session — take your time. The only automatic stop is a safety cap at <strong>10 minutes</strong> per clip.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>The transcript box is editable</h3>
|
||||||
|
<p>Unlike many dictation tools, the text area is fully editable. Click anywhere in it to fix a misheard word, delete a stray sentence, or type manually. When you dictate again, the new text is inserted <strong>at your cursor</strong> — so you can build up a document piece by piece, placing each new chunk exactly where you want it.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 5 -->
|
||||||
|
<section id="hotkeys">
|
||||||
|
<div class="sec-h"><span class="sec-n">05</span><h2>Keyboard & hotkeys</h2></div>
|
||||||
|
<p class="lead">Two global shortcuts work from anywhere in Windows, even when the window is hidden.</p>
|
||||||
|
<div class="kv"><div class="k"><kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Space</kbd></div><div class="v"><strong>Start / stop recording.</strong> The core hotkey. Press once to begin, once more to transcribe. If a transcription is already running, pressing it again cancels it.</div></div>
|
||||||
|
<div class="kv"><div class="k"><kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>H</kbd></div><div class="v"><strong>Hide the window.</strong> Tucks Win Dictation away to the tray (and cancels any recording in progress). The hotkeys still work while hidden.</div></div>
|
||||||
|
<div class="kv"><div class="k"><kbd>Esc</kbd> <span class="muted">(in a dropdown)</span></div><div class="v">Closes an open Microphone or History popup without choosing anything.</div></div>
|
||||||
|
<div class="kv"><div class="k"><kbd>Delete</kbd> <span class="muted">(in History)</span></div><div class="v">Deletes the history entry you're hovering over.</div></div>
|
||||||
|
<div class="note warn">
|
||||||
|
<p class="nt">If the hotkey doesn't work</p>
|
||||||
|
<p>You may see <code>Hotkey in use — edit win-dictation.ini</code>. That means another program already grabbed <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Space</kbd>. You can change it by editing the <code>hkMods</code> and <code>hkVk</code> values in the <span class="path">win-dictation.ini</span> file (see the <a href="#faq">FAQ</a>).</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 6 -->
|
||||||
|
<section id="autopaste">
|
||||||
|
<div class="sec-h"><span class="sec-n">06</span><h2>Auto-paste & the active window</h2></div>
|
||||||
|
<p class="lead">The feature that makes Win Dictation feel invisible: it types into <em>other</em> apps for you.</p>
|
||||||
|
<p>When you trigger recording, the app notes which window had focus a moment before. After transcription, if <strong>Auto-paste</strong> is enabled (it is by default), it brings that window back to the front and pastes your text there automatically. You dictate, and the words appear in your email — you never touch Win Dictation's own window.</p>
|
||||||
|
<p>If you'd rather paste manually, turn auto-paste off in the tray menu. The text is always still copied to your clipboard, and the <strong>Paste</strong> button will send it to your last window on demand.</p>
|
||||||
|
<div class="note">
|
||||||
|
<p class="nt">Pair it with Auto-hide</p>
|
||||||
|
<p>Turn on <strong>Auto-hide</strong> (tray menu) and the window disappears the instant it pastes. Combined with the global hotkey, dictation becomes a pure overlay: tap, speak, tap, and your words flow into whatever you're doing.</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 7 -->
|
||||||
|
<section id="history">
|
||||||
|
<div class="sec-h"><span class="sec-n">07</span><h2>History & sessions</h2></div>
|
||||||
|
<p class="lead">Every dictation session is saved automatically, so you never lose a transcript.</p>
|
||||||
|
<p>A <strong>session</strong> is everything you dictate between clears. As soon as you finish your first clip, Win Dictation writes it to a timestamped text file. Each additional clip in that session updates the same file — so one session is one tidy file, kept up to date as you go.</p>
|
||||||
|
|
||||||
|
<h3>Browsing and reloading</h3>
|
||||||
|
<p>Click the <strong>History</strong> selector to open the list. Each entry shows its date, time, and a short preview of the text. Click one to load it back into the transcript box. The most recent sessions are at the top, and up to <strong>100</strong> sessions are kept (older ones are pruned automatically).</p>
|
||||||
|
|
||||||
|
<h3>Deleting entries</h3>
|
||||||
|
<p>Hover over any history row and a small <strong>✕</strong> appears on its right edge — click it to delete that session's file. You can also press <kbd>Delete</kbd> on the hovered row. The list <em>stays open</em> after each delete so you can tidy up several at once. The window even shrinks to fit as the list gets shorter.</p>
|
||||||
|
<div class="note warn">
|
||||||
|
<p class="nt">Deletion is permanent</p>
|
||||||
|
<p>Removing a history entry deletes its text file from disk immediately — there is no confirmation prompt and no undo. The files themselves live in a <span class="path">history\</span> folder next to the program, if you ever want to back them up.</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 8 -->
|
||||||
|
<section id="models">
|
||||||
|
<div class="sec-h"><span class="sec-n">08</span><h2>Models & the Settings screen</h2></div>
|
||||||
|
<p class="lead">A model is the AI that turns sound into words. Bigger models are more accurate but slower. Click the cog to manage them.</p>
|
||||||
|
<p>The Settings screen lists every model Win Dictation can use. Each row shows the model's name, file size, and a short hint. Installed models have a filled radio button you can select; ones you don't have yet show a <strong>Download</strong> button that fetches them directly from Hugging Face with a live progress percentage.</p>
|
||||||
|
|
||||||
|
<table class="tbl">
|
||||||
|
<tr><th>Model</th><th>Size</th><th>Character</th><th></th></tr>
|
||||||
|
<tr><td><code>tiny.en</code></td><td class="sm">~75 MB</td><td class="sm">The default. Quick and light — ideal for this CPU.</td><td><span class="tag fast">fastest</span></td></tr>
|
||||||
|
<tr><td><code>tiny.en-q8_0</code></td><td class="sm">~42 MB</td><td class="sm">Same speed, smaller file (compressed).</td><td><span class="tag fast">fastest</span></td></tr>
|
||||||
|
<tr><td><code>base.en-q5_1</code></td><td class="sm">~59 MB</td><td class="sm">A noticeable accuracy bump for little cost.</td><td><span class="tag bal">good balance</span></td></tr>
|
||||||
|
<tr><td><code>base.en</code></td><td class="sm">~142 MB</td><td class="sm">More accurate; still reasonable on two cores.</td><td><span class="tag bal">balance</span></td></tr>
|
||||||
|
<tr><td><code>small.en-q5_1</code></td><td class="sm">~182 MB</td><td class="sm">Accurate, but slow on this machine.</td><td><span class="tag slow">slow here</span></td></tr>
|
||||||
|
<tr><td><code>small.en</code></td><td class="sm">~466 MB</td><td class="sm">The most accurate offered — and the slowest.</td><td><span class="tag slow">slowest</span></td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h3>Choosing a model</h3>
|
||||||
|
<ol>
|
||||||
|
<li>Open Settings (the cog), and find the model you want.</li>
|
||||||
|
<li>If it isn't installed, click <strong>Download</strong> and wait for it to reach 100%. You can cancel mid-download, and only one downloads at a time.</li>
|
||||||
|
<li>Click the model's row to select it (the dot fills in).</li>
|
||||||
|
<li>Click <strong>Save</strong>. The app reloads with the new model and remembers your choice. <strong>Back</strong> or <strong>Cancel</strong> discards any change.</li>
|
||||||
|
</ol>
|
||||||
|
<div class="note">
|
||||||
|
<p class="nt">A good rule of thumb</p>
|
||||||
|
<p>Stick with <code>tiny.en</code> or <code>base.en-q5_1</code> for everyday use on a two-core laptop. Step up to <code>base.en</code> if you want better accuracy and don't mind waiting a beat longer. The <code>small</code> models are best reserved for short, important clips where accuracy matters most.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>The progress bar learns your machine</h3>
|
||||||
|
<p>You'll notice the transcription countdown is unusually accurate. That's because Win Dictation <strong>measures how fast your specific computer is</strong> with each model and remembers it. The more you use a model, the better its time estimates become — the bar counts steadily down rather than jumping around.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 9 -->
|
||||||
|
<section id="tray">
|
||||||
|
<div class="sec-h"><span class="sec-n">09</span><h2>System tray & options</h2></div>
|
||||||
|
<p class="lead">Win Dictation lives in the tray. Right-click its icon for the quick options menu.</p>
|
||||||
|
<div class="grid">
|
||||||
|
<div class="fcard"><div class="fi"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 11l3 3L22 4"/><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/></svg></div><h4>Auto-paste</h4><p>Paste transcribed text into your previous window automatically. On by default.</p></div>
|
||||||
|
<div class="fcard"><div class="fi"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2l2.4 7.4H22l-6 4.6 2.3 7-6.3-4.6L5.7 21 8 14 2 9.4h7.6z"/></svg></div><h4>Always on top</h4><p>Keep the window above other apps. Mirrors the Pin button. On by default.</p></div>
|
||||||
|
<div class="fcard"><div class="fi"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7S2 12 2 12z"/><line x1="4" y1="4" x2="20" y2="20"/></svg></div><h4>Auto-hide</h4><p>Hide the window automatically right after it pastes. Off by default.</p></div>
|
||||||
|
<div class="fcard"><div class="fi"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6L6 18M6 6l12 12"/></svg></div><h4>Exit</h4><p>Fully quits the app. Closing the window only hides it to the tray — use this to stop it entirely.</p></div>
|
||||||
|
</div>
|
||||||
|
<p class="muted">Double-clicking the tray icon brings the window back. Closing the window with the <strong>✕</strong> doesn't quit — it just hides, so the hotkey keeps working in the background. Your window position, pinned state, and these toggles are all remembered between launches.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 10 -->
|
||||||
|
<section id="stats">
|
||||||
|
<div class="sec-h"><span class="sec-n">10</span><h2>Your statistics</h2></div>
|
||||||
|
<p class="lead">Scroll down in Settings to see a running tally of your dictation habits.</p>
|
||||||
|
<p>Win Dictation quietly keeps lifetime totals and turns them into friendly figures:</p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>Total audio dictated</strong> and the number of clips.</li>
|
||||||
|
<li><strong>Word count</strong>, plus your average <strong>speaking pace</strong> in words per minute.</li>
|
||||||
|
<li><strong>Total processing time</strong> and your machine's <strong>real-time factor</strong> (e.g. “4× real-time” means it transcribes four seconds of audio every second).</li>
|
||||||
|
<li>Your <strong>longest single clip</strong>.</li>
|
||||||
|
<li>An estimate of the <strong>time you've saved</strong> versus typing at 40 wpm.</li>
|
||||||
|
</ul>
|
||||||
|
<p class="muted">These numbers are stored locally and are just for your own curiosity — nothing is reported anywhere.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 11 -->
|
||||||
|
<section id="tips">
|
||||||
|
<div class="sec-h"><span class="sec-n">11</span><h2>Tips for best results</h2></div>
|
||||||
|
<div class="grid">
|
||||||
|
<div class="fcard"><h4>Click first, then dictate</h4><p>Put your text cursor in the destination app <em>before</em> pressing the hotkey, so auto-paste knows where to send the words.</p></div>
|
||||||
|
<div class="fcard"><h4>Speak in natural phrases</h4><p>Whisper transcribes best with full sentences and natural rhythm. You don't need to over-enunciate or pause between words.</p></div>
|
||||||
|
<div class="fcard"><h4>Pick the right mic</h4><p>If accuracy is poor, check the Microphone selector — a headset or dedicated mic beats a distant laptop mic in a noisy room.</p></div>
|
||||||
|
<div class="fcard"><h4>Match model to task</h4><p>Quick chat replies? <code>tiny.en</code>. A careful paragraph of prose? Try <code>base.en</code> for fewer corrections.</p></div>
|
||||||
|
<div class="fcard"><h4>Edit in place</h4><p>Fix the odd misheard word right in the transcript box, then Copy — faster than re-recording the whole thing.</p></div>
|
||||||
|
<div class="fcard"><h4>Let it warm up</h4><p>The very first transcription after launch can be a touch slower as the model settles into memory. It's quick from then on.</p></div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 12 -->
|
||||||
|
<section id="trouble">
|
||||||
|
<div class="sec-h"><span class="sec-n">12</span><h2>Troubleshooting</h2></div>
|
||||||
|
<table class="tbl">
|
||||||
|
<tr><th>Symptom</th><th>What to do</th></tr>
|
||||||
|
<tr><td><b>“Model not found”</b></td><td>The selected <code>.bin</code> model file is missing. Open Settings and download a model (start with <code>tiny.en</code>), or place a <code>.bin</code> file in the <span class="path">models\</span> folder next to the program and restart.</td></tr>
|
||||||
|
<tr><td><b>“Hotkey in use”</b></td><td>Another app owns <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Space</kbd>. Change the hotkey in <span class="path">win-dictation.ini</span>, or close the conflicting app. You can still record by clicking the Record button.</td></tr>
|
||||||
|
<tr><td><b>“Microphone error”</b></td><td>The chosen input device couldn't be opened. Pick a different mic from the selector, make sure it isn't in use by another app, and check Windows mic permissions.</td></tr>
|
||||||
|
<tr><td><b>“No speech detected”</b></td><td>The clip was silent, too quiet, or under ~0.3 seconds. Check the level meter moves when you talk, and confirm the right mic is selected.</td></tr>
|
||||||
|
<tr><td><b>Text pasted into the wrong place</b></td><td>Auto-paste targets whatever window was focused just before you pressed the hotkey. Click into your destination first. If in doubt, turn auto-paste off and use the Paste button deliberately.</td></tr>
|
||||||
|
<tr><td><b>Transcription feels slow</b></td><td>You're likely on a larger model. Switch to <code>tiny.en</code> or <code>base.en-q5_1</code> in Settings. The <code>small</code> models are inherently slow on a two-core CPU.</td></tr>
|
||||||
|
<tr><td><b>Window vanished</b></td><td>It hid to the tray. Double-click the tray icon, press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>H</kbd>, or right-click the tray icon → Show Window.</td></tr>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- 13 -->
|
||||||
|
<section id="faq">
|
||||||
|
<div class="sec-h"><span class="sec-n">13</span><h2>FAQ & where things live</h2></div>
|
||||||
|
|
||||||
|
<h3>Does my voice get sent anywhere?</h3>
|
||||||
|
<p>No. All recording and transcription happen on your computer. The only time the app reaches the internet is when <em>you</em> click Download to fetch a model file.</p>
|
||||||
|
|
||||||
|
<h3>Can it run completely offline?</h3>
|
||||||
|
<p>Yes — once you have at least one model installed, no internet is needed ever again.</p>
|
||||||
|
|
||||||
|
<h3>What languages does it support?</h3>
|
||||||
|
<p>This build is tuned for <strong>English</strong> (the <code>.en</code> models). It's optimised for accuracy and speed in English on modest hardware.</p>
|
||||||
|
|
||||||
|
<h3>Where are my files kept?</h3>
|
||||||
|
<p>Everything sits next to <span class="path">win-dictation.exe</span>:</p>
|
||||||
|
<table class="tbl">
|
||||||
|
<tr><th>Location</th><th>What's there</th></tr>
|
||||||
|
<tr><td><span class="path">models\</span></td><td>Your downloaded <code>.bin</code> speech models.</td></tr>
|
||||||
|
<tr><td><span class="path">history\</span></td><td>One text file per dictation session.</td></tr>
|
||||||
|
<tr><td><span class="path">win-dictation.ini</span></td><td>Your settings, hotkey, window position, learned timing, and statistics.</td></tr>
|
||||||
|
<tr><td><span class="path">win-dictation.log</span></td><td>A simple timestamped activity log, handy if something misbehaves.</td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h3>How do I change the hotkey?</h3>
|
||||||
|
<p>Open <span class="path">win-dictation.ini</span> in any text editor and edit the <code>hkMods</code> and <code>hkVk</code> values under <code>[app]</code> (they're standard Windows key codes), then restart the app. A built-in settings option for this is a natural future addition.</p>
|
||||||
|
|
||||||
|
<h3>Why is it called “push-to-talk” if I'm not holding a button?</h3>
|
||||||
|
<p>It's toggle-style push-to-talk: one press starts, another stops. You're not transcribing live as you speak — you capture a clip, then it's processed. This is what keeps it fast and light on a CPU-only machine.</p>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<b>Win Dictation</b> · push-to-talk speech-to-text for Windows · powered by whisper.cpp (MIT)<br>
|
||||||
|
Default hotkey Ctrl+Shift+Space · CPU-only build · runs entirely offline
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('keydown', function(e) {
|
||||||
|
if (e.key === 'Escape' && window.parent !== window) {
|
||||||
|
window.parent.postMessage({ type: 'close-fullscreen' }, '*');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<!-- broken-img-handler -->
|
||||||
|
<script>
|
||||||
|
(function(){
|
||||||
|
if(window.__brokenImgHandler)return;
|
||||||
|
window.__brokenImgHandler=true;
|
||||||
|
var MAX=5,DELAYS=[2000,4000,8000,16000,32000];
|
||||||
|
document.addEventListener('error',function(e){
|
||||||
|
var img=e.target;
|
||||||
|
if(!img||img.tagName!=='IMG')return;
|
||||||
|
var liveSrc=img.getAttribute('src');
|
||||||
|
var src=img.dataset.haOriginalSrc||liveSrc;
|
||||||
|
if(!src)return;
|
||||||
|
if(img.dataset.haOriginalSrc&&liveSrc&&liveSrc!==img.dataset.haOriginalSrc&&liveSrc.indexOf('_r=')<0){src=liveSrc;img.dataset.haOriginalSrc=src;img.dataset.haRetryCount='0'}
|
||||||
|
else if(!img.dataset.haOriginalSrc){img.dataset.haOriginalSrc=src}
|
||||||
|
var attempt=parseInt(img.dataset.haRetryCount||'0',10);
|
||||||
|
if(img.dataset.haPhId){var old=document.getElementById(img.dataset.haPhId);if(old)old.remove()}
|
||||||
|
var ph=document.createElement('div');
|
||||||
|
ph.className='ha-img-placeholder'+(attempt>=MAX?' ha-failed':'');
|
||||||
|
ph.id='ha-ph-'+Math.random().toString(36).slice(2,9);
|
||||||
|
var w=img.getAttribute('width');var h=img.getAttribute('height');
|
||||||
|
if(w)ph.style.width=w+(isNaN(Number(w))?'':'px');
|
||||||
|
else if(img.style.width)ph.style.width=img.style.width;
|
||||||
|
else if(img.width>1)ph.style.width=img.width+'px';
|
||||||
|
if(h)ph.style.height=h+(isNaN(Number(h))?'':'px');
|
||||||
|
else if(img.style.height)ph.style.height=img.style.height;
|
||||||
|
else if(img.height>1)ph.style.height=img.height+'px';
|
||||||
|
ph.textContent=attempt>=MAX?'Image unavailable':'Loading image\u2026';
|
||||||
|
img.dataset.haPhId=ph.id;
|
||||||
|
if(img.dataset.haOrigDisplay==null)img.dataset.haOrigDisplay=img.style.display||'';
|
||||||
|
img.style.display='none';
|
||||||
|
img.insertAdjacentElement('afterend',ph);
|
||||||
|
if(attempt<MAX){
|
||||||
|
img.dataset.haRetryCount=String(attempt+1);
|
||||||
|
setTimeout(function(){
|
||||||
|
if(!img.isConnected)return;
|
||||||
|
if(img.dataset.haOriginalSrc!==src)return;
|
||||||
|
if(img.complete&&img.naturalWidth>0)return;
|
||||||
|
var curSrc=img.getAttribute('src');
|
||||||
|
if(curSrc&&curSrc.indexOf(src)!==0)return;
|
||||||
|
var fresh=src+(src.indexOf('?')>=0?'&':'?')+'_r='+(attempt+1)+'_'+Date.now();
|
||||||
|
img.src=fresh;
|
||||||
|
},DELAYS[attempt]);
|
||||||
|
}
|
||||||
|
},true);
|
||||||
|
document.addEventListener('load',function(e){
|
||||||
|
var img=e.target;
|
||||||
|
if(!img||img.tagName!=='IMG')return;
|
||||||
|
if(img.dataset.haPhId){
|
||||||
|
var ph=document.getElementById(img.dataset.haPhId);
|
||||||
|
if(ph)ph.remove();
|
||||||
|
delete img.dataset.haPhId;
|
||||||
|
img.style.display=img.dataset.haOrigDisplay||'';
|
||||||
|
delete img.dataset.haOrigDisplay;
|
||||||
|
delete img.dataset.haOriginalSrc;
|
||||||
|
delete img.dataset.haRetryCount;
|
||||||
|
}
|
||||||
|
},true);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user