Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dictation Focus #1690

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ private void ToggleRecording()
else
{
isRecording = true;
StartCoroutine(DictationInputManager.StartRecording(initialSilenceTimeout, autoSilenceTimeout, recordingTime));
StartCoroutine(DictationInputManager.StartRecording(
gameObject,
initialSilenceTimeout,
autoSilenceTimeout,
recordingTime));
speechToTextOutput.color = Color.green;
recordLight.SetActive(true);
buttonRenderer.enabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class DictationInputManager : Singleton<DictationInputManager>, IInputSou

private static bool isTransitioning;
private static bool hasFailed;
private static bool hasListener;
#endif

#region Unity Methods
Expand Down Expand Up @@ -103,11 +104,12 @@ protected override void OnDestroy()
/// <summary>
/// Turns on the dictation recognizer and begins recording audio from the default microphone.
/// </summary>
/// <param name="listener">GameObject listening for the dictation input.</param>
/// <param name="initialSilenceTimeout">The time length in seconds before dictation recognizer session ends due to lack of audio input in case there was no audio heard in the current session.</param>
/// <param name="autoSilenceTimeout">The time length in seconds before dictation recognizer session ends due to lack of audio input.</param>
/// <param name="recordingTime">Length in seconds for the manager to listen.</param>
/// <returns></returns>
public static IEnumerator StartRecording(float initialSilenceTimeout = 5f, float autoSilenceTimeout = 20f, int recordingTime = 10)
public static IEnumerator StartRecording(GameObject listener = null, float initialSilenceTimeout = 5f, float autoSilenceTimeout = 20f, int recordingTime = 10)
{
#if UNITY_WSA || UNITY_STANDALONE_WIN
if (IsListening || isTransitioning)
Expand All @@ -119,6 +121,12 @@ public static IEnumerator StartRecording(float initialSilenceTimeout = 5f, float
IsListening = true;
isTransitioning = true;

if (listener != null)
{
hasListener = true;
InputManager.Instance.PushModalInputHandler(listener);
}

if (PhraseRecognitionSystem.Status == SpeechSystemStatus.Running)
{
PhraseRecognitionSystem.Shutdown();
Expand Down Expand Up @@ -149,6 +157,7 @@ public static IEnumerator StartRecording(float initialSilenceTimeout = 5f, float
textSoFar = new StringBuilder();
isTransitioning = false;
#else
Debug.LogWarning("Unable to start recording! Dictation is unsupported for this platform.");
return null;
#endif
}
Expand All @@ -168,6 +177,12 @@ public static IEnumerator StopRecording()
IsListening = false;
isTransitioning = true;

if (hasListener)
{
InputManager.Instance.PopModalInputHandler();
hasListener = false;
}

Microphone.End(DeviceName);

if (dictationRecognizer.Status == SpeechSystemStatus.Running)
Expand Down
2 changes: 1 addition & 1 deletion Assets/HoloToolkit/UX/Scripts/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ private void ActivateSpecificKeyboard(LayoutType keyboardType)
private void BeginDictation()
{
ResetClosingTime();
StartCoroutine(DictationInputManager.StartRecording());
StartCoroutine(DictationInputManager.StartRecording(gameObject));
SetMicrophoneRecording();
}

Expand Down