resonance-audio / resonance-audio-web-sdk

Resonance Audio SDK for Web
https://resonance-audio.github.io/resonance-audio/
Apache License 2.0
200 stars 56 forks source link

Spatial audio does not work with audio streams #7

Closed benank closed 6 years ago

benank commented 6 years ago

I'm trying to use this as part of a voice chat feature in a game that implements CEF. However, it doesn't seem to apply any 3D effects to the voice stream. I tested a normal sound (ogg) and it worked as expected, with the audio becoming quieter as the player moved away from the other and the direction in the speakers changing as well. With an audio stream from a microphone, using window.URL.createObjectURL(stream) to get the source, it only plays the sound as if it were a normal sound - it doesn't matter where my player is in the game; the sound is the same volume and direction.

I'm curious as to if this even works with spatial audio. I tried using a different library (HowlerJS), but I read that audio streams are not supported with their spatial audio. Is this the same case here?

drewbitllama commented 6 years ago

Hi Benank,

I have a feeling you need to explicitly have WebAudio handle the stream via a createMediaStreamSource() function call and then pipe it's output to our renderer. See https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaStreamSource for more details.

Please feel free to post some example code as well so I can help you better. :)

Cheers, Drew

benank commented 6 years ago

Hi, thank you for the response. Using createMediaStreamSource was exactly what I needed, along with muting the original audioElement. Thank you for your help!

drewbitllama commented 6 years ago

Excellent! So glad I could help. Let us know about what cool things you end up making with our SDK. :)

Cheers, Drew On Fri, Jan 5, 2018 at 5:28 PM Ben A. notifications@github.com wrote:

Closed #7 https://github.com/resonance-audio/resonance-audio-web-sdk/issues/7.

— You are receiving this because you were assigned.

Reply to this email directly, view it on GitHub https://github.com/resonance-audio/resonance-audio-web-sdk/issues/7#event-1412235441, or mute the thread https://github.com/notifications/unsubscribe-auth/AGDsNoVyeqqPXOM6mZgn4yYXJdy9fL0Iks5tHswygaJpZM4RT4-7 .

ryancwalsh commented 3 years ago

@benank and @drewbitllama I'd be so appreciative if you could clarify what you did here because I have the same question and shared my code in this other issue here.

Like you said, regular wav files worked well, but I couldn't get webcam streams to work (even with audioContext.createMediaStreamSource(video.srcObject); ).

I'm wondering what you did differently to get it to work.

I realize it's 3.3 years later, but any hints you can think of would be much appreciated! Thanks!

benank commented 3 years ago

@ryancwalsh My use case was for a voice chat application, and the code is still available here. I honestly can't give you much more than the code because I don't remember anything else about it at this point. Hope this helps!

ryancwalsh commented 3 years ago

@benank Wow, I didn't really expect that you'd respond at all, and the fact that you responded so quickly is blowing me away, especially given that you're sharing code.

I really appreciate it. 😃

As it turns out, at the same time as you were typing this, I was able to figure it out based on your earlier hint: https://github.com/resonance-audio/resonance-audio-web-sdk/issues/34#issuecomment-819902221

Thank you so much! This is really cool.