near final

This commit is contained in:
ImBenji
2024-03-02 18:07:05 +00:00
parent 67e1cd3530
commit 429eb4ad5f
29 changed files with 7870 additions and 1345 deletions

View File

@@ -13,8 +13,15 @@ class AudioCache {
return _audioCache.keys.toList();
}
Uint8List operator [](String key) {
return _audioCache[key]!;
Uint8List? operator [](String key) {
// ignore case
key = key.toLowerCase();
for (var k in _audioCache.keys) {
if (k.toLowerCase() == key) {
return _audioCache[k];
}
}
return null;
}
}
@@ -22,7 +29,21 @@ class AnnouncementCache extends AudioCache {
String _assetLocation = "assets/ibus_recordings.zip";
Future<void> loadAnnouncements(List<String> Announcements) async {
Future<void> loadAnnouncements(List<String> announcements) async {
List<String> _announements = [];
// remove any announcements that are already loaded
for (var announcement in announcements) {
if (!_audioCache.containsKey(announcement.toLowerCase())) {
_announements.add(announcement);
}
}
if (_announements.length == 0) {
return;
}
final bytes = await rootBundle.load(_assetLocation);
final archive = ZipDecoder().decodeBytes(bytes.buffer.asUint8List());
@@ -34,9 +55,9 @@ class AnnouncementCache extends AudioCache {
filename = filename.split("/").last;
}
if (Announcements.contains(filename)) {
_audioCache[filename] = file.content;
print("Loaded announcement: ${filename}");
if (_announements.contains(filename)) {
_audioCache[filename.toLowerCase()] = file.content;
print("Loaded announcement: $filename");
}
}
}
@@ -62,7 +83,7 @@ class AnnouncementCache extends AudioCache {
filename = filename.split("/").last;
}
_audioCache[filename] = file.content;
_audioCache[filename.toLowerCase()] = file.content;
}
print("Done loading all announcements.");