91Act / curl-unity

This is a C# wrapper for Unity to use libcurl with http/2 and openssl enabled.
98 stars 20 forks source link

Send continuous stream to endpoint #8

Open lavarith opened 4 years ago

lavarith commented 4 years ago

First, thank you for being so responsive.

Somewhat related to a previous issue I submitted, I'm now trying to send a continuous audio stream--recorded from the microphone--to the Alexa Voice Service in 10ms chunks.

However, there doesn't seem to be a way to send a stream of bytes (or floats) of indeterminate size. The Curl Interface seems to have a form_add, READData, and ReadFunction options that seem relevant, but they're not implemented. I may be looking in the wrong place, though.

Any idea how I might add a binary audio stream to a multipart message and keep adding to it until a separate function tells me to stop (I'm receiving directives on a separate channel and can end the audio stream if there's a method to close the stream)?

Reference: https://developer.amazon.com/docs/alexa-voice-service/speechrecognizer.html#recognize

Jayatubi commented 4 years ago

As the previous issue you post the curl may not be the best tool for endless streams, no matter incoming or outgoing. If you are looking for a way for duplex communication without a determined end of stream you'd better checkout the websocket protocol or just an oridinary TCP connection.

If you insist to do this with curl you may check the CURLOPT_READFUNCTION. By setting this option you could provide a function to control outgoing data by yourself.

lavarith commented 4 years ago

I got the previous issue (incoming stream) working based on your recommendations.

I'm afraid that setting the readdata function and managing the memory pointers is outside my wheelhouse. I'll keep hacking at it though. I have some evidence from a separate product that it's definitely possible to use curl.

The data has to be sent over http2 and I have everything else working. I don't want to open an entirely new can of worms with web sockets

Jayatubi commented 4 years ago

The read data function should be safe if you just handle your data carefully and that's the only way I could tell for an endless data transferring so far. Another thing that I'm not sure is that if you could get any incoming data before you finish the uploading then you could achieve the goal for duplex data streaming. It's worth for you to try and if you made it a PR is welcome.