I am trying to use a websocket to send audio message, what type of message should I change the audio stream into so that I can use a socket to send?
If I directly use a websocket.send(audio), I would get an error “DOMException”, should I change it into binary data? and how?
I am totally new to program, so please help!!!
I am trying to use a websocket to send audio message, what type of
Share
The Websocket API and supports sending Blob and ArrayBuffer binary types.
If your browser supports Mozilla’s audio data API then you can read out the data from an audio tag as an ArrayBuffer and send that. However, this API is unlikely to be standardized.
If your browser supports the Web Audio API (proposed by Google) then you can also extract an ArrayBuffer of the data and send that. The Web Audio API will likely see greater adoption. Here is an intro to Web Audio API. This FAQ has an answer that describes how to use the Web Audio API to read from normal audio/video tags.
Updated:
The Aurora.js library mentioned in this blog post looks like it might be helpful in dealing with audio and binary data.