From 62f3abc7eed04e5bfaf3e323dd7e03c18f19e24a Mon Sep 17 00:00:00 2001 From: Marlena Klein Date: Mon, 10 Jul 2023 13:19:47 -0700 Subject: [PATCH] Update Dictation Handler --- .../Assets/Scripts/DictationHandler.cs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/UnityProjects/MRTKDevTemplate/Assets/Scripts/DictationHandler.cs b/UnityProjects/MRTKDevTemplate/Assets/Scripts/DictationHandler.cs index 9f274418a7c..1c4e9db04d8 100644 --- a/UnityProjects/MRTKDevTemplate/Assets/Scripts/DictationHandler.cs +++ b/UnityProjects/MRTKDevTemplate/Assets/Scripts/DictationHandler.cs @@ -44,7 +44,8 @@ public class StringUnityEvent : UnityEvent { } [field: SerializeField] public StringUnityEvent OnRecognitionFaulted { get; private set; } - private DictationSubsystem dictationSubsystem; + private IDictationSubsystem dictationSubsystem = null; + private IKeywordRecognitionSubsystem keywordRecognitionSubsystem = null; /// /// Start dictation on a DictationSubsystem. @@ -54,9 +55,16 @@ public void StartRecognition() // Make sure there isn't an ongoing recognition session StopRecognition(); - dictationSubsystem = XRSubsystemHelpers.GetFirstRunningSubsystem(); + dictationSubsystem = XRSubsystemHelpers.DictationSubsystem; if (dictationSubsystem != null) { + + keywordRecognitionSubsystem = XRSubsystemHelpers.KeywordRecognitionSubsystem; + if (keywordRecognitionSubsystem != null) + { + keywordRecognitionSubsystem.Stop(); + } + dictationSubsystem.Recognizing += DictationSubsystem_Recognizing; dictationSubsystem.Recognized += DictationSubsystem_Recognized; dictationSubsystem.RecognitionFinished += DictationSubsystem_RecognitionFinished; @@ -73,11 +81,13 @@ public void StartRecognition() private void DictationSubsystem_RecognitionFaulted(DictationSessionEventArgs obj) { OnRecognitionFaulted.Invoke("Recognition faulted. Reason: " + obj.ReasonString); + HandleDictationShutdown(); } private void DictationSubsystem_RecognitionFinished(DictationSessionEventArgs obj) { OnRecognitionFinished.Invoke("Recognition finished. Reason: " + obj.ReasonString); + HandleDictationShutdown(); } private void DictationSubsystem_Recognized(DictationResultEventArgs obj) @@ -105,5 +115,19 @@ public void StopRecognition() dictationSubsystem = null; } } + + /// + /// Stop dictation on the current DictationSubsystem. + /// + public void HandleDictationShutdown() + { + StopRecognition(); + + if (keywordRecognitionSubsystem != null) + { + keywordRecognitionSubsystem.Start(); + keywordRecognitionSubsystem = null; + } + } } }