Skip to content

Changed OnListen to return a bool, true if audio was sent/enqueued #299

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

Merged
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
9 changes: 8 additions & 1 deletion Scripts/Services/SpeechToText/v1/SpeechToText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,11 @@ public bool StartListening(OnRecognize callback, OnRecognizeSpeaker speakerLabel
/// microphone input is sent to this function.
/// </summary>
/// <param name="clip">A AudioData object containing the AudioClip and max level found in the clip.</param>
public void OnListen(AudioData clip)
/// <returns>True if audio was sent or enqueued, false if audio was discarded.</returns>
public bool OnListen(AudioData clip)
{
bool audioSentOrEnqueued = false;

if (_isListening)
{
if (_recordingHZ < 0)
Expand All @@ -483,12 +486,14 @@ public void OnListen(AudioData clip)
{
_listenSocket.Send(new WSConnector.BinaryMessage(AudioClipUtil.GetL16(clip.Clip)));
_audioSent = true;
audioSentOrEnqueued = true;
}
else
{
// we have not received the "listening" state yet from the server, so just queue
// the audio clips until that happens.
_listenRecordings.Enqueue(clip);
audioSentOrEnqueued = true;

// check the length of this queue and do something if it gets too full.
if (_listenRecordings.Count > MaxQueuedRecordings)
Expand Down Expand Up @@ -518,6 +523,8 @@ public void OnListen(AudioData clip)
OnError("Failed to enter listening state.");
}
}

return audioSentOrEnqueued;
}

/// <summary>
Expand Down