enforce using bot transcription if exist (#1078)

* enforce bot transcription if exist

* follow snake case model key convention

* update text color in speech to text toolbar

---------

Co-authored-by: ggurdin <ggurdin@gmail.com>
Co-authored-by: ggurdin <46800240+ggurdin@users.noreply.github.com>
pull/1544/head
Wilson 12 months ago committed by GitHub
parent ff0ab7e00b
commit dd0f20e56c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -102,6 +102,7 @@ class ModelKey {
static const String feedbackLang = "feedback_lang";
static const String transcription = "transcription";
static const String botTranscription = 'bot_transcription';
// bot options
static const String languageLevel = "difficulty";

@ -248,6 +248,15 @@ class PangeaMessageEvent {
return null;
}
final rawBotTranscription =
event.content.tryGetMap(ModelKey.botTranscription);
if (rawBotTranscription != null) {
final botTranscription = SpeechToTextModel.fromJson(
Map<String, dynamic>.from(rawBotTranscription),
);
return botTranscription;
}
final SpeechToTextModel? speechToTextLocal = representations
.firstWhereOrNull(
(element) => element.content.speechToText != null,

@ -91,10 +91,7 @@ class STTToken {
Color color(BuildContext context) {
if (confidence == null) {
return Theme.of(context).textTheme.bodyMedium?.color ??
(Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black);
return Theme.of(context).colorScheme.onSurface;
}
if (confidence! > THRESHOLD_FOR_GREEN) {
return AppConfig.success;

@ -77,9 +77,20 @@ class MessageSpeechToTextCardState extends State<MessageSpeechToTextCard> {
final String fullText = transcript.text;
int lastEnd = 0;
if (transcript.sttTokens.isEmpty) {
return TextSpan(
text: fullText,
style: BotStyle.text(
context,
existingStyle: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
),
setColor: false,
),
);
}
for (final token in transcript.sttTokens) {
// debugPrint('Token confidence: ${token.confidence}');
// debugPrint('color: ${token.color(context)}');
if (token.offset > lastEnd) {
// Add any plain text before the token
spans.add(
@ -187,8 +198,13 @@ class MessageSpeechToTextCardState extends State<MessageSpeechToTextCard> {
),
],
),
const InlineTooltip(
instructionsEnum: InstructionsEnum.speechToText,
const Row(
mainAxisSize: MainAxisSize.min,
children: [
InlineTooltip(
instructionsEnum: InstructionsEnum.speechToText,
),
],
),
],
),

Loading…
Cancel
Save