A cross platform Audiobookshelf client for Android and iOS
Dart
Add a button to clear the transcript cache
Barnabasca6c9b7391f9
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex 03697abc..2f6fd717 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -4861,6 +4861,11 @@"lyricsFullCover": "Use the whole cover","lyricsFullCoverHint": "Shows the transcript in place of the artwork while it runs, fitting as many lines as there is room for.","lyricsBatteryInfo": "Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.",+ "lyricsClearCache": "Clear transcript cache",+ "lyricsClearCacheHint": "{size} of saved transcript lines. Cleared books and episodes are transcribed again as you listen.",+ "@lyricsClearCacheHint": { "placeholders": { "size": { "type": "String" } } },+ "lyricsClearCacheConfirm": "Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.",+ "lyricsCacheCleared": "Transcript cache cleared","lyricsIntroBody": "This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.","lyricsBuildingLead": "Getting ahead of the narration... {percent}","@lyricsBuildingLead": { "placeholders": { "percent": { "type": "String" } } },diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dartindex 4ca386a5..a46bf1d7 100644--- a/lib/l10n/app_localizations.dart+++ b/lib/l10n/app_localizations.dart@@ -14841,6 +14841,30 @@ abstract class AppLocalizations {/// **'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.'**String get lyricsBatteryInfo;+ /// No description provided for @lyricsClearCache.+ ///+ /// In en, this message translates to:+ /// **'Clear transcript cache'**+ String get lyricsClearCache;++ /// No description provided for @lyricsClearCacheHint.+ ///+ /// In en, this message translates to:+ /// **'{size} of saved transcript lines. Cleared books and episodes are transcribed again as you listen.'**+ String lyricsClearCacheHint(String size);++ /// No description provided for @lyricsClearCacheConfirm.+ ///+ /// In en, this message translates to:+ /// **'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.'**+ String get lyricsClearCacheConfirm;++ /// No description provided for @lyricsCacheCleared.+ ///+ /// In en, this message translates to:+ /// **'Transcript cache cleared'**+ String get lyricsCacheCleared;+/// No description provided for @lyricsIntroBody.////// In en, this message translates to:diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dartindex 8e900467..8745503d 100644--- a/lib/l10n/app_localizations_de.dart+++ b/lib/l10n/app_localizations_de.dart@@ -8699,6 +8699,21 @@ class AppLocalizationsDe extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_el.dart b/lib/l10n/app_localizations_el.dartindex 74da9581..687753cb 100644--- a/lib/l10n/app_localizations_el.dart+++ b/lib/l10n/app_localizations_el.dart@@ -8587,6 +8587,21 @@ class AppLocalizationsEl extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex 45d55123..182e48c8 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -8587,6 +8587,21 @@ class AppLocalizationsEn extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dartindex 495bafe3..68fba936 100644--- a/lib/l10n/app_localizations_es.dart+++ b/lib/l10n/app_localizations_es.dart@@ -8589,6 +8589,21 @@ class AppLocalizationsEs extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dartindex aba7d9f7..c83ea278 100644--- a/lib/l10n/app_localizations_fr.dart+++ b/lib/l10n/app_localizations_fr.dart@@ -8636,6 +8636,21 @@ class AppLocalizationsFr extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dartindex 7576b6e7..cfb6ac76 100644--- a/lib/l10n/app_localizations_it.dart+++ b/lib/l10n/app_localizations_it.dart@@ -8587,6 +8587,21 @@ class AppLocalizationsIt extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dartindex 901e1d08..fbac2d29 100644--- a/lib/l10n/app_localizations_ja.dart+++ b/lib/l10n/app_localizations_ja.dart@@ -8587,6 +8587,21 @@ class AppLocalizationsJa extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_no.dart b/lib/l10n/app_localizations_no.dartindex e76c092b..a1b0ca27 100644--- a/lib/l10n/app_localizations_no.dart+++ b/lib/l10n/app_localizations_no.dart@@ -8587,6 +8587,21 @@ class AppLocalizationsNo extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dartindex 43d4e39c..be93b883 100644--- a/lib/l10n/app_localizations_pt.dart+++ b/lib/l10n/app_localizations_pt.dart@@ -8587,6 +8587,21 @@ class AppLocalizationsPt extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_ro.dart b/lib/l10n/app_localizations_ro.dartindex ec926306..36440575 100644--- a/lib/l10n/app_localizations_ro.dart+++ b/lib/l10n/app_localizations_ro.dart@@ -8587,6 +8587,21 @@ class AppLocalizationsRo extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dartindex dc302be3..03c57ad9 100644--- a/lib/l10n/app_localizations_ru.dart+++ b/lib/l10n/app_localizations_ru.dart@@ -8592,6 +8592,21 @@ class AppLocalizationsRu extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dartindex 84d6866d..ce23e4b2 100644--- a/lib/l10n/app_localizations_zh.dart+++ b/lib/l10n/app_localizations_zh.dart@@ -8495,6 +8495,21 @@ class AppLocalizationsZh extends AppLocalizations {String get lyricsBatteryInfo =>'Live transcript and read along use extra battery and processing while they run. On phones with slower processors, lines can take longer to appear.';+ @override+ String get lyricsClearCache => 'Clear transcript cache';++ @override+ String lyricsClearCacheHint(String size) {+ return '$size of saved transcript lines. Cleared books and episodes are transcribed again as you listen.';+ }++ @override+ String get lyricsClearCacheConfirm =>+ 'Delete the saved transcripts for every book and episode? They rebuild automatically as you listen.';++ @override+ String get lyricsCacheCleared => 'Transcript cache cleared';+@overrideString get lyricsIntroBody =>'This listens a little ahead of the narration and shows each line as it is spoken, transcribed on your phone - nothing leaves the device. After turning it on, hold off on pressing play for a few seconds while it gets ahead. The transcript appears once its head start is ready, and starting paused gives it the smoothest run. It uses extra battery and processing while it runs.';diff --git a/lib/screens/transcription_settings_screen.dart b/lib/screens/transcription_settings_screen.dartindex abc20526..cc9f276a 100644--- a/lib/screens/transcription_settings_screen.dart+++ b/lib/screens/transcription_settings_screen.dart@@ -4,6 +4,7 @@ import '../l10n/app_localizations.dart';import '../services/player_settings.dart';import '../services/transcription_service.dart';import '../services/lyrics_service.dart';+import '../services/transcript_line_store.dart';import '../widgets/overlay_toast.dart';/// Colors the spoken words can be painted in. Vivid enough to read on the@@ -42,6 +43,7 @@ class _TranscriptionSettingsScreenStatefinal Map<TranscriptionModelSize, bool> _downloaded = {};TranscriptionModelSize? _downloading;double _progress = 0;+ int _transcriptCacheBytes = 0;@overridevoid initState() {@@ -59,9 +61,39 @@ class _TranscriptionSettingsScreenStatefor (final s in TranscriptionModelSize.values) {_downloaded[s] = await TranscriptionService.instance.isModelDownloaded(s);}+ _transcriptCacheBytes = await TranscriptLineStore.instance.cacheBytes();if (mounted) setState(() => _loaded = true);}+ String _fmtBytes(int b) => b >= 1024 * 1024+ ? '${(b / (1024 * 1024)).toStringAsFixed(1)} MB'+ : '${(b / 1024).ceil()} KB';++ Future<void> _clearTranscriptCache() async {+ final l = AppLocalizations.of(context)!;+ final ok = await showDialog<bool>(+ context: context,+ builder: (ctx) => AlertDialog(+ title: Text(l.lyricsClearCache),+ content: Text(l.lyricsClearCacheConfirm),+ actions: [+ TextButton(+ onPressed: () => Navigator.pop(ctx, false),+ child: Text(l.cancel)),+ FilledButton(+ onPressed: () => Navigator.pop(ctx, true),+ child: Text(l.clearCache)),+ ],+ ),+ );+ if (ok != true || !mounted) return;+ await TranscriptLineStore.instance.clearAll();+ if (!mounted) return;+ setState(() => _transcriptCacheBytes = 0);+ showOverlayToast(context, l.lyricsCacheCleared,+ icon: Icons.delete_outline_rounded);+ }+Future<void> _setEnabled(bool v) async {setState(() => _enabled = v);await PlayerSettings.setTranscriptionEnabled(v);@@ -340,6 +372,20 @@ class _TranscriptionSettingsScreenState],),),+ ListTile(+ title: Text(l.lyricsClearCache),+ subtitle: Text(+ l.lyricsClearCacheHint(_fmtBytes(_transcriptCacheBytes)),+ style: tt.bodySmall+ ?.copyWith(color: cs.onSurfaceVariant, height: 1.35)),+ trailing: TextButton.icon(+ icon: const Icon(Icons.delete_sweep_outlined, size: 18),+ label: Text(l.clearCache),+ onPressed: _transcriptCacheBytes > 0+ ? _clearTranscriptCache+ : null,+ ),+ ),],),);diff --git a/lib/services/transcript_line_store.dart b/lib/services/transcript_line_store.dartindex 486dbb9c..8a164858 100644--- a/lib/services/transcript_line_store.dart+++ b/lib/services/transcript_line_store.dart@@ -250,6 +250,37 @@ class TranscriptLineStore {_scheduleFlush();}+ /// Total bytes the on-disk transcript cache occupies.+ Future<int> cacheBytes() async {+ var total = 0;+ try {+ final dir = await _dir();+ for (final f in dir.listSync()) {+ if (f is File) total += f.lengthSync();+ }+ } catch (_) {}+ return total;+ }++ /// Wipe every cached transcript, memory and disk. Emptying [_cache] also+ /// defuses any flush in flight - it re-reads the cache per key and skips+ /// keys that are gone, so a pending write can't resurrect a file.+ Future<void> clearAll() async {+ _cache.clear();+ _dirty.clear();+ try {+ final dir = await _dir();+ for (final f in dir.listSync()) {+ if (f is! File) continue;+ try {+ await f.delete();+ } catch (_) {}+ }+ } catch (e) {+ debugPrint('[Lyrics] store clear failed: $e');+ }+ }+void _scheduleFlush() {if (_flushScheduled) return;_flushScheduled = true;