Audio streaming via websocket in WEBGL, is it possible?

Hello, how are you? I hope so!

I’m working on a task that is to check the possibility and use audio streaming via WebSocket in WebGL (chrome browser), I haven’t had success yet, is there any way to do this?

NOTE: I tested WebsocketSharp, but it appears that it is not supported in WebGL. Socket.IO does the streaming, but it also doesn’t seem to be supported in WebGL.

Hi!
There is no built-in way in Unity for Web to stream audio.
It could be do-able if you create a JavaScript plugin and use the browser WebSocket and WebAudio API.

  • You would need a server that transfers the audio in chunks via the WebSocket connection.
  • In the JavaScript plugin you would need to read the chunks and place them in an AudioBuffer (either using AudioContext: decodeAudioData() for compressed audio or AudioBuffer.copyToChannel for raw audio data).
  • Use a AudioBufferSourceNode to playback the received audio data
  • Manually handle the playback timing of the individual chunks to achieve seamless playback