معلم التجويد - Flutter Quran Tajweed Recitation Assistant
A Flutter package for real-time Quranic recitation analysis using Google Gemini's Live API for Arabic transcription.
🎯 Key Features
- Smart Tajweed Feedback: Analyzes specific pronunciation errors with actionable feedback
- Tajweed Rule Detection: Identifies mismatches in Madd, articulation (Makharij), and emphatic sounds
- Real-time Transcription: Uses Gemini Live API for instant Arabic speech-to-text
- English Localization: Full English UI for Recitation Report and error messages
- Page-Based Display: 15-line layout matching traditional Mushaf format (604 pages)
- Word-by-Word Highlighting: Visual feedback as you recite with color-coded accuracy
- Quranic Typography: Authentic IndoPak and Uthmanic font support
- Clean UI: Modern Material Design 3 with Arabic language support
- Recitation Statistics: Accuracy metrics and detailed error summary
- Cross-Platform: iOS, Android support
📦 Installation
Add this to your package's pubspec.yaml file:
dependencies:
flutter_quran_tajwid: ^1.0.2
Then run:
flutter pub get
🚀 Usage
Import the package:
import 'package:flutter_quran_tajwid/flutter_quran_tajwid.dart';
Initialize in your main():
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await QuranJsonService().initialize();
runApp(const ProviderScope(child: MyApp()));
}
Use the RecitationScreen widget with a page number (1-604):
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const RecitationScreen(initialPageNumber: 1), // Specify initial page number
);
}
}
⚠️ Important Notes
API Key Required
You need a Google Gemini API key for transcription to work:
- Get your key from Google AI Studio
- Configure it in your app (see example for
.envsetup)
📱 Example App
The example folder contains a complete demonstration. To run it:
cd example
flutter pub get
# Create .env file with your API key
echo "GEMINI_API_KEY=your_api_key_here" > .env
flutter run
🏗️ Project Structure
lib/
├── main.dart # App entry point
├── models/ # Data models
│ ├── highlighted_word.dart
│ ├── recitation_summary.dart
│ └── surah.dart
├── services/ # Business logic
│ ├── gemini_live_service.dart # Gemini API integration
│ ├── tajweed_feedback_service.dart # Smart feedback logic
│ ├── audio_recording_service.dart
│ └── quran_service.dart # Quran data (114 Surahs)
├── providers/ # Riverpod state management
│ └── app_state.dart
├── screens/ # UI screens
│ └── recitation_screen.dart
├── widgets/ # Reusable widgets
│ ├── audio_visualizer.dart
│ ├── surah_display.dart
│ └── recitation_summary_widget.dart
└── utils/ # Utilities
└── arabic_utils.dart
🔑 Key Components
Gemini Live Service
- WebSocket connection to
wss://generativelanguage.googleapis.com - PCM audio at 16kHz mono format
- Real-time Arabic transcriptions
- Connection state and error handling
Quran Service
- 114 Complete Surahs with full text
- Local Hive-based caching
- Fast surah lookup and search
- Automatic cache management
Audio Recording
- Records at 16kHz PCM (optimal for speech recognition)
- Real-time streaming to Gemini
- Automatic microphone selection
- Permission handling
State Management (Riverpod)
- Centralized state for all app data
- Reactive UI updates
- Word matching and error detection logic
- Transcription queue processing
🎤 How It Works
- Select a Surah from the dropdown (Arabic interface)
- Press "ابدأ الترتيل" (Start Reciting)
- App automatically connects to Gemini Live API
- Speak the Quranic text
- Words are transcribed in real-time
- Color Coding:
- 🟢 Green - Correctly recited words
- 🔴 Red - Tajweed errors detected
- ⚪ Gray - Not yet recited
- Press "إيقاف" (Stop) to end and view detailed summary
⚙️ Configuration
Audio Quality
- Sample Rate: 16kHz (optimal for speech recognition)
- Format: PCM 16-bit mono
- Bit Rate: 128 kbps
Gemini Model
- Model:
gemini-2.0-flash-exp - Language: Arabic (ar)
- WebSocket: Multimodal Live API
- Input Transcription: Enabled
Fonts
- Quran Display: IndoPak or Uthmanic Hafs
- UI Elements: Noto Naskh Arabic (modern, readable)
🐛 Troubleshooting
Fonts Not Displaying
- Ensure all font files are in
assets/fonts/ - Run
flutter clean && flutter pub get - Restart the app
Microphone permission denied
- iOS: Settings > Privacy > Microphone > Allow
- Android: App Settings > Permissions > Microphone
No transcription received
- Verify API key is correct in
.env - Check internet connection
- Test microphone in device settings
- Ensure audio is being recorded (check visualizer)
WebSocket connection failed
- Validate API key with simple test request
- Check network connectivity
- Try disabling VPN/proxy
📦 Dependencies
- riverpod: State management
- record: Audio recording
- web_socket_channel: WebSocket communication
- hive: Local data caching
- flutter_dotenv: Environment variables
🔄 Future Enhancements
xEnglish LocalizationxSmart Tajweed FeedbackxFull Quran Navigation (1-604 pages)xDetailed Tajweed rules explanationProgress tracking and historyAdjustable recitation speedExport recitation results as PDFLeaderboard and achievementsMulti-language UI support
📄 License
Apache 2.0
👤 Support
For issues or questions:
Libraries
- flutter_quran_tajwid
- models/highlighted_word
- models/llm_config
- models/recitation_result
- models/recitation_summary
- models/surah
- onboarding/auth/forgot_password_screen
- onboarding/kyc/personal_info_screen
- onboarding/router/onboarding_routes
- onboarding/theme/onboarding_theme
- onboarding/widgets/otp_fields
- providers/app_state
- screens/recitation_screen
- services/audio_analysis_service
- services/audio_matching_service
- services/audio_recording_service
- services/debug_highlighting_service
- services/fuzzy_matching_service
- services/gemini_live_service
- services/quran_json_service
- services/quran_service
- services/tajweed_feedback_service
- utils/arabic_utils
- utils/font_loader
- utils/surah_names
- widgets/audio_visualizer
- widgets/recitation_summary_widget
- widgets/surah_display