# How to play sound from WebRTC peer connection?

**URL:** <https://qa.fmod.com/t/how-to-play-sound-from-webrtc-peer-connection/19645>\
**Category:** Unity\
**Created:** [December 15, 2022, 2:29pm UTC](https://qa.fmod.com/t/how-to-play-sound-from-webrtc-peer-connection/19645 "2022-12-15T14:29:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdrienCareprod](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@AdrienCareprod](https://qa.fmod.com/u/AdrienCareprod)\
**Post date:** [December 15, 2022, 2:29pm UTC](https://qa.fmod.com/t/how-to-play-sound-from-webrtc-peer-connection/19645/1 "2022-12-15T14:29:46Z")

</div>

We use WebRTC package in my unity project to add voicechat. We get my audio as AudioStreamTrack from the peer connection. For now we used `audioSource.SetTrack(myAudioStreamTrack); //an extension method which is available when using Unity.WebRTC namespace.`

But if we want to use FMOD for Unity, can we play AudioStreamTrack sound? And can we get and send the input from the microphone?

Thanks for your help

---

<div class="post-metadata">

**Author:** ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)\
**Post date:** [December 19, 2022, 5:24am UTC](https://qa.fmod.com/t/how-to-play-sound-from-webrtc-peer-connection/19645/2 "2022-12-19T05:24:21Z")

</div>

Hi,

FMOD doesn’t support WebRTC, but if you can retrieve the audio buffer of an incoming audio stream track and access the raw audio data, you’ll be able to stream it into an FMOD Sound for playback. You can either do this in an [`FMOD_SOUND_PCMREAD_CALLBACK`](https://fmod.com/docs/2.02/api/core-api-sound.html#fmod_sound_pcmread_callback), or by getting a pointer to the sound’s buffer with [`Sound.lock`](https://fmod.com/docs/2.02/api/core-api-sound.html#fmod_sound_pcmread_callback), and copying your raw audio data to it with [`Sound.unlock`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-sound.html#sound_unlock). Note that the second method requires you to manually schedule copying audio data yourself, as you won’t be told when to give it data.

I’d recommend taking a look at the `user_created_sound.cpp` example in the FMOD Core API examples (found in the FMOD Studio API install - `./api/core/examples/`) as a reference on how to use `FMOD_SOUND_PCMREAD_CALLBACK`, though note that with C# you’ll want to use `Marshal.Copy()` instead of manually iterating through the data to copy it.
