Skip to content

Commit 9097939

Browse files
Added IsTransitioning bool to check to make sure we're not already performing start/stop recording functions back to back.
1 parent 9f3327e commit 9097939

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Assets/HoloToolkit/Input/Scripts/Microphone/DictationInputManager.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public class DictationInputManager : Singleton<DictationInputManager>, IInputSou
4747

4848
private static DictationRecognizer dictationRecognizer;
4949

50-
private bool hasFailed;
50+
private static bool isTransitioning;
51+
52+
private static bool hasFailed;
5153

5254
#region Unity Methods
5355

@@ -101,9 +103,14 @@ protected override void OnDestroy()
101103
/// <returns></returns>
102104
public static IEnumerator StartRecording(float initialSilenceTimeout = 5f, float autoSilenceTimeout = 20f, int recordingTime = 10)
103105
{
104-
if (IsListening) { yield break; }
106+
if (IsListening || isTransitioning)
107+
{
108+
Debug.LogWarning("Unable to start recording");
109+
yield break;
110+
}
105111

106112
IsListening = true;
113+
isTransitioning = true;
107114

108115
if (PhraseRecognitionSystem.Status == SpeechSystemStatus.Running)
109116
{
@@ -132,19 +139,23 @@ public static IEnumerator StartRecording(float initialSilenceTimeout = 5f, float
132139

133140
// Start recording from the microphone.
134141
dictationAudioClip = Microphone.Start(DeviceName, false, recordingTime, samplingRate);
135-
136-
// Use this string to cache the text currently displayed.
137142
textSoFar = new StringBuilder();
143+
isTransitioning = false;
138144
}
139145

140146
/// <summary>
141147
/// Ends the recording session.
142148
/// </summary>
143149
public static IEnumerator StopRecording()
144150
{
145-
if (!IsListening) { yield break; }
151+
if (!IsListening || isTransitioning)
152+
{
153+
Debug.LogWarning("Unable to stop recording");
154+
yield break;
155+
}
146156

147157
IsListening = false;
158+
isTransitioning = true;
148159

149160
Microphone.End(DeviceName);
150161

@@ -159,6 +170,7 @@ public static IEnumerator StopRecording()
159170
}
160171

161172
PhraseRecognitionSystem.Restart();
173+
isTransitioning = false;
162174
}
163175

164176
#region Dictation Recognizer Callbacks

0 commit comments

Comments
 (0)