Skip to content

Commit 8082b33

Browse files
committed
fix(STT): wait for audio to load when sending keep alive message
1 parent 17e1e56 commit 8082b33

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Examples/ExampleStreaming.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ private IEnumerator CreateService()
7979
yield return null;
8080

8181
_service = new SpeechToTextService(authenticator);
82+
if (!string.IsNullOrEmpty(_serviceUrl))
83+
{
84+
_service.SetServiceUrl(_serviceUrl);
85+
}
8286
_service.StreamMultipart = true;
8387

8488
Active = true;
@@ -192,9 +196,7 @@ private IEnumerator RecordingHandler()
192196

193197
yield return new WaitForSeconds(timeRemaining);
194198
}
195-
196199
}
197-
198200
yield break;
199201
}
200202

Scripts/Services/SpeechToText/V1/SpeechToTextServiceExtension.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public partial class SpeechToTextService : BaseService
4444
private const float WsKeepAliveInterval = 20.0f;
4545
/// <summary>
4646
/// If no listen state is received after start is sent within this time, we will timeout
47-
/// and stop listening.
47+
/// and stop listening.
4848
/// </summary>
4949
private const float ListenTimeout = 10.0f;
5050
/// <summary>
@@ -77,9 +77,9 @@ public partial class SpeechToTextService : BaseService
7777
#endregion
7878

7979
#region Private Data
80-
private OnRecognize _listenCallback = null; // Callback is set by StartListening()
80+
private OnRecognize _listenCallback = null; // Callback is set by StartListening()
8181
private OnRecognizeSpeaker _speakerLabelCallback = null;
82-
private WSConnector _listenSocket = null; // WebSocket object used when StartListening() is invoked
82+
private WSConnector _listenSocket = null; // WebSocket object used when StartListening() is invoked
8383
private bool _listenActive = false;
8484
private bool _audioSent = false;
8585
private bool _isListening = false;
@@ -541,6 +541,8 @@ private IEnumerator KeepAlive()
541541
// Temporary clip to use for KeepAlive
542542
// TODO: Generate small sound clip to send to the service to keep alive.
543543
AudioClip _keepAliveClip = Resources.Load<AudioClip>("highHat");
544+
while (_keepAliveClip.loadState != AudioDataLoadState.Loaded)
545+
yield return null;
544546

545547
#if ENABLE_DEBUGGING
546548
Log.Debug("SpeechToText.KeepAlive()", "Sending keep alive.");

0 commit comments

Comments
 (0)