Skip to content

Commit c8a066d

Browse files
DictationInputManager better error handling.
1 parent af093bd commit c8a066d

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public static int RecordingTime
124124

125125
private static DictationRecognizer dictationRecognizer;
126126

127+
private bool hasFailed;
128+
127129
#region Unity Methods
128130

129131
protected override void Awake()
@@ -156,7 +158,13 @@ private void Update()
156158
recordingStarted = false;
157159

158160
// If the microphone stops as a result of timing out, make sure to manually stop the dictation recognizer.
159-
StopRecording();
161+
StartCoroutine(StopRecording());
162+
}
163+
164+
if (!hasFailed && dictationRecognizer.Status == SpeechSystemStatus.Failed)
165+
{
166+
hasFailed = true;
167+
InputManager.Instance.RaiseDictationError(Instance, 0, "Dictation recognizer has failed!");
160168
}
161169
}
162170

@@ -179,16 +187,29 @@ public static IEnumerator StartRecording()
179187
PhraseRecognitionSystem.Shutdown();
180188
}
181189

182-
yield return PhraseRecognitionSystem.Status == SpeechSystemStatus.Stopped;
190+
while (PhraseRecognitionSystem.Status == SpeechSystemStatus.Running)
191+
{
192+
yield return null;
193+
}
183194

184195
dictationRecognizer.Start();
185196

186-
yield return dictationRecognizer.Status == SpeechSystemStatus.Running;
197+
while (dictationRecognizer.Status == SpeechSystemStatus.Failed)
198+
{
199+
InputManager.Instance.RaiseDictationError(Instance, 0, "Dictation recognizer failed to start!");
200+
yield break;
201+
}
202+
203+
while (dictationRecognizer.Status == SpeechSystemStatus.Stopped)
204+
{
205+
yield return null;
206+
}
187207

188208
recordingStarted = true;
189209

190210
// Start recording from the microphone.
191211
dictationAudioClip = Microphone.Start(DeviceName, false, RecordingTime, samplingRate);
212+
Debug.LogFormat("Recording Started {0}", dictationRecognizer.Status);
192213
}
193214

194215
/// <summary>
@@ -203,9 +224,14 @@ public static IEnumerator StopRecording()
203224
dictationRecognizer.Stop();
204225
}
205226

206-
yield return dictationRecognizer.Status == SpeechSystemStatus.Stopped;
227+
while (dictationRecognizer.Status == SpeechSystemStatus.Running)
228+
{
229+
yield return null;
230+
}
207231

208232
PhraseRecognitionSystem.Restart();
233+
234+
Debug.LogFormat("Recording Stopped {0}", dictationRecognizer.Status);
209235
}
210236

211237
#region Dictation Recognizer Callbacks

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class DictationRecordButton : MonoBehaviour, IInputClickHandler, IDictati
1313
private float initialSilenceTimeout = 5f;
1414

1515
[SerializeField]
16-
[Range(5f,60f)]
16+
[Range(5f, 60f)]
1717
[Tooltip("The time length in seconds before dictation recognizer session ends due to lack of audio input.")]
1818
private float autoSilenceTimeout = 20f;
1919

2020
[SerializeField]
21-
[Range(1,60)]
21+
[Range(1, 60)]
2222
[Tooltip("Length in seconds for the manager to listen.")]
2323
private int recordingTime = 10;
2424

@@ -41,6 +41,11 @@ private void Awake()
4141
}
4242

4343
public void OnInputClicked(InputClickedEventData eventData)
44+
{
45+
ToggleRecording();
46+
}
47+
48+
private void ToggleRecording()
4449
{
4550
if (isRecording)
4651
{
@@ -77,8 +82,13 @@ public void OnDictationComplete(DictationEventData eventData)
7782

7883
public void OnDictationError(DictationEventData eventData)
7984
{
85+
isRecording = false;
8086
speechToTextOutput.color = Color.red;
87+
buttonRenderer.enabled = true;
88+
recordLight.SetActive(false);
8189
speechToTextOutput.text = eventData.DictationResult;
90+
Debug.LogError(eventData.DictationResult);
91+
StartCoroutine(DictationInputManager.StopRecording());
8292
}
8393
}
8494
}

0 commit comments

Comments
 (0)