【问题标题】:How can I use javascript to play audio data streaming from a machine on browser of a remote PC?如何使用 javascript 在远程 PC 的浏览器上播放来自机器的音频数据流?
【发布时间】: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


    【解决方案1】:

    缓冲区必须是Float32Array,并且不能Int16Array

    【讨论】:

      猜你喜欢
      • 2013-11-21
      • 2017-07-12
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多