project-f92029b8

byAkhilesh

This is a comprehensive specification for a fully offline-first translation app. Building this with Flutter and on-device AI models is an ambitious but achievable project. The key challenge is balancing model size (storage) with performance (speed/RAM) while ensuring true offline functionality. Below is a technical roadmap and implementation guide to build this app, focusing on the Offline-First Architecture you described. 1. Technology Stack & Model Selection To achieve true offline capability, we cannot rely on standard API calls. We must use ONNX Runtime or TensorFlow Lite to run models directly on the device. FeatureRecommended TechModel/EngineNotesFrameworkFlutterN/ACross-platform (iOS/Android).TranslationONNX RuntimeNLLB-200 (Distilled) or MarianMTNLLB supports 200+ languages. Distilled versions are smaller for mobile.Speech-to-Textflutter_whisper or onnxruntime_whisperWhisper-tiny or base"Tiny" is ~75MB, fast enough for mobile.Text-to-Speechflutter_ttsPlatform NativeUses Android/iOS built-in TTS (no model download needed).OCRgoogle_mlkit_text_recognitionML KitWorks fully offline on device.Databasesqflite / driftSQLiteLocal storage for history, favorites, user data.Bluetoothflutter_blue_plusN/AFor P2P messaging.State ManagementRiverpodN/ARobust state management for complex flows. 2. Project Structure Organize your lib/ folder to handle the complexity of offline models and multiple features. text Copy lib/ ├── main.dart ├── app.dart ├── core/ │ ├── constants/ (app colors, strings) │ ├── utils/ (helpers, formatters) │ └── theme/ ├── features/ │ ├── translation/ │ │ ├── services/ (translation_engine, ocr_service, speech_service) │ │ ├── widgets/ (input_field, result_card) │ │ └── screens/ (text_translate_screen.dart) │ ├── conversation/ │ │ └── screens/ (conversation_mode_screen.dart) │ ├── camera/ │ │ └── screens/ (camera_translate_screen.dart) │ ├── dictionary/ │ │ └── services/ (offline_dictionary_service) │ ├── emergency/ │ │ └── screens/ (emergency_mode_screen.dart) │ └── settings/ │ └── screens/ (download_models_screen.dart) ├── data/ │ ├── database/ (db_helper, tables) │ ├── models/ (user, translation_history, favorite) │ └── repositories/ (local_translation_repo) ├── providers/ (Riverpod providers for state) └── widgets/ (shared UI components) 3. Core Implementation Details A. Offline Translation Engine (NLLB/Marian) You cannot simply "call" a model; you must convert it to ONNX format and bundle it with the app (or download it once). Step 1: Convert Model Use Python to convert a HuggingFace model (e.g., facebook/nllb-200-distilled-600M) to ONNX. Note: For a mobile app, you might need to quantize the model (int8) to reduce size from ~500MB to ~100MB. Step 2: Flutter Integration Use onnxruntime_flutter (or a similar package). dart Copy // lib/features/translation/services/translation_service.dart import 'package:onnxruntime/onnxruntime.dart'; import 'package:flutter/services.dart'; class OfflineTranslationService { late OrtSession _session; bool _isInitialized = false; Future<void> init() async { if (_isInitialized) return; // Load the model from assets final bytes = await rootBundle.load('assets/models/nllb_distilled.onnx'); final buffer = bytes.buffer.asUint8List(); final options = OrtSessionOptions(); // Enable CPU optimizations options.setIntraOpNumThreads(4); options.setGraphOptimizationLevel(GraphOptimizationLevel.ORT_ENABLE_ALL); _session = await OrtSession.create(buffer, options); _isInitialized = true; } Future<String> translate(String text, String sourceLang, String targetLang) async { if (!_isInitialized) await init(); // 1. Preprocess: Tokenize text (requires a tokenizer bundle) // 2. Create input tensor // 3. Run session // 4. Postprocess: Detokenize to string // Pseudo-code for the actual inference // final outputs = await _session.run(inputs); // return decode(outputs); return "Translated Text"; // Placeholder } } B. Voice & Conversation Mode Use flutter_whisper for STT and flutter_tts for TTS. dart Copy // lib/features/conversation/services/speech_service.dart import 'package:flutter_whisper/flutter_whisper.dart'; class SpeechService { final FlutterWhisper _whisper = FlutterWhisper(); Future<String> recognizeSpeech() async { // Records audio and returns text return await _whisper.transcribe(); } Future<void> speak(String text) async { // Uses native platform TTS await FlutterTts().speak(text); } } C. Camera Translation (OCR + Overlay) Use google_mlkit_text_recognition for OCR. The "Overlay" requires camera package and custom_paint. Capture: Take image via camera plugin. OCR: Run ML Kit text recognition. Translate: Pass extracted text to OfflineTranslationService. Render: Use Stack widget to draw original text (transparent) and translated text (on top). D. Bluetooth Messaging (Offline P2P) Use flutter_blue_plus to create a simple chat. Mode: Device A acts as Peripheral, Device B as Central (or vice versa). Flow: Scan for devices. Connect. Send raw text string. Receive text -> Auto-translate -> Display. E. Emergency Mode A dedicated screen with hardcoded, high-priority phrases. Data: Store these in a local JSON file or constant list. No model inference needed for speed. UI: Large, high-contrast buttons. Action: Tap button -> Speak phrase immediately via TTS. 4. Database Schema (SQLite) Use drift (Moor) or sqflite to manage local data. sql Copy -- Users Table CREATE TABLE users ( id INTEGER PRIMARY KEY, name TEXT, email TEXT, guest_mode BOOLEAN DEFAULT 1 ); -- Translation History CREATE TABLE history ( id INTEGER PRIMARY KEY AUTOINCREMENT, source_text TEXT, target_text TEXT, source_lang TEXT, target_lang TEXT, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP ); -- Saved Phrases / Favorites CREATE TABLE favorites ( id INTEGER PRIMARY KEY AUTOINCREMENT, phrase TEXT, category TEXT, -- 'Hospital', 'Airport', etc. lang TEXT ); -- Downloaded Models CREATE TABLE models ( lang_pair TEXT PRIMARY KEY, file_path TEXT, size_mb REAL, is_downloaded BOOLEAN ); 5. Development Roadmap Phase 1: Core Offline Engine (MVP) Set up Flutter project. Convert NLLB or Marian model to ONNX and bundle it. Implement OfflineTranslationService (Text -> Text). Build Home Screen with language selection. Implement Text Translation screen. Phase 2: Voice & Camera Integrate flutter_whisper (Whisper-tiny). Integrate google_mlkit_text_recognition. Build Conversation Mode (Turn-taking UI). Build Camera Translation (OCR + Overlay). Phase 3: Advanced Features Dictionary: Build a local JSON dictionary for "Offline Dictionary" feature. Emergency Mode: Hardcoded UI flow. Bluetooth: Implement flutter_blue_plus for P2P chat. QR Chat: Use qr_flutter to generate QR codes containing text; scan with mobile_scanner. Phase 4: Optimization & Polish Model Quantization: Reduce model size for faster loading. Performance: Ensure translation < 1s for common phrases. UI/UX: Add animations, dark mode, and "Saved Phrases" categories. Testing: Test on low-end Android devices (critical for offline apps). 6. Critical Challenges & Solutions ChallengeSolutionApp SizeModels are large. Use App Bundle to download models on first run (optional) or provide a "Lite" version with only 5 languages.RAM LimitsLoad models lazily. Unload unused models from memory. Use int8 quantization.Battery DrainOptimize loop rates. Do not run OCR or Speech recognition in the background unless necessary.Language DetectionUse flutter_language_detector (on-device) or a small NLP model for auto-detection. 7. Next Steps to Start Coding Initialize Project: bash Copy flutter create offline_translator cd offline_translator flutter pub add flutter_tts flutter_whisper google_mlkit_text_recognition qr_flutter mobile_scanner flutter_blue_plus sqflite drift riverpod onnxruntime Get the Model: Download a distilled NLLB model from HuggingFace. Convert to ONNX using optimum library in Python. Place model.onnx in assets/models/. Build the Shell: Create the splash screen and language selection. Implement the "Text Translate" screen first. build this fully offline androde workable app

LandingConversationBluetooth
Landing

Comments (0)

No comments yet. Be the first!

System Requirements

System Requirement Document
Page 1 of 5

project-f92029b8 System Requirements Document

Introduction

This document outlines the system requirements for project-f92029b8, a fully offline-first translation app. The app will be developed using Flutter and on-device AI models, focusing on achieving true offline functionality. The key challenge is balancing model size with performance while ensuring offline capabilities.

System Overview

Project-f92029b8 aims to provide a comprehensive translation solution that operates entirely offline. The app will leverage on-device AI models for translation, speech-to-text, text-to-speech, OCR, and Bluetooth messaging. The architecture will be designed to handle the complexity of offline models and multiple features, ensuring a seamless user experience across various functionalities.

Page 2 of 5

Functional Requirements as Story Points

  • As a User, I should be able to translate text between multiple languages offline.
  • As a User, I should be able to use speech-to-text functionality offline.
  • As a User, I should be able to use text-to-speech functionality offline.
  • As a User, I should be able to perform OCR on images offline.
  • As a User, I should be able to send and receive messages via Bluetooth offline.
  • As a User, I should be able to access emergency phrases quickly and have them spoken aloud.
  • As a User, I should be able to save favorite phrases for quick access.
  • As a User, I should be able to view my translation history.
  • As a User, I should be able to manage downloaded language models.

User Personas

  • Regular User: Uses the app for personal translation needs, including text, speech, and image translations.
  • Traveler: Requires quick access to emergency phrases and offline capabilities due to limited internet access.
  • Language Learner: Uses the app to learn new languages and save favorite phrases for practice.
  • Business Professional: Utilizes the app for translating documents and conversations in professional settings.

Core User Flows

  • User selects languages -> Inputs text -> Receives translated text
  • User speaks into the app -> App transcribes speech -> Displays text
  • User captures image -> App performs OCR -> Displays extracted text -> Translates text
  • User connects to another device via Bluetooth -> Sends message -> Receives translated message
  • User accesses emergency mode -> Selects phrase -> App speaks phrase aloud
Page 3 of 5

Visuals Colors and Theme

  • primary: #1E3A8A (Deep Blue)
  • primary_light: #3B82F6 (Light Blue)
  • secondary: #F59E0B (Amber)
  • accent: #EF4444 (Red)
  • highlight: #FBBF24 (Gold)
  • bg: #F3F4F6 (Light Gray)
  • surface: rgba(255, 255, 255, 0.8)
  • text: #111827 (Dark Gray)
  • text_muted: #6B7280 (Muted Gray)
  • border: rgba(209, 213, 219, 0.2)

Signature Design Concept

The homepage will feature an interactive translation globe. Users can spin the globe to select languages, and as they do, the globe will display real-time translations of common phrases in the selected languages. The globe will be animated using motion/react to provide a smooth, engaging experience. Hovering over a country will highlight it and display the language spoken there, creating an educational and interactive experience.

Landing Hero Motion Brief

The hero section will depict a user inputting text into a device, which then transforms into a globe that spins to reveal translated phrases in various languages. The animation will loop every 10 seconds, showcasing the app's ability to handle multiple languages seamlessly. The animation will be built using motion/react to ensure smooth transitions and interactions.

Page 4 of 5

Interaction Model & Motion Direction

  • Interaction Model: Animated
  • The landing page will feature moderate scroll-triggered reveals and hover transitions, enhancing user engagement without overwhelming them with excessive motion.

Non-Functional Requirements

  • The app must operate entirely offline, with no reliance on external APIs for core functionalities.
  • The app should load translations in under 1 second for common phrases.
  • The app should be optimized for low-end Android devices to ensure accessibility.

Tech Stack

  • Frontend: Flutter
  • Backend: ONNX Runtime or TensorFlow Lite for on-device AI models
  • Database: SQLite (using sqflite or drift)
  • AI Models: NLLB-200 (Distilled) or MarianMT for translation, Whisper-tiny for speech-to-text
  • State Management: Riverpod

Assumptions and Constraints

  • The app will be developed for both iOS and Android platforms using Flutter.
  • On-device AI models will be used to ensure offline functionality.
  • The app will prioritize performance and storage optimization to accommodate low-end devices.
Page 5 of 5

Glossary

  • ONNX Runtime: An open-source library for running machine learning models.
  • TensorFlow Lite: A lightweight version of TensorFlow designed for mobile and embedded devices.
  • OCR: Optical Character Recognition, a technology used to convert different types of documents into editable and searchable data.
  • TTS: Text-to-Speech, a technology that converts text into spoken voice output.
Landing design preview
Landing: View Overview
Home: Select Languages
Camera: Capture Document
Camera: View OCR Translation
Conversation: Translate Conversation
Bluetooth: Send Message
Bluetooth: Receive Message
History: View History
Landing design preview
Landing: View Overview
Home: Select Languages
Camera: Capture Document
Camera: View OCR Translation
Conversation: Translate Conversation
Bluetooth: Send Message
Bluetooth: Receive Message
History: View History