From 38b70baeb23ef8569faffe83faae8325f58f5e25 Mon Sep 17 00:00:00 2001 From: William Jordan-Cooley Date: Sat, 10 Feb 2024 15:35:38 -0500 Subject: [PATCH] turn off try catch around getAudioGlobal so eerror bubbles up --- lib/pangea/models/pangea_message_event.dart | 131 ++++++++++---------- 1 file changed, 63 insertions(+), 68 deletions(-) diff --git a/lib/pangea/models/pangea_message_event.dart b/lib/pangea/models/pangea_message_event.dart index a2ec57633..58df14bf7 100644 --- a/lib/pangea/models/pangea_message_event.dart +++ b/lib/pangea/models/pangea_message_event.dart @@ -86,86 +86,81 @@ class PangeaMessageEvent { //if no audio exists, create it //if audio exists, return it Future getAudioGlobal(String langCode) async { - try { - final String text = representationByLanguage(langCode)?.text ?? body; + final String text = representationByLanguage(langCode)?.text ?? body; - final local = getAudioLocal(langCode, text); + final local = getAudioLocal(langCode, text); - if (local != null) return Future.value(local); + if (local != null) return Future.value(local); - final TextToSpeechRequest params = TextToSpeechRequest( - text: text, - langCode: langCode, - ); + final TextToSpeechRequest params = TextToSpeechRequest( + text: text, + langCode: langCode, + ); - final TextToSpeechResponse response = - await MatrixState.pangeaController.textToSpeech.get( - params, - ); + final TextToSpeechResponse response = + await MatrixState.pangeaController.textToSpeech.get( + params, + ); - if (response.mediaType != 'audio/ogg') { - throw Exception('Unexpected media type: ${response.mediaType}'); - } + if (response.mediaType != 'audio/ogg') { + throw Exception('Unexpected media type: ${response.mediaType}'); + } - final audioBytes = base64.decode(response.audioContent); + final audioBytes = base64.decode(response.audioContent); - // if (!TextToSpeechController.isOggFile(audioBytes)) { - // throw Exception("File is not a valid OGG format"); - // } else { - // debugPrint("File is a valid OGG format"); - // } + // if (!TextToSpeechController.isOggFile(audioBytes)) { + // throw Exception("File is not a valid OGG format"); + // } else { + // debugPrint("File is a valid OGG format"); + // } - // from text, trim whitespace, remove special characters, and limit to 20 characters - // final fileName = - // text.trim().replaceAll(RegExp('[^A-Za-z0-9]'), '').substring(0, 20); - final eventIdParam = _event.eventId; - final fileName = "audio_for_${eventIdParam}_$langCode"; + // from text, trim whitespace, remove special characters, and limit to 20 characters + // final fileName = + // text.trim().replaceAll(RegExp('[^A-Za-z0-9]'), '').substring(0, 20); + final eventIdParam = _event.eventId; + final fileName = "audio_for_${eventIdParam}_$langCode"; - final file = MatrixAudioFile( - bytes: audioBytes, - name: fileName, - mimeType: response.mediaType, - ); + final file = MatrixAudioFile( + bytes: audioBytes, + name: fileName, + mimeType: response.mediaType, + ); - if (file.mimeType != "audio/ogg") { - debugPrint("Unexpected mime type for audio: ${file.mimeType}"); - // throw Exception("Unexpected mime type: ${file.mimeType}"); - } + if (file.mimeType != "audio/ogg") { + debugPrint("Unexpected mime type for audio: ${file.mimeType}"); + // throw Exception("Unexpected mime type: ${file.mimeType}"); + } - // try { - final String? eventId = await room.sendFileEvent( - file, - inReplyTo: _event, - extraContent: { - 'info': { - ...file.info, - 'duration': response.durationMillis, - }, - 'org.matrix.msc3245.voice': {}, - 'org.matrix.msc1767.audio': { - 'duration': response.durationMillis, - 'waveform': response.waveform, - }, - ModelKey.transcription: { - ModelKey.text: text, - ModelKey.langCode: langCode, - }, + // try { + final String? eventId = await room.sendFileEvent( + file, + inReplyTo: _event, + extraContent: { + 'info': { + ...file.info, + 'duration': response.durationMillis, }, - ); - // .timeout( - // Durations.long4, - // onTimeout: () { - // debugPrint("timeout in getAudioGlobal"); - // return null; - // }, - // ); - - debugPrint("eventId in getAudioGlobal $eventId"); - return eventId != null ? room.getEventById(eventId) : null; - } catch (err) { - debugPrint("error in getAudioGlobal"); - return null; - } + 'org.matrix.msc3245.voice': {}, + 'org.matrix.msc1767.audio': { + 'duration': response.durationMillis, + 'waveform': response.waveform, + }, + ModelKey.transcription: { + ModelKey.text: text, + ModelKey.langCode: langCode, + }, + }, + ); + // .timeout( + // Durations.long4, + // onTimeout: () { + // debugPrint("timeout in getAudioGlobal"); + // return null; + // }, + // ); + + debugPrint("eventId in getAudioGlobal $eventId"); + return eventId != null ? room.getEventById(eventId) : null; } Event? getAudioLocal(String langCode, String text) {