2.8 KiB
2.8 KiB
Windows Dictation App Design Document
Goals
- Create a "polished" Windows app for dictation.
- Small memory footprint.
- Real-time transcription.
- Global hotkey support.
- On-demand GPU usage.
Architecture
The application is a native Win32 C++ application. It avoids heavy UI frameworks (Electron, .NET, Qt) to strictly adhere to the "small memory footprint" requirement and integration with the C++ codebase.
Components
-
Main Entry (
WinMain):- Initializes the application.
- Registers the global hotkey (
RegisterHotKey). - Creates the main window (hidden by default).
- Creates the System Tray icon (
Shell_NotifyIcon). - Runs the standard Windows Message Loop.
-
UI Layer (Win32 API):
- Main Window: A simple Dialog or Window containing:
EDITcontrol (Multiline, VScroll) for text output.BUTTONcontrols for Record/Stop/Clear.STATUSbar for model state.
- Tray Icon: Context menu for Open/Exit.
- Main Window: A simple Dialog or Window containing:
-
Audio & Inference Layer (
Transcriber):- Runs in a separate Worker Thread to prevent freezing the UI.
- Audio Capture: Uses
SDL2(reusingcommon-sdl.cpplogic) for cross-platform consistency with the repo, or potentially native WASAPI if dependencies become an issue. For now, SDL2 is assumed as it's standard in this repo. - Inference: Uses
whisper.cpplibrary (whisper_full). - VAD (Voice Activity Detection): Uses the simple energy-based VAD from
common.cppto detect when to transcribe.
Threading Model
- UI Thread: Handles Windows messages, paints the UI, processes hotkeys.
- Worker Thread:
- Loops continuously when "Recording" is active.
- Captures PCM audio chunks.
- Runs
whisper_fullon the buffer. - Uses
PostMessage(hWindow, WM_USER_TEXT_READY, ...)to send transcribed text back to the UI thread safely.
Resource Management (GPU/Memory)
- Startup: Does not load the model immediately to save RAM/VRAM.
- On Record: Checks if context exists. If not, loads the model (
whisper_init_from_file). - Inactive Timeout: A timer in the UI thread monitors inactivity. If inactive for X minutes, it signals the worker to destroy the whisper context (
whisper_free), releasing VRAM.
Key APIs
RegisterHotKey: For global shortcuts.Shell_NotifyIcon: For system tray.CreateWindowEx/DialogBox: For UI.whisper_full: For inference.
File Structure
main.cpp: Entry point, Window Proc, Message Loop.transcriber.h/cpp: Wraps the Whisper context and SDL audio loop.resource.rc: Defines the UI layout (dialogs, menus, icons).CMakeLists.txt: Build definition.
Future Improvements
- Settings dialog to select Model path.
- Select Audio Input device.