Lain AI: Streamed DeepSeek Persona Chat & Voice Client
A mobile AI chat interface leveraging the DeepSeek API to simulate conversations with the 'Lain Iwakura' persona. Features real-time SSE streaming, asynchronous chunked Text-to-Speech, and a custom retro CRT overlay.
Tech stack
- Languages
Performance & metrics
- Prevents UI freezing during active API streaming by isolating byte-chunk decoding to asynchronous tasks
- Dramatically reduces perceived TTS latency by vocalizing text at the first punctuation mark rather than waiting for the entire LLM response
- Efficient
CustomPainterimplementation for the CRT scanline effect ensures minimal rendering overhead and maintains stable 60 FPS
Why I built it
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
- 01Real-time Server-Sent Events (SSE) parsing for zero-latency LLM text streaming
- 02Asynchronous TTS queue that logically chunks and vocalizes sentences on-the-fly
- 03Native Speech-to-Text (STT) integration allowing hands-free voice interaction
- 04Custom GPU-optimized CRT scanline overlay (
CustomPainter) and audio-reactive UI animations - 05Persistent local storage via
path_providerfor offline multi-session chat history management
Technical review
This project perfectly demonstrates how to handle raw, streaming LLM data in a mobile environment. By intercepting raw SSE data, extracting delta chunks, and buffering them into logical sentence blocks for the native TTS engine, the application achieves a highly responsive, conversational flow. The strict adherence to an injected system prompt enforces the 'Lain' persona at the API level, turning a standard LLM endpoint into a fully immersive, voice-enabled digital companion.
Related projects
Mobile Applications
WonderNest: Interactive EdTech & Telemetry Application
A gamified, co-learning mobile application designed for early childhood education. It combines highly animated biological taxonomy modules (habitats, diets, acoustics) with a secure, telemetry-driven parent dashboard for granular progress tracking.
- Dart
- Flutter
- Provider
- +4
Look Back Fan App
A mobile app developed for the anime community, featuring real-time messaging and commenting via WebSockets.
- Dart
- Flutter
- Firebase
- +1
Smart PDF Reader & TDK Dictionary Assistant
A hybrid PDF and text reading engine designed to eliminate context switching, featuring on-the-fly TDK dictionary translations and local NoSQL memory tracking.
- Dart
- Flutter
- Hive (NoSQL)
- +3
Need something similar?
I can build a system like this for you, too.
Describe your project in a few sentences, and we'll work out the right approach and an estimated scope together.