Hi! My name is Juan Miguel Rochina.
I'm trying to integrate Voice Agent in Unity (using WebSockets in C#), but I can't establish a connection.
I am able to connect to the WebSockets for Speech to Text, but not for Text to Speech or Voice Agent (even when including the authentication Token and using the WebSocket connection, etc).
Is there any special requirement for the websocket? I know .NET 6.0 is required, but it works for TTS and I don't understand why it's not working for Voice Agent or STT.
Here is a simplified version of the function I use to connect, focusing on the connection and event structure:
private IEnumerator InitAgentWebSocket()
{
if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(agentId))
yield break;
#if UNITY_WEBGL && !UNITY_EDITOR
// WebGL cannot send Authorization headers.
yield break;
#endif
string wsUrl = "wss://agent.deepgram.com/v1/agent/converse";
var headers = new Dictionary<string, string> {
{ "Authorization", $"Token {apiKey}" }
};
ws = new WebSocket(wsUrl, headers);
ws.OnOpen += () =>
{
isConnected = true;
// Send config here
};
ws.OnError += (e) =>
{
isConnected = false;
// Handle error
};
ws.OnClose += (e) =>
{
isConnected = false;
// Handle close
};
var connectTask = ws.Connect();
while (!connectTask.IsCompleted)
yield return null;
if (connectTask.IsFaulted)
{
// Handle failed connection
}
else if (!isConnected)
{
// OnOpen not triggered
}
}
Thank you in advance for your help!