Why Did I Build This?
"Most AI clients are generic wrappers around REST endpoints. I wanted to build a highly immersive, character-driven AI client (inspired by Serial Experiments Lain) that tests the boundaries of real-time Server-Sent Events (SSE) streaming paired with on-the-fly Text-to-Speech. It serves as an architectural study in managing asynchronous text streams, buffering sentences logically, and maintaining a non-blocking UI while simulating a 'living' digital entity."
Architecture & Decisions
The application utilizes Flutter with `Provider` for reactive state management. The core engine (`ChatProvider`) connects to the DeepSeek API using a continuous `http.Client` stream. As the JSON chunks arrive via SSE, they are decoded line-by-line (`utf8.decoder`, `LineSplitter()`), parsed, and rendered in real-time to the UI via a `MarkdownBody` widget. Concurrently, the text stream is fed into a Regex-based sentence buffer. Once a complete sentence is detected (via punctuation), it is immediately pushed to an asynchronous TTS queue (`flutter_tts`), ensuring the AI begins speaking instantly before the full network payload finishes downloading.
Key Features
- 01.Real-time Server-Sent Events (SSE) parsing for zero-latency LLM text streaming
- 02.Asynchronous TTS queue that logically chunks and vocalizes sentences on-the-fly
- 03.Native Speech-to-Text (STT) integration allowing hands-free voice interaction
- 04.Custom GPU-optimized CRT scanline overlay (`CustomPainter`) and audio-reactive UI animations
- 05.Persistent local storage via `path_provider` for offline multi-session chat history management