From 907ad15f797e4784fc74ad7ee73426941970b3c5 Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Wed, 26 Feb 2025 13:31:22 -0500 Subject: [PATCH] chore: when choices array goes off screen, stop playing TTS (#1945) --- .../choreographer/controllers/choreographer.dart | 1 + lib/pangea/choreographer/widgets/igc/span_card.dart | 11 ++++++++++- .../widgets/translation_finished_flow.dart | 2 +- .../practice_activity/practice_activity_card.dart | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index 693cc5584..cb3bca424 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -338,6 +338,7 @@ class Choreographer { _textController.selection = TextSelection.collapsed(offset: _textController.text.length); giveInputFocus(); + tts.stop(); } Future onReplacementSelect({ diff --git a/lib/pangea/choreographer/widgets/igc/span_card.dart b/lib/pangea/choreographer/widgets/igc/span_card.dart index e49d726bc..cf4b7388c 100644 --- a/lib/pangea/choreographer/widgets/igc/span_card.dart +++ b/lib/pangea/choreographer/widgets/igc/span_card.dart @@ -16,6 +16,7 @@ import 'package:fluffychat/pangea/choreographer/utils/match_copy.dart'; import 'package:fluffychat/pangea/choreographer/widgets/igc/card_error_widget.dart'; import 'package:fluffychat/pangea/common/utils/error_handler.dart'; import 'package:fluffychat/pangea/events/models/pangea_token_model.dart'; +import 'package:fluffychat/pangea/toolbar/controllers/tts_controller.dart'; import '../../../../widgets/matrix.dart'; import '../../../bot/widgets/bot_face_svg.dart'; import '../../../common/controllers/pangea_controller.dart'; @@ -63,6 +64,14 @@ class SpanCardState extends State { fetchSelected(); } + @override + void dispose() { + tts.stop(); + super.dispose(); + } + + TtsController get tts => widget.scm.choreographer.tts; + //get selected choice SpanChoice? get selectedChoice { if (selectedChoiceIndex == null) return null; @@ -308,7 +317,7 @@ class WordMatchContent extends StatelessWidget { uniqueKeyForLayerLink: (int index) => "wordMatch$index", selectedChoiceIndex: controller.selectedChoiceIndex, - tts: controller.widget.scm.choreographer.tts, + tts: controller.tts, ), const SizedBox(height: 12), PromptAndFeedback(controller: controller), diff --git a/lib/pangea/choreographer/widgets/translation_finished_flow.dart b/lib/pangea/choreographer/widgets/translation_finished_flow.dart index e5561337c..e9e322854 100644 --- a/lib/pangea/choreographer/widgets/translation_finished_flow.dart +++ b/lib/pangea/choreographer/widgets/translation_finished_flow.dart @@ -89,7 +89,7 @@ class AlternativeTranslations extends StatelessWidget { }, uniqueKeyForLayerLink: (int index) => "altTranslation$index", selectedChoiceIndex: null, - tts: controller.choreographer.tts, + tts: null, ); } } diff --git a/lib/pangea/toolbar/widgets/practice_activity/practice_activity_card.dart b/lib/pangea/toolbar/widgets/practice_activity/practice_activity_card.dart index 68ca7a616..77d96ced1 100644 --- a/lib/pangea/toolbar/widgets/practice_activity/practice_activity_card.dart +++ b/lib/pangea/toolbar/widgets/practice_activity/practice_activity_card.dart @@ -275,6 +275,7 @@ class PracticeActivityCardState extends State { // wait for savor the joy before popping from the activity queue // to keep the completed activity on screen for a moment widget.overlayController.onActivityFinish(currentActivity!.activityType); + widget.overlayController.widget.chatController.choreographer.tts.stop(); } catch (e, s) { _onError(); debugger(when: kDebugMode);