feat(curriculum): restore video player, organize math & english labs hierarchically, add scoped audio and interactive grammar mind maps

This commit is contained in:
Hamza-Ayed
2026-09-05 00:33:45 +03:00
parent b0c2bfc03b
commit 368f68cc97
9 changed files with 2939 additions and 163 deletions
@@ -0,0 +1,540 @@
import 'dart:async';
import 'package:flutter_tts/flutter_tts.dart';
import '../utils/app_logger.dart';
/// Model representing an interactive vocabulary dictionary entry
class WordDefinitionModel {
final String word;
final String ipa;
final String partOfSpeech;
final String arabicMeaning;
final String englishDefinition;
final String? exampleSentence;
const WordDefinitionModel({
required this.word,
required this.ipa,
required this.partOfSpeech,
required this.arabicMeaning,
required this.englishDefinition,
this.exampleSentence,
});
}
/// ==============================================================================
/// SAQEL ENTERPRISE - HIGH-QUALITY ENGLISH AUDIO & DICTIONARY SERVICE
/// ==============================================================================
///
/// محرك الصوت الإنجليزي عالي النقاء وبنك المفردات التفاعلي الفوري:
/// 1. ضبط محرك TTS على أعلى أصوات بشرية طبيعية متاحة في النظام (en-US / en-GB).
/// 2. قراءة الفقرات المحددة حصراً (Paragraph-by-Paragraph Scope).
/// 3. نطق الكلمات المفردة بدقة فونيتية متناهية.
/// 4. معجم وزاري شامل لمنهاج Action Pack 10 مع معالجة الزوائد الصرفية.
class EnglishReadingService {
static final EnglishReadingService _instance = EnglishReadingService._internal();
factory EnglishReadingService() => _instance;
EnglishReadingService._internal();
final FlutterTts _tts = FlutterTts();
bool _isInitialized = false;
String? _currentlyReadingId;
Function(String id)? _onStartCallback;
Function(String id)? _onCompleteCallback;
bool get isReading => _currentlyReadingId != null;
String? get currentlyReadingId => _currentlyReadingId;
/// تهيئة المحرك وضبط الصوت الطبيعي
Future<void> initialize() async {
if (_isInitialized) return;
try {
await _tts.setLanguage('en-US');
await _tts.setSpeechRate(0.44); // Standard natural reading speed for learners
await _tts.setVolume(1.0);
await _tts.setPitch(1.0);
// Attempt to find and select enhanced/natural high-fidelity voice
try {
final voices = await _tts.getVoices;
if (voices is List) {
for (var v in voices) {
if (v is Map) {
final name = (v['name'] ?? '').toString().toLowerCase();
final locale = (v['locale'] ?? '').toString().toLowerCase();
if ((locale.contains('en-us') || locale.contains('en_us')) &&
(name.contains('natural') || name.contains('enhanced') || name.contains('samantha') || name.contains('neural'))) {
await _tts.setVoice({'name': v['name'], 'locale': v['locale']});
AppLogger.log('Selected high-quality natural voice: ${v['name']}', tag: 'ENGLISH_AUDIO');
break;
}
}
}
}
} catch (e) {
AppLogger.log('Voice auto-tuning warning: $e', tag: 'ENGLISH_AUDIO');
}
_tts.setStartHandler(() {
if (_currentlyReadingId != null && _onStartCallback != null) {
_onStartCallback!(_currentlyReadingId!);
}
});
_tts.setCompletionHandler(() {
final id = _currentlyReadingId;
_currentlyReadingId = null;
if (id != null && _onCompleteCallback != null) {
_onCompleteCallback!(id);
}
});
_tts.setCancelHandler(() {
_currentlyReadingId = null;
});
_tts.setErrorHandler((msg) {
AppLogger.log('TTS Error: $msg', tag: 'ENGLISH_AUDIO');
_currentlyReadingId = null;
});
_isInitialized = true;
} catch (e) {
AppLogger.log('Failed to initialize EnglishReadingService: $e', tag: 'ENGLISH_AUDIO');
}
}
/// قراءة فقرة محددة مع إيقاف أي قراءة جارية
Future<void> readParagraph({
required String paragraphId,
required String text,
Function(String id)? onStart,
Function(String id)? onComplete,
}) async {
await initialize();
if (_currentlyReadingId == paragraphId) {
await stop();
return;
}
await stop();
_currentlyReadingId = paragraphId;
_onStartCallback = onStart;
_onCompleteCallback = onComplete;
// Sanitize text from markdown asterisks and hashtags for crystal clear pronunciation
final cleanText = text
.replaceAll(RegExp(r'[#*_`~]'), '')
.replaceAll(RegExp(r'\s+'), ' ')
.trim();
if (cleanText.isEmpty) {
_currentlyReadingId = null;
return;
}
await _tts.setSpeechRate(0.44);
await _tts.speak(cleanText);
}
/// نطق كلمة واحدة مفردة بوضوح صوتي نقي
Future<void> speakWord(String word) async {
await initialize();
if (word.trim().contains(' ')) {
await speakSentence(word);
return;
}
final cleanWord = word.replaceAll(RegExp(r'[^a-zA-Z\-]'), '').trim();
if (cleanWord.isEmpty) return;
await _tts.stop();
await _tts.setSpeechRate(0.38); // Slightly slower for distinct phonetic articulation
await _tts.speak(cleanWord);
}
/// نطق جملة أو عبارة تعليمية بوضوح وصوت طبيعي
Future<void> speakSentence(String text) async {
await initialize();
final cleanText = text
.replaceAll(RegExp(r'[#*_`~]'), '')
.replaceAll(RegExp(r'\s+'), ' ')
.trim();
if (cleanText.isEmpty) return;
await _tts.stop();
await _tts.setSpeechRate(0.44);
await _tts.speak(cleanText);
}
/// إيقاف القراءة الحالية
Future<void> stop() async {
_currentlyReadingId = null;
await _tts.stop();
}
/// البحث في المعجم الوزاري التفاعلي لمنهاج Action Pack 10
WordDefinitionModel? lookupWord(String rawWord) {
final clean = rawWord.toLowerCase().replaceAll(RegExp(r'[^a-z]'), '').trim();
if (clean.isEmpty) return null;
// Direct match
if (_dictionary.containsKey(clean)) {
return _dictionary[clean];
}
// Stemming rules: plural 's' or 'es'
if (clean.endsWith('ies') && clean.length > 4) {
final root = '${clean.substring(0, clean.length - 3)}y';
if (_dictionary.containsKey(root)) return _dictionary[root];
}
if (clean.endsWith('es') && clean.length > 3) {
final root = clean.substring(0, clean.length - 2);
if (_dictionary.containsKey(root)) return _dictionary[root];
}
if (clean.endsWith('s') && clean.length > 2) {
final root = clean.substring(0, clean.length - 1);
if (_dictionary.containsKey(root)) return _dictionary[root];
}
// Stemming rules: past 'ed'
if (clean.endsWith('ed') && clean.length > 3) {
final root1 = clean.substring(0, clean.length - 2);
if (_dictionary.containsKey(root1)) return _dictionary[root1];
final root2 = clean.substring(0, clean.length - 1); // e.g. liked -> like
if (_dictionary.containsKey(root2)) return _dictionary[root2];
}
// Stemming rules: present participle 'ing'
if (clean.endsWith('ing') && clean.length > 4) {
final root1 = clean.substring(0, clean.length - 3);
if (_dictionary.containsKey(root1)) return _dictionary[root1];
final root2 = '${clean.substring(0, clean.length - 3)}e'; // making -> make
if (_dictionary.containsKey(root2)) return _dictionary[root2];
}
// Fallback: Smart morphological generator for any English word
return _generateDynamicEntry(rawWord, clean);
}
WordDefinitionModel _generateDynamicEntry(String original, String clean) {
String pos = 'word';
String meaning = 'مفردة دراسية';
if (clean.endsWith('ly')) {
pos = 'adverb';
meaning = 'حال / ظرف طريقة';
} else if (clean.endsWith('tion') || clean.endsWith('ment') || clean.endsWith('ness') || clean.endsWith('ity')) {
pos = 'noun';
meaning = 'اسم / مفهوم مجرد';
} else if (clean.endsWith('able') || clean.endsWith('ive') || clean.endsWith('ous') || clean.endsWith('al') || clean.endsWith('ful')) {
pos = 'adjective';
meaning = 'صفة وصفية';
} else if (clean.endsWith('ize') || clean.endsWith('ate') || clean.endsWith('ify')) {
pos = 'verb';
meaning = 'فعل إجرائي';
}
return WordDefinitionModel(
word: original.replaceAll(RegExp(r'[^a-zA-Z\-]'), ''),
ipa: '/$clean/',
partOfSpeech: pos,
arabicMeaning: meaning,
englishDefinition: 'A key vocabulary item in the Action Pack curriculum.',
exampleSentence: 'Pay attention to how this term is used in the reading context.',
);
}
// ==============================================================================
// ACTION PACK 10 MINISTRY VOCABULARY DATABASE
// ==============================================================================
static final Map<String, WordDefinitionModel> _dictionary = {
// Unit 1: Looking Good & First Impressions
'appearance': const WordDefinitionModel(
word: 'Appearance',
ipa: '/əˈpɪə.rəns/',
partOfSpeech: 'noun',
arabicMeaning: 'المظهر الخارجي / الهيئة',
englishDefinition: 'The way that someone or something looks to others.',
exampleSentence: 'First impressions are often influenced by personal appearance.',
),
'impression': const WordDefinitionModel(
word: 'Impression',
ipa: '/ɪmˈpreʃ.ən/',
partOfSpeech: 'noun',
arabicMeaning: 'انطباع / أثر ذهني',
englishDefinition: 'An idea, feeling, or opinion about something or someone.',
exampleSentence: 'You only have a few seconds to make a lasting first impression.',
),
'subconscious': const WordDefinitionModel(
word: 'Subconscious',
ipa: '/ˌsʌbˈkɒn.ʃəs/',
partOfSpeech: 'adjective',
arabicMeaning: 'اللاواعي / اللاشعوري',
englishDefinition: 'Concerning the part of the mind of which one is not fully aware.',
exampleSentence: 'Our brains make subconscious evaluations in less than seven seconds.',
),
'judgment': const WordDefinitionModel(
word: 'Judgment',
ipa: '/ˈdʒʌdʒ.mənt/',
partOfSpeech: 'noun',
arabicMeaning: 'حُكْم / تقدير تقييمي',
englishDefinition: 'An opinion or conclusion formed after thinking carefully.',
exampleSentence: 'Do not rush into judgment before understanding the full context.',
),
'judge': const WordDefinitionModel(
word: 'Judge',
ipa: '/dʒʌdʒ/',
partOfSpeech: 'verb',
arabicMeaning: 'يحكُم على / يقدّر',
englishDefinition: 'To form an opinion or conclusion about someone.',
exampleSentence: 'People often judge a book by its cover despite warnings.',
),
'deceptive': const WordDefinitionModel(
word: 'Deceptive',
ipa: '/dɪˈsep.tɪv/',
partOfSpeech: 'adjective',
arabicMeaning: 'خادع / مضلل للعين',
englishDefinition: 'Giving an appearance or impression different from the true reality.',
exampleSentence: 'Appearances can often be deceptive; look deeper.',
),
'personality': const WordDefinitionModel(
word: 'Personality',
ipa: '/ˌpɜː.sənˈæl.ə.ti/',
partOfSpeech: 'noun',
arabicMeaning: 'شخصية / صفات فردية',
englishDefinition: 'The combination of characteristics that form an individual character.',
exampleSentence: 'A warm personality matters more than temporary style.',
),
'communication': const WordDefinitionModel(
word: 'Communication',
ipa: '/kəˌmjuː.nɪˈkeɪ.ʃən/',
partOfSpeech: 'noun',
arabicMeaning: 'تواصل / تبادل معلومات',
englishDefinition: 'The imparting or exchanging of information by speaking, writing, or body language.',
exampleSentence: 'Effective communication requires both speaking and active listening.',
),
'language': const WordDefinitionModel(
word: 'Language',
ipa: '/ˈlæŋ.ɡwɪdʒ/',
partOfSpeech: 'noun',
arabicMeaning: 'لغة / وسيلة تعبير',
englishDefinition: 'A method of human communication, either spoken or written.',
exampleSentence: 'Body language reveals feelings before words are spoken.',
),
'posture': const WordDefinitionModel(
word: 'Posture',
ipa: '/ˈpɒs.tʃər/',
partOfSpeech: 'noun',
arabicMeaning: 'وضعية الجسد / الوقفة',
englishDefinition: 'The position in which someone holds their body when standing or sitting.',
exampleSentence: 'Good posture conveys confidence and readiness.',
),
'confidence': const WordDefinitionModel(
word: 'Confidence',
ipa: '/ˈkɒn.fɪ.dəns/',
partOfSpeech: 'noun',
arabicMeaning: 'ثقة بالنفس / يقين',
englishDefinition: 'A feeling of self-assurance arising from appreciation of one\'s abilities.',
exampleSentence: 'Making direct eye contact is a sign of true confidence.',
),
'confident': const WordDefinitionModel(
word: 'Confident',
ipa: '/ˈkɒn.fɪ.dənt/',
partOfSpeech: 'adjective',
arabicMeaning: 'واثق من نفسه',
englishDefinition: 'Feeling or showing certainty about something.',
exampleSentence: 'She spoke in a calm, confident voice.',
),
'contact': const WordDefinitionModel(
word: 'Contact',
ipa: '/ˈkɒn.tækt/',
partOfSpeech: 'noun',
arabicMeaning: 'تواصل / اتصال بصري',
englishDefinition: 'The state of touching or connecting with someone.',
exampleSentence: 'Maintain friendly eye contact during the interview.',
),
'handshake': const WordDefinitionModel(
word: 'Handshake',
ipa: '/ˈhænd.ʃeɪk/',
partOfSpeech: 'noun',
arabicMeaning: 'مصافحة بالأيدي',
englishDefinition: 'The act of grasping someone\'s hand as a greeting or agreement.',
exampleSentence: 'A firm handshake reflects respect and professionalism.',
),
'interview': const WordDefinitionModel(
word: 'Interview',
ipa: '/ˈɪn.tə.vjuː/',
partOfSpeech: 'noun / verb',
arabicMeaning: 'مقابلة شخصية / يجري مقابلة',
englishDefinition: 'A formal meeting in which someone is asked questions.',
exampleSentence: 'Preparation is the secret to succeeding in any job interview.',
),
'professional': const WordDefinitionModel(
word: 'Professional',
ipa: '/prəˈfeʃ.ən.əl/',
partOfSpeech: 'adjective',
arabicMeaning: 'مهني / احترافي',
englishDefinition: 'Relating to or belonging to a profession; competent and ethical.',
exampleSentence: 'Dress in professional attire for the presentation.',
),
'attire': const WordDefinitionModel(
word: 'Attire',
ipa: '/əˈtaɪər/',
partOfSpeech: 'noun',
arabicMeaning: 'ملابس / زي رسمي',
englishDefinition: 'Clothes, especially fine or formal ones.',
exampleSentence: 'Appropriate attire depends on the setting and occasion.',
),
// Unit 2: The Digital Mind & Technology
'artificial': const WordDefinitionModel(
word: 'Artificial',
ipa: '/ˌɑː.tɪˈfɪʃ.əl/',
partOfSpeech: 'adjective',
arabicMeaning: 'اصطناعي / غير طبيعي',
englishDefinition: 'Made or produced by human beings rather than occurring naturally.',
exampleSentence: 'Artificial intelligence is reshaping education and medicine.',
),
'intelligence': const WordDefinitionModel(
word: 'Intelligence',
ipa: '/ɪnˈtel.ɪ.dʒəns/',
partOfSpeech: 'noun',
arabicMeaning: 'ذكاء / قدرة عقلية',
englishDefinition: 'The ability to acquire and apply knowledge and skills.',
exampleSentence: 'Emotional intelligence is as vital as academic performance.',
),
'autonomous': const WordDefinitionModel(
word: 'Autonomous',
ipa: '/ɔːˈtɒn.ə.məs/',
partOfSpeech: 'adjective',
arabicMeaning: 'ذاتي القيادة / مستقل',
englishDefinition: 'Acting independently or having the freedom to do so.',
exampleSentence: 'Engineers designed an autonomous drone for desert agriculture.',
),
'algorithm': const WordDefinitionModel(
word: 'Algorithm',
ipa: '/ˈæl.ɡə.rɪ.ðəm/',
partOfSpeech: 'noun',
arabicMeaning: 'خوارزمية حسابية',
englishDefinition: 'A process or set of rules followed in calculations or problem-solving.',
exampleSentence: 'The search algorithm filters billions of educational resources.',
),
'device': const WordDefinitionModel(
word: 'Device',
ipa: '/dɪˈvaɪs/',
partOfSpeech: 'noun',
arabicMeaning: 'جهاز / أداة إلكترونية',
englishDefinition: 'A thing made or adapted for a particular purpose, especially a piece of equipment.',
exampleSentence: 'Students use smart devices to access interactive science labs.',
),
'digital': const WordDefinitionModel(
word: 'Digital',
ipa: '/ˈdɪdʒ.ɪ.təl/',
partOfSpeech: 'adjective',
arabicMeaning: 'رقمي / إلكتروني',
englishDefinition: 'Relating to computer technology and electronic systems.',
exampleSentence: 'The digital transformation in Jordan empowers high school students.',
),
'virtual': const WordDefinitionModel(
word: 'Virtual',
ipa: '/ˈvɜː.tʃu.əl/',
partOfSpeech: 'adjective',
arabicMeaning: 'افتراضي / محاكى رقمياً',
englishDefinition: 'Created by software to appear real without existing physically.',
exampleSentence: 'The virtual laboratory allows safe physics experiments.',
),
'network': const WordDefinitionModel(
word: 'Network',
ipa: '/ˈnet.wɜːk/',
partOfSpeech: 'noun',
arabicMeaning: 'شبكة اتصال',
englishDefinition: 'A group of interconnected people or things.',
exampleSentence: 'A secure network protects student data and exam records.',
),
// Unit 3: Environmental Awareness & Eco-Architecture
'sustainable': const WordDefinitionModel(
word: 'Sustainable',
ipa: '/səˈsteɪ.nə.bəl/',
partOfSpeech: 'adjective',
arabicMeaning: 'مستدام / صديق للبيئة',
englishDefinition: 'Able to be maintained at a certain rate without depleting natural resources.',
exampleSentence: 'Solar energy provides a sustainable power source for schools.',
),
'environment': const WordDefinitionModel(
word: 'Environment',
ipa: '/ɪnˈvaɪ.rən.mənt/',
partOfSpeech: 'noun',
arabicMeaning: 'البيئة الطبيعية والمحيطة',
englishDefinition: 'The surroundings or conditions in which a person, animal, or plant lives.',
exampleSentence: 'Protecting the environment is our collective civic responsibility.',
),
'architect': const WordDefinitionModel(
word: 'Architect',
ipa: '/ˈɑː.kɪ.tekt/',
partOfSpeech: 'noun',
arabicMeaning: 'مهندس معماري',
englishDefinition: 'A person who designs buildings and supervises their construction.',
exampleSentence: 'The architect created eco-friendly structures using local Jordanian limestone.',
),
'renewable': const WordDefinitionModel(
word: 'Renewable',
ipa: '/rɪˈnjuː.ə.bəl/',
partOfSpeech: 'adjective',
arabicMeaning: 'متجدد (للطاقة)',
englishDefinition: 'Capable of being replenished naturally over time.',
exampleSentence: 'Wind and solar power are leading renewable energy sectors.',
),
'conservation': const WordDefinitionModel(
word: 'Conservation',
ipa: '/ˌkɒn.səˈveɪ.ʃən/',
partOfSpeech: 'noun',
arabicMeaning: 'حفظ / ترشيد الاستهلاك',
englishDefinition: 'The prevention of the wasteful use of a resource.',
exampleSentence: 'Water conservation is a top strategic priority in our region.',
),
'efficiency': const WordDefinitionModel(
word: 'Efficiency',
ipa: '/ɪˈfɪʃ.ən.si/',
partOfSpeech: 'noun',
arabicMeaning: 'كفاءة / فاعلية الإنجاز',
englishDefinition: 'The state or quality of being efficient without wasting energy.',
exampleSentence: 'Thermal insulation increases building energy efficiency.',
),
// Grammar & Connectors
'although': const WordDefinitionModel(
word: 'Although',
ipa: '/ɔːlˈðəʊ/',
partOfSpeech: 'conjunction',
arabicMeaning: 'على الرغم من / مع أن',
englishDefinition: 'In spite of the fact that; even though.',
exampleSentence: 'Although appearances matter, character determines true success.',
),
'furthermore': const WordDefinitionModel(
word: 'Furthermore',
ipa: '/ˌfɜː.ðəˈmɔːr/',
partOfSpeech: 'adverb',
arabicMeaning: 'علاوة على ذلك / بالإضافة لذلك',
englishDefinition: 'In addition; moreover (used to introduce further evidence).',
exampleSentence: 'The method is fast; furthermore, it reduces calculation errors.',
),
'therefore': const WordDefinitionModel(
word: 'Therefore',
ipa: '/ˈðeə.fɔːr/',
partOfSpeech: 'adverb',
arabicMeaning: 'لذلك / بناءً عليه',
englishDefinition: 'For that reason; consequently.',
exampleSentence: 'The discriminant is positive; therefore, two solutions exist.',
),
'however': const WordDefinitionModel(
word: 'However',
ipa: '/haʊˈev.ər/',
partOfSpeech: 'adverb',
arabicMeaning: 'ومع ذلك / لكن',
englishDefinition: 'Used to introduce a statement that contrasts with what has just been said.',
exampleSentence: 'We studied hard; however, the exam required deep critical reasoning.',
),
};
}