added vocabulary audio reading

This commit is contained in:
Rene Kievits
2025-10-28 06:00:15 +01:00
parent 6dabb9c977
commit a572a6e6fc
3 changed files with 99 additions and 29 deletions

View File

@@ -57,7 +57,8 @@ class _VocabScreenState extends State<VocabScreen> {
}
var items = await repo.loadVocabulary();
if (items.isEmpty) {
if (items.isEmpty ||
items.every((item) => item.pronunciationAudios.isEmpty)) {
setState(() {
_status = 'Fetching deck...';
});
@@ -149,7 +150,6 @@ class _VocabScreenState extends State<VocabScreen> {
_asked += 1;
if (isCorrect) {
_score += 1;
_audioPlayer.play(AssetSource('sfx/confirm.mp3'));
srsItem.srsStage += 1;
} else {
srsItem.srsStage = max(0, srsItem.srsStage - 1);
@@ -183,7 +183,23 @@ class _VocabScreenState extends State<VocabScreen> {
ScaffoldMessenger.of(context).showSnackBar(snack);
}
Future.delayed(const Duration(milliseconds: 900), _nextQuestion);
if (isCorrect) {
await _audioPlayer.play(AssetSource('sfx/confirm.mp3'));
final maleAudios =
current.pronunciationAudios.where((a) => a.gender == 'male');
if (maleAudios.isNotEmpty) {
try {
await _audioPlayer.play(UrlSource(maleAudios.first.url));
} catch (e) {
// Ignore player errors
}
}
await Future.delayed(const Duration(milliseconds: 400));
} else {
await Future.delayed(const Duration(milliseconds: 900));
}
_nextQuestion();
}
@override