diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 2bfceb67..23ff3cfb 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -862,5 +862,9 @@ const Map> localizedValues = { "try-saying": {"en": "Try saying something", "ar": 'حاول قول شيء ما'}, "refClinic": {"en": "Ref Clinic", "ar": "Ref Clinic"}, "acknowledged": {"en": "Acknowledged", "ar": "إقرار"}, + "didntCatch": { + "en": "Didn't catch that. Try Speaking again", + "ar": "لم يتم التقاط ذلك. حاول التحدث مرة أخرى" + }, "showDetail": {"en": "Show Detail", "ar": "أظهر المعلومات"}, }; diff --git a/lib/screens/patients/profile/note/update_note.dart b/lib/screens/patients/profile/note/update_note.dart index e555e613..207e56a6 100644 --- a/lib/screens/patients/profile/note/update_note.dart +++ b/lib/screens/patients/profile/note/update_note.dart @@ -65,7 +65,7 @@ class _UpdateNoteOrderState extends State { event.controller.stream.listen((p) { if (p['startPopUp'] == 'true') { if (this.mounted) { - onVoiceText(); + initSpeechState().then((value) => {onVoiceText()}); } } }); @@ -118,13 +118,13 @@ class _UpdateNoteOrderState extends State { // isTextFieldHasSuffix: true, validationError: - progressNoteController.text.isEmpty && isSubmitted + progressNoteController.text.isEmpty && + isSubmitted ? TranslationBase.of(context).emptyMessage : null, ), - Positioned( - top: 0,//MediaQuery.of(context).size.height * 0, + top: 0, //MediaQuery.of(context).size.height * 0, right: 15, child: IconButton( icon: Icon( @@ -132,7 +132,8 @@ class _UpdateNoteOrderState extends State { color: Colors.black, ), onPressed: () { - onVoiceText(); + initSpeechState() + .then((value) => {onVoiceText()}); }, ), ) @@ -235,7 +236,7 @@ class _UpdateNoteOrderState extends State { if (available) { speech.listen( onResult: resultListener, - // listenMode: ListenMode.confirmation, + listenMode: stt.ListenMode.confirmation, localeId: lang == 'en' ? 'en-US' : 'ar-SA', ); } else { @@ -266,10 +267,18 @@ class _UpdateNoteOrderState extends State { if (result.finalResult == true) { setState(() { SpeechToText.closeAlertDialog(context); + speech.stop(); progressNoteController.text = reconizedWord; }); } else { print(result.finalResult); } } + + Future initSpeechState() async { + bool hasSpeech = await speech.initialize( + onError: errorListener, onStatus: statusListener); + print(hasSpeech); + if (!mounted) return; + } } diff --git a/lib/util/translations_delegate_base.dart b/lib/util/translations_delegate_base.dart index 044f95a5..a991c2aa 100644 --- a/lib/util/translations_delegate_base.dart +++ b/lib/util/translations_delegate_base.dart @@ -568,7 +568,8 @@ class TranslationBase { String get referTo => localizedValues['referTo'][locale.languageCode]; - String get referredFrom => localizedValues['referredFrom'][locale.languageCode]; + String get referredFrom => + localizedValues['referredFrom'][locale.languageCode]; String get refClinic => localizedValues['refClinic'][locale.languageCode]; String get branch => localizedValues['branch'][locale.languageCode]; @@ -1239,7 +1240,9 @@ class TranslationBase { String get replayBefore => localizedValues['replayBefore'][locale.languageCode]; String get trySaying => localizedValues["try-saying"][locale.languageCode]; - String get acknowledged => localizedValues['acknowledged'][locale.languageCode]; + String get acknowledged => + localizedValues['acknowledged'][locale.languageCode]; + String get didntCatch => localizedValues["didntCatch"][locale.languageCode]; } class TranslationBaseDelegate extends LocalizationsDelegate { diff --git a/lib/widgets/shared/speech-text-popup.dart b/lib/widgets/shared/speech-text-popup.dart index ec1fca1c..dad7e2d1 100644 --- a/lib/widgets/shared/speech-text-popup.dart +++ b/lib/widgets/shared/speech-text-popup.dart @@ -2,30 +2,23 @@ import 'dart:async'; import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/provider/robot_provider.dart'; +import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'dart:async'; +import 'package:speech_to_text/speech_to_text.dart' as stt; class SpeechToText { final BuildContext context; static var dialog; + static stt.SpeechToText speech = stt.SpeechToText(); SpeechToText({ @required this.context, }); showAlertDialog(BuildContext context) { - //AlertDialog alert = AlertDialog - // AlertDialog alert = AlertDialog(content: MyStatefulBuilder(dispose: () { - // print('dispose!!!!!!!!!!!!'); - // }) - // isClosed = true; - // streamSubscription.cancel(); - // }, builder: (BuildContext context, StateSetter setState) { - // //print(streamSubscription); - // }), - // ); - // show the dialog showDialog( context: context, @@ -42,6 +35,7 @@ class SpeechToText { static closeAlertDialog(BuildContext context) { Navigator.of(dialog).pop(); + speech.stop(); } } @@ -93,14 +87,16 @@ class _MyStatefulBuilderState extends State { width: SizeConfig.realScreenWidth * 0.8, child: Container( child: Column(children: [ - Expanded( - flex: 1, - child: Center( - child: Image.asset( - 'assets/images/habib-logo.png', - height: 75, - width: 75, - ))), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + IconButton( + icon: Icon(DoctorApp.close), + onPressed: () { + SpeechToText.closeAlertDialog(context); + }) + ], + ), Expanded( flex: 3, child: Center( @@ -126,19 +122,38 @@ class _MyStatefulBuilderState extends State { Expanded( flex: 1, child: Center( - child: AppText(searchText != null && searchText != 'null' - ? searchText - : TranslationBase.of(context).trySaying))), + child: AppText( + searchText == null + ? TranslationBase.of(context).trySaying + : searchText == 'null' + ? TranslationBase.of(context).didntCatch + : searchText, + fontSize: 14, + ))), searchText == 'null' ? Center( - child: RaisedButton( - child: AppText('Retry'), - onPressed: () { + child: InkWell( + child: Container( + decoration: BoxDecoration( + border: Border.all(color: Colors.grey[300])), + padding: EdgeInsets.all(5), + child: AppText( + 'Try Again', + fontSize: 13, + )), + onTap: () { SpeechToText.closeAlertDialog(context); event.setValue({'startPopUp': 'true'}); }, )) - : SizedBox() + : SizedBox(), + Row(mainAxisAlignment: MainAxisAlignment.end, children: [ + Image.asset( + 'assets/images/habib-logo.png', + height: 20, + width: 20, + ) + ]) ]), )));