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:
commit
b363021504
2 changed files with 33 additions and 8 deletions
|
|
@ -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!;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class SpeechToTextRepo {
|
|||
);
|
||||
|
||||
final Response res = await req.post(
|
||||
url: PApiUrls.simpleTranslation,
|
||||
url: PApiUrls.speechToText,
|
||||
body: request.toJson(),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue