Skip to content

Commit 535fc0a

Browse files
Merge branch 'mrtk_development' into vNEXT-BaseInputHandlerRaceCondition
2 parents 511a45b + 008a709 commit 535fc0a

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

Assets/MixedRealityToolkit/_Core/Devices/VoiceInput/WindowsDictationInputDeviceManager.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using Microsoft.MixedReality.Toolkit.Core.Interfaces;
54
using Microsoft.MixedReality.Toolkit.Core.Interfaces.Devices;
65
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
76
using Microsoft.MixedReality.Toolkit.Core.Utilities.Async;
@@ -65,6 +64,8 @@ public WindowsDictationInputDeviceManager(string name, uint priority) : base(nam
6564
/// <inheritdoc />
6665
public override void Enable()
6766
{
67+
if (!Application.isPlaying) { return; }
68+
6869
if (InputSystem == null)
6970
{
7071
Debug.LogWarning("Unable to start Windows Dictation Device Manager. An Input System is required for this feature.");
@@ -74,30 +75,21 @@ public override void Enable()
7475
inputSource = InputSystem.RequestNewGenericInputSource("Dictation Recognizer");
7576
dictationResult = string.Empty;
7677

77-
dictationRecognizer = new DictationRecognizer();
78+
if (dictationRecognizer == null)
79+
{
80+
dictationRecognizer = new DictationRecognizer();
81+
}
82+
7883
dictationRecognizer.DictationHypothesis += DictationRecognizer_DictationHypothesis;
7984
dictationRecognizer.DictationResult += DictationRecognizer_DictationResult;
8085
dictationRecognizer.DictationComplete += DictationRecognizer_DictationComplete;
8186
dictationRecognizer.DictationError += DictationRecognizer_DictationError;
8287
}
8388

84-
/// <inheritdoc />
85-
public override void Disable()
86-
{
87-
if (dictationRecognizer != null)
88-
{
89-
dictationRecognizer.DictationHypothesis -= DictationRecognizer_DictationHypothesis;
90-
dictationRecognizer.DictationResult -= DictationRecognizer_DictationResult;
91-
dictationRecognizer.DictationComplete -= DictationRecognizer_DictationComplete;
92-
dictationRecognizer.DictationError -= DictationRecognizer_DictationError;
93-
dictationRecognizer.Dispose();
94-
}
95-
}
96-
9789
/// <inheritdoc />
9890
public override void Update()
9991
{
100-
if (InputSystem == null) { return; }
92+
if (!Application.isPlaying || InputSystem == null) { return; }
10193

10294
if (!isTransitioning && IsListening && !Microphone.IsRecording(deviceName) && dictationRecognizer.Status == SpeechSystemStatus.Running)
10395
{
@@ -112,6 +104,28 @@ public override void Update()
112104
}
113105
}
114106

107+
/// <inheritdoc />
108+
public override async void Disable()
109+
{
110+
if (Application.isPlaying && dictationRecognizer != null)
111+
{
112+
if (!isTransitioning && IsListening) { await StopRecordingAsync(); }
113+
114+
dictationRecognizer.DictationHypothesis -= DictationRecognizer_DictationHypothesis;
115+
dictationRecognizer.DictationResult -= DictationRecognizer_DictationResult;
116+
dictationRecognizer.DictationComplete -= DictationRecognizer_DictationComplete;
117+
dictationRecognizer.DictationError -= DictationRecognizer_DictationError;
118+
}
119+
}
120+
121+
public override void Destroy()
122+
{
123+
if (Application.isPlaying)
124+
{
125+
dictationRecognizer?.Dispose();
126+
}
127+
}
128+
115129
/// <inheritdoc />
116130
public async void StartRecording(GameObject listener, float initialSilenceTimeout = 5, float autoSilenceTimeout = 20, int recordingTime = 10, string micDeviceName = "")
117131
{

0 commit comments

Comments
 (0)