Reputation: 19
I got audio data streaming continuously from a machine (e.g. [-198 -144 -172 ... 469 472 543] ....). They were successfully captured with html and javascript on a browser of a remote PC and I tried to use the following code to play the captured sound data:
data: .... [-198, -144, -172, ... 469, 472, 543] ....
var context = new AudioContext();
function playByteArray( bytes ) {
var buffer = new Int16Array( bytes.length );
buffer.set( new Int16Array(bytes), 0 );
context.decodeAudioData(buffer.buffer, play);
}
function play( audioBuffer ) {
var source = context.createBufferSource();
source.buffer = audioBuffer;
source.connect( context.destination );
source.start(0);
}
playByteArray(data);
I got an error message:
Uncaught (in promise) DOMException: Unable to decode audio data
Upvotes: 1
Views: 456