Web Audio API 获取当前播放音频的字节流

Eri*_*oek 5 javascript audio-recording html5-audio web-audio-api

我的游戏中有几个活动的 AudioContext,它们由音频库 Howler.js 组织。这些 AudioContext 正在播放我游戏中的音频。除了播放音频之外,是否还可以记录当前播放音频的字节流?这看起来如何?我想通过 webrtc 将此音频发送给其他客户端。

在此先感谢您的帮助。

Ali*_*upu 4

考虑到您可以访问音频上下文,这些引用应该可以帮助您通过 mediaStream 将它们直接连接到 webRTC

https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioDestinationNode

https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/webrtc-integration.html

请参阅上面链接中的示例 3:

<script>
    navigator.getUserMedia('audio', gotAudio);
    function gotAudio(stream) {
        var microphone = context.createMediaStreamSource(stream);
        var filter = context.createBiquadFilter();
        var peer = context.createMediaStreamDestination();
        microphone.connect(filter);
        filter.connect(peer);
        peerConnection.addStream(peer.stream);
    }
</script>
Run Code Online (Sandbox Code Playgroud)

此处,流是从麦克风获取的。您应该从音频上下文中获取它。