Merge pull request #4939 from pangeachat/4938-calling-direct_translate-endpoint-from-a-bot-audio-message-gives-translation-error-without-making-a-http-request-to-choreo

fix: allow translation of bot audio transcripts
This commit is contained in:
ggurdin 2025-12-23 09:35:00 -05:00 committed by GitHub
commit b363021504
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 8 deletions

View file

@ -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<String, dynamic>.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<PangeaAudioFile> 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!;
}

View file

@ -48,7 +48,7 @@ class SpeechToTextRepo {
);
final Response res = await req.post(
url: PApiUrls.simpleTranslation,
url: PApiUrls.speechToText,
body: request.toJson(),
);