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 2 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 @@ -103,11 +103,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, float initialSilenceTimeout = 5f, float autoSilenceTimeout = 20f, int recordingTime = 10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I'm using a global listener and I don't want/need to pass a specific GameObject in? Can we give listener a default value (probably null), like we've done with the others? That'd also prevent this from being a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question.

I don't think it's a good idea to make the object you're using to start the dictation a global listener.
But if you did, you'd have a script on the object that listens for the click handler:

OnInputClicked(EventData eventData)
{
    StartCoroutine(DictationManager.Instance.StartRecording(gameObject);
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I didn't mean the starting object being a global listener, but the one being sent the dictation results. If I want a button to start recording, but I want the results to be sent to a global listener (or two), my button would be forced to pass in some GameObject anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll make the listener optional.

{
#if UNITY_WSA || UNITY_STANDALONE_WIN
if (IsListening || isTransitioning)
Expand All @@ -119,6 +120,8 @@ public static IEnumerator StartRecording(float initialSilenceTimeout = 5f, float
IsListening = true;
isTransitioning = true;

InputManager.Instance.PushModalInputHandler(listener);

if (PhraseRecognitionSystem.Status == SpeechSystemStatus.Running)
{
PhraseRecognitionSystem.Shutdown();
Expand Down Expand Up @@ -149,6 +152,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 +172,8 @@ public static IEnumerator StopRecording()
IsListening = false;
isTransitioning = true;

InputManager.Instance.PopModalInputHandler();

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