From 8a24b0342bbb6c49c840b35d2207bb5845e7d403 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Mon, 21 Oct 2024 16:33:30 -0400 Subject: [PATCH] added fix for different map keys in voices across platforms --- lib/pangea/extensions/pangea_event_extension.dart | 14 ++++++++++---- lib/pangea/widgets/chat/message_audio_card.dart | 6 ------ lib/pangea/widgets/chat/tts_controller.dart | 13 +++++-------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/pangea/extensions/pangea_event_extension.dart b/lib/pangea/extensions/pangea_event_extension.dart index 23a0c1374..1ca280a98 100644 --- a/lib/pangea/extensions/pangea_event_extension.dart +++ b/lib/pangea/extensions/pangea_event_extension.dart @@ -45,18 +45,24 @@ extension PangeaEvent on Event { Future getPangeaAudioFile() async { if (type != EventTypes.Message || messageType != MessageTypes.Audio) { ErrorHandler.logError( - e: "Event $eventId is not an audio message", + e: "Event is not an audio message", + data: { + "event": toJson(), + }, ); return null; } - // @ggurdin what are cases where these would be null? - // if it would be unexpected, we should log an error with details to investigate final transcription = content.tryGetMap(ModelKey.transcription); final audioContent = content.tryGetMap('org.matrix.msc1767.audio'); - if (transcription == null || audioContent == null) return null; + if (transcription == null || audioContent == null) { + ErrorHandler.logError( + e: "Called getPangeaAudioFile on an audio message without transcription or audio content", + ); + return null; + } final matrixFile = await downloadAndDecryptAttachment(); final duration = audioContent.tryGet('duration'); diff --git a/lib/pangea/widgets/chat/message_audio_card.dart b/lib/pangea/widgets/chat/message_audio_card.dart index b56e7103e..7bb557d00 100644 --- a/lib/pangea/widgets/chat/message_audio_card.dart +++ b/lib/pangea/widgets/chat/message_audio_card.dart @@ -56,12 +56,6 @@ class MessageAudioCardState extends State { @override void didUpdateWidget(covariant oldWidget) { - // @ggurdin did you find a case of needing to reinitialize TTS because of a language change? - // if (widget.messageEvent.messageDisplayLangCode != - // oldWidget.messageEvent.messageDisplayLangCode) { - // initializeTTS(); - // } - if (oldWidget.selection != widget.selection) { debugPrint('selection changed'); setSectionStartAndEndFromSelection(); diff --git a/lib/pangea/widgets/chat/tts_controller.dart b/lib/pangea/widgets/chat/tts_controller.dart index e8edd65c3..ea28a66dd 100644 --- a/lib/pangea/widgets/chat/tts_controller.dart +++ b/lib/pangea/widgets/chat/tts_controller.dart @@ -35,15 +35,13 @@ class TtsController { await tts.awaitSpeakCompletion(true); final voices = await tts.getVoices; + debugPrint("voices: $voices"); availableLangCodes = (voices as List) .map((v) { - // debugPrint('v: $v'); - - //@ggurdin i changed this from name to locale - //in my testing, that's where the language code is stored - // maybe it's different for different devices? was it different in your android testing? - // return v['name']?.split("-").first; - return v['locale']?.split("-").first; + // on iOS / web, the codes are in 'locale', but on Android, they are in 'name' + final nameCode = v['name']?.split("-").first; + final localeCode = v['locale']?.split("-").first; + return nameCode.length == 2 ? nameCode : localeCode; }) .toSet() .cast() @@ -67,7 +65,6 @@ class TtsController { bool get isLanguageFullySupported => availableLangCodes.contains(targetLanguage); - // @ggurdin Widget get missingVoiceButton => targetLanguage != null && (kIsWeb || isLanguageFullySupported || !PlatformInfos.isAndroid) ? const SizedBox.shrink()