How devemperor/dictate works
<explanation>
1. Project Type and Purpose
- This is a single‑module Android application implementing a custom input method (keyboard) that captures user speech, sends it to OpenAI’s Whisper API for transcription, optionally post‑processes it via GPT‑4 Omni, and then injects the resulting text into any focused input field. It also provides onboarding, settings, prompt management and usage‑tracking UIs, backed by local SQLite databases and SharedPreferences.
2. Main Components
a. Android Framework (the container)
– InputMethodService lifecycle and UI hosting
– Activity stack hosting onboarding, settings, prompts, usage screens
– SharedPreferences for user settings
– SQLite databases (PromptsDatabaseHelper, UsageDatabaseHelper)
b. App‑specific Modules
– DictateInputMethodService (core IME service: audio capture → network → result insertion)
– Onboarding flow (OnboardingActivity + adapter + assets)
– Prompt management (PromptModel, PromptEditActivity, PromptsOverviewActivity + DB)
– Usage tracking (UsageModel, UsageActivity + DB)
– Settings UI (PreferencesFragment + DictateSettingsActivity + “how‑to” assets)
c. Local Storage
– SharedPreferences (via PreferencesFragment)
– Prompts SQLite DB
– Usage SQLite DB
– Static assets (HTML/TXT in assets/)
d. External Services
– OpenAI Whisper Speech‑to‑Text API
– OpenAI GPT‑4 Omni API for optional rewording
3. Relationships & Data Flows
- User taps mic on the custom keyboard → DictateInputMethodService
- Service records audio → streams to Whisper API → receives transcript
- (Optional) Service posts transcript to GPT‑4 Omni → receives reworded text
- Service inserts final text into host app via InputConnection
- Service logs each transcription event into Usage DB
- Prompt editing UIs read/write prompts into Prompts DB
- Settings UI reads/writes SharedPreferences
- Onboarding UI reads static assets to guide user through permissions, API‑key entry
4. Architectural Patterns & Principles
- Modular separation between UI (Activities/Fragments), service logic, data persistence, and networking
- Use of Android’s InputMethodService to isolate keyboard implementation
- Repository‑like pattern: database helper classes encapsulate DB operations
- Lean network layer: direct HTTP calls to OpenAI REST endpoints
- Asset‑driven static content for “how‑to” and key info
5. Diagramming Guidelines Tailored to This Mobile App
a. Draw a large “Android OS” box to contain all app components.
b. Inside it, group boxes by layer:
– UI Layer (Activities & Fragments) – color: green
– Service Layer (DictateInputMethodService) – color: blue
– Data Layer (SharedPreferences, Prompts DB, Usage DB) – color: orange
c. Outside the OS box, place “OpenAI Whisper API” and “OpenAI GPT‑4 Omni API” – color: red.
d. Use directed arrows:
– From Service → Whisper API (“audio stream/request”)
– From Whisper API → Service (“transcript response”)
– (Optional) Service ↔ GPT‑4 Omni (“rewording request/response”)
– Service → InputConnection (“insert text into host app”)
– Service → Usage DB (“log usage event”)
– UI → Prompts DB (“load/save prompts”)
– Settings UI → SharedPreferences (“read/write prefs”)
e. Indicate static assets flow: Onboarding UI → assets/ (HTML, TXT)
6. Notation & Styling
- Label every box with component name (e.g., “DictateInputMethodService”).
- Use solid arrows for synchronous calls/responses; dashed arrows for asynchronous logging.
- Use color coding as above, or distinct shapes (rounded for services, rectangles for data stores, cylinders for DBs).
- Add a legend explaining color/shape conventions.
7. Level of Detail
- Do not flatten everything into a single cloud of boxes. Instead, reflect Android’s layered architecture: separate UI/Service/Data.
- Capture key classes only (e.g., don’t list every activity’s adapter class individually—group them under “Prompt Management UI”).
- Highlight the dual API interactions (Whisper vs. GPT‑4 Omni).
By following these steps, you’ll produce a clear, accurate system design diagram that reflects how the Dictate Keyboard app is structured, how its components interact, and how it integrates with external AI services.