From 326d2b5fbd494cf4aa1a26d5c307a8080230378d Mon Sep 17 00:00:00 2001 From: William Jordan-Cooley Date: Wed, 15 May 2024 10:57:34 -0400 Subject: [PATCH] adding words per minute to speech to text feedback --- assets/l10n/intl_en.arb | 4 + lib/config/app_config.dart | 2 + .../pangea_message_event.dart | 14 +- lib/pangea/models/speech_to_text_models.dart | 23 ++- .../chat/message_speech_to_text_card.dart | 18 ++- needed-translations.txt | 144 ++++++++++++------ 6 files changed, 137 insertions(+), 68 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 41eeb498d..643ee9a98 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -3945,5 +3945,9 @@ "accuracy": "Accuracy", "points": "Points", "noPaymentInfo": "No payment info necessary!", +<<<<<<< Updated upstream "updatePhoneOS": "You may need to update your device's OS version." +======= + "wordsPerMinute": "Words per minute" +>>>>>>> Stashed changes } \ No newline at end of file diff --git a/lib/config/app_config.dart b/lib/config/app_config.dart index 2b3e74f96..a21a2caad 100644 --- a/lib/config/app_config.dart +++ b/lib/config/app_config.dart @@ -29,6 +29,8 @@ abstract class AppConfig { static const Color primaryColorLight = Color(0xFFDBC9FF); static const Color secondaryColor = Color(0xFF41a2bc); static const Color activeToggleColor = Color(0xFF33D057); + static const Color success = Color(0xFF33D057); + static const Color warning = Color.fromARGB(255, 210, 124, 12); // static String _privacyUrl = // 'https://gitlab.com/famedly/fluffychat/-/blob/main/PRIVACY.md'; static String _privacyUrl = "https://www.pangeachat.com/privacy"; diff --git a/lib/pangea/matrix_event_wrappers/pangea_message_event.dart b/lib/pangea/matrix_event_wrappers/pangea_message_event.dart index 3f2f23616..bea286ba8 100644 --- a/lib/pangea/matrix_event_wrappers/pangea_message_event.dart +++ b/lib/pangea/matrix_event_wrappers/pangea_message_event.dart @@ -296,14 +296,14 @@ class PangeaMessageEvent { return null; } - final SpeechToTextModel? speechToTextLocal = representations - .firstWhereOrNull( - (element) => element.content.speechToText != null, - ) - ?.content - .speechToText; + // final SpeechToTextModel? speechToTextLocal = representations + // .firstWhereOrNull( + // (element) => element.content.speechToText != null, + // ) + // ?.content + // .speechToText; - if (speechToTextLocal != null) return speechToTextLocal; + // if (speechToTextLocal != null) return speechToTextLocal; final matrixFile = await _event.downloadAndDecryptAttachment(); // Pangea# diff --git a/lib/pangea/models/speech_to_text_models.dart b/lib/pangea/models/speech_to_text_models.dart index ad5fd96dd..005d2371f 100644 --- a/lib/pangea/models/speech_to_text_models.dart +++ b/lib/pangea/models/speech_to_text_models.dart @@ -1,11 +1,14 @@ import 'dart:convert'; +import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pangea/enum/audio_encoding_enum.dart'; import 'package:fluffychat/pangea/models/pangea_token_model.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:matrix/matrix.dart'; +const int THRESHOLD_FOR_GREEN = 80; + class SpeechToTextAudioConfigModel { final AudioEncodingEnum encoding; final int sampleRateHertz; @@ -93,13 +96,10 @@ class STTToken { ? Colors.white : Colors.black); } - if (confidence! > 80) { - return const Color.fromARGB(255, 0, 152, 0); + if (confidence! > THRESHOLD_FOR_GREEN) { + return AppConfig.success; } - if (confidence! > 50) { - return const Color.fromARGB(255, 184, 142, 43); - } - return Colors.red; + return AppConfig.warning; } factory STTToken.fromJson(Map json) { @@ -148,6 +148,7 @@ class STTToken { class Transcript { final String text; final int confidence; + final double? wordsPerMinute; final List sttTokens; final String langCode; @@ -156,6 +157,7 @@ class Transcript { required this.confidence, required this.sttTokens, required this.langCode, + required this.wordsPerMinute, }); factory Transcript.fromJson(Map json) => Transcript( @@ -167,6 +169,7 @@ class Transcript { .map((e) => STTToken.fromJson(e)) .toList(), langCode: json['lang_code'], + wordsPerMinute: json['words_per_minute'], ); Map toJson() => { @@ -174,7 +177,15 @@ class Transcript { "confidence": confidence, "stt_tokens": sttTokens.map((e) => e.toJson()).toList(), "lang_code": langCode, + "words_per_minute": wordsPerMinute, }; + + Color color(BuildContext context) { + if (confidence > THRESHOLD_FOR_GREEN) { + return AppConfig.success; + } + return AppConfig.warning; + } } class SpeechToTextResult { diff --git a/lib/pangea/widgets/chat/message_speech_to_text_card.dart b/lib/pangea/widgets/chat/message_speech_to_text_card.dart index c516d4447..6fc02ffe1 100644 --- a/lib/pangea/widgets/chat/message_speech_to_text_card.dart +++ b/lib/pangea/widgets/chat/message_speech_to_text_card.dart @@ -133,6 +133,9 @@ class MessageSpeechToTextCardState extends State { getSpeechToText(); } + String? get wordsPerMinuteString => + speechToTextResponse?.transcript.wordsPerMinute?.toString(); + @override Widget build(BuildContext context) { if (_fetchingTranscription) { @@ -158,11 +161,11 @@ class MessageSpeechToTextCardState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - IconNumberWidget( - icon: Icons.abc, - number: (selectedToken == null ? words : 1).toString(), - toolTip: L10n.of(context)!.words, - ), + // IconNumberWidget( + // icon: Icons.abc, + // number: (selectedToken == null ? words : 1).toString(), + // toolTip: L10n.of(context)!.words, + // ), IconNumberWidget( icon: Symbols.target, number: @@ -171,8 +174,9 @@ class MessageSpeechToTextCardState extends State { ), IconNumberWidget( icon: Icons.speed, - number: (selectedToken?.confidence ?? total).toString(), - toolTip: L10n.of(context)!.points, + number: + wordsPerMinuteString != null ? "$wordsPerMinuteString" : "??", + toolTip: L10n.of(context)!.wordsPerMinute, ), ], ), diff --git a/needed-translations.txt b/needed-translations.txt index c93f52d05..74f684f74 100644 --- a/needed-translations.txt +++ b/needed-translations.txt @@ -820,7 +820,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "be": [ @@ -2239,7 +2240,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "bn": [ @@ -3120,7 +3122,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "bo": [ @@ -4001,7 +4004,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "ca": [ @@ -4882,7 +4886,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "cs": [ @@ -5763,7 +5768,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "de": [ @@ -6591,7 +6597,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "el": [ @@ -7472,7 +7479,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "eo": [ @@ -8353,7 +8361,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "es": [ @@ -8382,7 +8391,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "et": [ @@ -9206,7 +9216,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "eu": [ @@ -10030,7 +10041,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "fa": [ @@ -10911,7 +10923,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "fi": [ @@ -11792,7 +11805,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "fr": [ @@ -12673,7 +12687,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "ga": [ @@ -13554,7 +13569,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "gl": [ @@ -14378,7 +14394,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "he": [ @@ -15259,7 +15276,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "hi": [ @@ -16140,7 +16158,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "hr": [ @@ -17008,7 +17027,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "hu": [ @@ -17889,7 +17909,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "ia": [ @@ -19294,7 +19315,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "id": [ @@ -20175,7 +20197,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "ie": [ @@ -21056,7 +21079,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "it": [ @@ -21922,7 +21946,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "ja": [ @@ -22803,7 +22828,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "ko": [ @@ -23684,7 +23710,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "lt": [ @@ -24565,7 +24592,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "lv": [ @@ -25446,7 +25474,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "nb": [ @@ -26327,7 +26356,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "nl": [ @@ -27208,7 +27238,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "pl": [ @@ -28089,7 +28120,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "pt": [ @@ -28970,7 +29002,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "pt_BR": [ @@ -29820,7 +29853,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "pt_PT": [ @@ -30701,7 +30735,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "ro": [ @@ -31582,7 +31617,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "ru": [ @@ -32406,7 +32442,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "sk": [ @@ -33287,7 +33324,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "sl": [ @@ -34168,7 +34206,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "sr": [ @@ -35049,7 +35088,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "sv": [ @@ -35895,7 +35935,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "ta": [ @@ -36776,7 +36817,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "th": [ @@ -37657,7 +37699,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "tr": [ @@ -38523,7 +38566,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "uk": [ @@ -39347,7 +39391,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "vi": [ @@ -40228,7 +40273,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "zh": [ @@ -41052,7 +41098,8 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ], "zh_Hant": [ @@ -41933,6 +41980,7 @@ "score", "accuracy", "points", - "noPaymentInfo" + "noPaymentInfo", + "wordsPerMinute" ] }