Skip to content

Commit d54f099

Browse files
committed
changed OnListen to return a bool, true if audio was sent/enqueued
1 parent 46289a8 commit d54f099

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Scripts/Services/SpeechToText/v1/SpeechToText.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,11 @@ public bool StartListening(OnRecognize callback, OnRecognizeSpeaker speakerLabel
457457
/// microphone input is sent to this function.
458458
/// </summary>
459459
/// <param name="clip">A AudioData object containing the AudioClip and max level found in the clip.</param>
460-
public void OnListen(AudioData clip)
460+
/// <returns>True if audio was sent or enqueued, false if audio was discarded.</returns>
461+
public bool OnListen(AudioData clip)
461462
{
463+
bool audioSentOrEnqueued = false;
464+
462465
if (_isListening)
463466
{
464467
if (_recordingHZ < 0)
@@ -483,12 +486,14 @@ public void OnListen(AudioData clip)
483486
{
484487
_listenSocket.Send(new WSConnector.BinaryMessage(AudioClipUtil.GetL16(clip.Clip)));
485488
_audioSent = true;
489+
audioSentOrEnqueued = true;
486490
}
487491
else
488492
{
489493
// we have not received the "listening" state yet from the server, so just queue
490494
// the audio clips until that happens.
491495
_listenRecordings.Enqueue(clip);
496+
audioSentOrEnqueued = true;
492497

493498
// check the length of this queue and do something if it gets too full.
494499
if (_listenRecordings.Count > MaxQueuedRecordings)
@@ -518,6 +523,8 @@ public void OnListen(AudioData clip)
518523
OnError("Failed to enter listening state.");
519524
}
520525
}
526+
527+
return audioSentOrEnqueued;
521528
}
522529

523530
/// <summary>

0 commit comments

Comments
 (0)