#Need help using .Net API. How to close a stream?

1 messages · Page 1 of 1 (latest)

dark totem
#

We're using the .Net API in Unity. However, we can't work out how to safely close a stream. The docs don't show how, and it seems that the state of the client never becomes Closed after calling FinishAsync. Can anyone here help?

gaunt acornBOT
#

Thanks for asking your question. Please be sure to reply with as much detail as possible so we can assist you efficiently. Such as:

  • Provide the request_id if you've a question about a transcription response.
  • The options you used or the api.deepgram.com URL you sent your request to, including parameters.
  • Any code snippets you can include.
  • Any audio you can include, or if you can't share it here please email it to us at [email protected] and provide a link to this thread.
lilac pumice
#

You can either send {"type": "CloseStream"} or an empty byte. I'm not familiar enough with the SDK to know how to send the text or raw data

#

new byte[0] maybe?

elder wedge
elder wedge
#

this should do it:

await _clientWebSocket.SendAsync(new ArraySegment<byte>([]), WebSocketMessageType.Binary, true, cancelToken).ConfigureAwait(false);
dark totem
#

Not sure we're talking about the same API here! The .Net API doesn't expose sockets directly and SendAsync doesnt exist.
No doubt we could change our approach entirely but I'd rather not; we're rather invested in the .Net one now.

elder wedge
#

I never got a reply in the issue. based on your comments here, it seems like you are using v3 of the SDK then, correct?

#

this could also be achieved using the idea behind the initial code above by using the v3 void SendData(byte[] data) function like so:

Byte[] array = new Byte[1];
Array.Clear(array, 0, array.Length);

client.SendData(array);
dark totem
#

Ah sorry, I've not had time to look at the ticket properly. I saw you recommended switching to 4 and thought perhaps we'd do that after our deadline.
We are using FinishAsync. Its very unclear how it's meant to be used but as far as I can tell, after calling it we should wait for the next message with "isFinal" marked, and at that point we can consider the stream finished - but it never actually seems to close, so I'm not sure it ever disposes the deepgram object. The docs say to always wrap in a using rather than disposing manually so we're not sure what we're supposed to do here (esp since the examples on github DO dispose manually)

elder wedge
#

ok. I will need to take a look at why it isnt closing then. that doesnt seem right.

#

let's use that ticket work through that problem

#

you should know that v4 will most likely be released as early as next friday-ish

#

the RC will likely be posted tomorrow