5
votes

I have a couple of active AudioContext in my game that are being organized by the audio library Howler.js. These AudioContext are playing audio from my game. Is it possible to besides playing the audio also record the bytestream of the currently playing audio? How would this look? I want to send this audio over webrtc to other clients.

Thanks in advance for your help.

1

1 Answers

3
votes

Considering you have access to the Audio Contexts, these references should help you connect them directly to webRTC, through a mediaStream

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

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

See example 3, from the link above:

<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>

Here, the stream is taken from the microphone. You should get it from your audio contexts.