#Need help using .Net API. How to close a stream?
1 messages · Page 1 of 1 (latest)
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_idif 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.
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?
for reference, this issue was also created in the repo
https://github.com/deepgram/deepgram-dotnet-sdk/issues/257
this should do it:
await _clientWebSocket.SendAsync(new ArraySegment<byte>([]), WebSocketMessageType.Binary, true, cancelToken).ConfigureAwait(false);
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.
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?
if you are, they have a function that exactly calls that above in the v3 SDK called FinishAsync(). Please see:
https://github.com/deepgram/deepgram-dotnet-sdk/blob/3.4.2/Deepgram/Clients/LiveTranscriptionClient.cs#L167C9-L167C40
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);
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)