Skip to content

Commit 767c199

Browse files
DictationInputManager: updated record functions to utilize coroutines.
1 parent 48e36d7 commit 767c199

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System;
5+
using System.Collections;
56
using System.Text;
67
using UnityEngine;
78
using UnityEngine.Windows.Speech;
@@ -150,8 +151,6 @@ protected override void Awake()
150151

151152
private void Update()
152153
{
153-
//Debug.Log(dictationRecognizer.Status);
154-
155154
if (recordingStarted && !Microphone.IsRecording(DeviceName) && dictationRecognizer.Status == SpeechSystemStatus.Running)
156155
{
157156
recordingStarted = false;
@@ -173,12 +172,19 @@ protected override void OnDestroy()
173172
/// <summary>
174173
/// Turns on the dictation recognizer and begins recording audio from the default microphone.
175174
/// </summary>
176-
public static void StartRecording()
175+
public static IEnumerator StartRecording()
177176
{
178-
PhraseRecognitionSystem.Shutdown();
177+
if (PhraseRecognitionSystem.Status == SpeechSystemStatus.Running)
178+
{
179+
PhraseRecognitionSystem.Shutdown();
180+
}
181+
182+
yield return PhraseRecognitionSystem.Status == SpeechSystemStatus.Stopped;
179183

180184
dictationRecognizer.Start();
181185

186+
yield return dictationRecognizer.Status == SpeechSystemStatus.Running;
187+
182188
recordingStarted = true;
183189

184190
// Start recording from the microphone.
@@ -188,14 +194,16 @@ public static void StartRecording()
188194
/// <summary>
189195
/// Ends the recording session.
190196
/// </summary>
191-
public static void StopRecording()
197+
public static IEnumerator StopRecording()
192198
{
199+
Microphone.End(DeviceName);
200+
193201
if (dictationRecognizer.Status == SpeechSystemStatus.Running)
194202
{
195203
dictationRecognizer.Stop();
196204
}
197205

198-
Microphone.End(DeviceName);
206+
yield return dictationRecognizer.Status == SpeechSystemStatus.Stopped;
199207

200208
PhraseRecognitionSystem.Restart();
201209
}

Assets/HoloToolkit/Input/Tests/Scripts/DictationRecordButton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ public void OnInputClicked(InputClickedEventData eventData)
4646
if (isRecording)
4747
{
4848
isRecording = false;
49-
DictationInputManager.StopRecording();
49+
StartCoroutine(DictationInputManager.StopRecording());
5050
speechToTextOutput.color = Color.white;
5151
buttonRenderer.enabled = true;
5252
recordLight.SetActive(false);
5353
}
5454
else
5555
{
5656
isRecording = true;
57-
DictationInputManager.StartRecording();
57+
StartCoroutine(DictationInputManager.StartRecording());
5858
speechToTextOutput.color = Color.green;
5959
recordLight.SetActive(true);
6060
buttonRenderer.enabled = false;

0 commit comments

Comments
 (0)