【发布时间】:2020-10-19 07:11:29
【问题描述】:
我从一台机器连续获得音频数据流(例如 [-198 -144 -172 ... 469 472 543] ....)。在远程 PC 的浏览器上使用 html 和 javascript 成功捕获了它们,我尝试使用以下代码播放捕获的声音数据:
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);
我收到一条错误消息:
Uncaught (in promise) DOMException: Unable to decode audio data
【问题讨论】:
标签: javascript audio browser stream playback