diff --git a/lib/pangea/events/event_wrappers/pangea_message_event.dart b/lib/pangea/events/event_wrappers/pangea_message_event.dart index 95cbf50c1..5c572f369 100644 --- a/lib/pangea/events/event_wrappers/pangea_message_event.dart +++ b/lib/pangea/events/event_wrappers/pangea_message_event.dart @@ -319,14 +319,34 @@ class PangeaMessageEvent { } SpeechToTextResponseModel? getSpeechToTextLocal() { + final rep = representations + .firstWhereOrNull( + (element) => element.content.speechToText != null, + ) + ?.content + .speechToText; + + if (rep != null) { + return rep; + } + final rawBotTranscription = event.content.tryGetMap(ModelKey.botTranscription); if (rawBotTranscription != null) { try { - return SpeechToTextResponseModel.fromJson( + final stt = SpeechToTextResponseModel.fromJson( Map.from(rawBotTranscription), ); + _sendRepresentationEvent( + PangeaRepresentation( + langCode: stt.langCode, + text: stt.transcript.text, + originalSent: false, + originalWritten: false, + speechToText: stt, + ), + ); } catch (err, s) { ErrorHandler.logError( e: err, @@ -340,12 +360,7 @@ class PangeaMessageEvent { } } - return representations - .firstWhereOrNull( - (element) => element.content.speechToText != null, - ) - ?.content - .speechToText; + return null; } Future requestTextToSpeech( @@ -456,6 +471,16 @@ class PangeaMessageEvent { } _representations = null; + _sendRepresentationEvent( + PangeaRepresentation( + langCode: result.result!.langCode, + text: result.result!.transcript.text, + originalSent: false, + originalWritten: false, + speechToText: result.result!, + ), + ); + return result.result!; } diff --git a/lib/pangea/speech_to_text/speech_to_text_repo.dart b/lib/pangea/speech_to_text/speech_to_text_repo.dart index c6802e749..730db58b9 100644 --- a/lib/pangea/speech_to_text/speech_to_text_repo.dart +++ b/lib/pangea/speech_to_text/speech_to_text_repo.dart @@ -48,7 +48,7 @@ class SpeechToTextRepo { ); final Response res = await req.post( - url: PApiUrls.simpleTranslation, + url: PApiUrls.speechToText, body: request.toJson(), );