How to stream audio in a PositionalAudio with AudioLoader?

Hello,

Is there a way to use a stream of audio (such as an internet radio / a soundfile-loop stream on a server) as the source of a PositionalAudio instance?

Thnx,
J

You can stream an audio if you create a native HTML5 Audio element and then set it via THREE.Audio.setMediaElementSource(). This approach is used in the following official example:

https://threejs.org/examples/webaudio_visualizer

Doing this is recommended for stuff like background music since it’s not necessary to download the whole audio buffer at once via AudioLoader.

Would this approach work for you?

1 Like

This looks good yes!

I will try to see if I can find a streaming audio example and replace the audio-file used here with the stream.

This is probably not the correct forum to ask this but, I am looking for a way to loop and stream an audio-file on a server and pipe it to all clients in real-time (so everybody visiting the website would hear the same playback). Then I would use that as a source for thee.js.

Do you think this is possible? Is there a good node-js forum to ask for this? I asked Quora and Stackoverflow, but didn’t get a straight response, Ideally I would love to find a forum like this one with a lot of activity but for node-js :slight_smile:

if my question is irrelevant, I understand, and it can be ignored :wink:

Thank you for the answer!

If you don’t get a response at stackoverflow, there could be also an issue with your question. So maybe you have to write it differently in order to get more feedback. In general, stackoverflow should be a good space for such topics.

If you can get it work with the pure Web Audio API, we will probably find a solution with three.js, too. I’m not sure this is helpful but AudioContext.createMediaStreamSource() could be interesting for you. MediaStreamAudioSourceNode is not yet supported by three.js. But it could be part of your solution if HTML5 Audio is no option for some reasons.

Thnx! I will look into it.

FYI: With the next release R109, THREE.Audio provides a new method .setMediaStreamSource()for including Web RTC media streams into the Web Audio pipeline. Could be useful to you :wink:

1 Like