# How to get AudioContext from WebRTCPeer or Subscriber

**URL:** <https://openvidu.discourse.group/t/how-to-get-audiocontext-from-webrtcpeer-or-subscriber/3731>\
**Category:** Issues developing apps\
**Tags:** v2\
**Created:** [February 7, 2022, 8:23am UTC](https://openvidu.discourse.group/t/how-to-get-audiocontext-from-webrtcpeer-or-subscriber/3731 "2022-02-07T08:23:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![buck](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@buck](https://openvidu.discourse.group/u/buck)\
**Post date:** [February 7, 2022, 8:23am UTC](https://openvidu.discourse.group/t/how-to-get-audiocontext-from-webrtcpeer-or-subscriber/3731/1 "2022-02-07T08:23:19Z")

</div>

Nice to meet you.  
I am a junior developer who is successfully performing real-time video interview service using OpenVidu.

During development, I am trying to visualize audio by receiving audio from a remote stream rather than a local stream.

I thought it wouldn’t be difficult at all to visualize this, since I’m already listening to other users, but it doesn’t seem to be. I seem to be missing something.  
Hints from other great developers for visualizing audio seem to all use AudioContext, but I’m not sure how to incorporate it into Openvidu.

Even if I check the objects one by one using the browser’s developer tool, I can’t figure out how to combine them.

I’d like to get some advice on whether my approach is the right way, or if there is another way.

Here is the example code I was trying to graft.

> **[Getting Audio Visualizations working with Web Audio API / Dwayne.xyz](https://dwayne.xyz/post/audio-visualizations-web-audio-api)**
>
> Dwayne's Website

Thank you.

---

<div class="post-metadata">

**Author:** ![CSantosM](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/csantosm/32/16_2.png) [@CSantosM](https://openvidu.discourse.group/u/CSantosM)\
**Post date:** [February 7, 2022, 9:16am UTC](https://openvidu.discourse.group/t/how-to-get-audiocontext-from-webrtcpeer-or-subscriber/3731/2 "2022-02-07T09:16:49Z")

</div>

Hi @buck , welcome to OpenVidu.

Have you tried the `publisherStartSpeaking` event? [Speech detection - OpenVidu Docs](https://docs.openvidu.io/en/stable/advanced-features/speech-detection/#speech-detection)

Also the [AudioVolumeDetection](https://docs.openvidu.io/en/stable/advanced-features/speech-detection/#audio-volume-detection) event could help you.

---

<div class="post-metadata">

**Author:** ![pabloFuente](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/pablofuente/32/2536_2.png) [@pabloFuente](https://openvidu.discourse.group/u/pabloFuente)\
**Post date:** [February 7, 2022, 9:28am UTC](https://openvidu.discourse.group/t/how-to-get-audiocontext-from-webrtcpeer-or-subscriber/3731/3 "2022-02-07T09:28:24Z")

</div>

Also, if all you need is a call to `AudioContext.createMediaStreamSource(mediaStream)`, then you can simply access the internal MediaStream of any Stream object with **[`Stream.getMediaStream()`](https://docs.openvidu.io/en/stable/api/openvidu-browser/classes/stream.html#getmediastream)**

---

<div class="post-metadata">

**Author:** ![buck](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@buck](https://openvidu.discourse.group/u/buck)\
**Post date:** [February 8, 2022, 1:01am UTC](https://openvidu.discourse.group/t/how-to-get-audiocontext-from-webrtcpeer-or-subscriber/3731/4 "2022-02-08T01:01:41Z")

</div>

@CSantosM  
Of course!  
Even now, we use detection and recording functions conveniently only when users speak!

@pabloFuente  
I’m sorry for my lack of understanding.  
I want to check and visualize the audio of other users except myself, but it’s not going well.  
( visualizing my audio has already been completed.)  
I’m going to apply it to the sauce below. Yes, that’s right. I need `AudioContext.createMediaStreamSource(mediaStream)` as the leader explained.  
Am I missing something?

 ![image](https://global.discourse-cdn.com/free1/uploads/openvidu/original/2X/e/e2a27b00e2a429d9be2064d543e010fca5e42d96.png)

---

<div class="post-metadata">

**Author:** ![pabloFuente](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/pablofuente/32/2536_2.png) [@pabloFuente](https://openvidu.discourse.group/u/pabloFuente)\
**Post date:** [February 8, 2022, 9:14am UTC](https://openvidu.discourse.group/t/how-to-get-audiocontext-from-webrtcpeer-or-subscriber/3731/5 "2022-02-08T09:14:53Z")

</div>

Stream.getMediaStream is a method. It is not a property:

```auto
stream.getMediaStream();

```

That will return the native Web API `MediaStream` object associated to OpenVidu’s `Stream` object.

---

<div class="post-metadata">

**Author:** ![buck](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@buck](https://openvidu.discourse.group/u/buck)\
**Post date:** [February 10, 2022, 2:31am UTC](https://openvidu.discourse.group/t/how-to-get-audiocontext-from-webrtcpeer-or-subscriber/3731/6 "2022-02-10T02:31:35Z")

</div>

@pabloFuente  
As you said, I checked the value on the browser console, but I don’t know how to get it undefined.

 ![image](https://global.discourse-cdn.com/free1/uploads/openvidu/original/2X/a/a86314d77f45ccdf314651df8c4e6408514915a0.png)

Where and what am I missing and doing wrong?

---

<div class="post-metadata">

**Author:** ![pabloFuente](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/pablofuente/32/2536_2.png) [@pabloFuente](https://openvidu.discourse.group/u/pabloFuente)\
**Post date:** [February 10, 2022, 9:37am UTC](https://openvidu.discourse.group/t/how-to-get-audiocontext-from-webrtcpeer-or-subscriber/3731/7 "2022-02-10T09:37:01Z")

</div>

Why are you accessing it on `videoElementCreated` event?  
Use method [Session.subscribeAsync](https://docs.openvidu.io/en/stable/api/openvidu-browser/classes/session.html#subscribeasync) to get your Subscriber object. Once that promise is resolved, you may access the internal Stream.getMediaStream() object and that should be properly defined.
