-1

I'm testing Electron app which uses microphone. My goal is to test behavior when mic is muted in the app. When I use "use-fake-ui-for-media-stream","use-fake-device-for-media-stream" flags on app run - there is random noises generation when mic is enabled, but no sound generating when mic is disabled. My idea is to pass some JS generated sound into microphone input when microphone is muted. Will it work ? How to do this ?

Artsiom
  • 37
  • 5

1 Answers1

0

You can check out Web Audio API and its nodes structure that enables you to pass the audio between nodes and finally reach it to a destination.

As for WebRTC part you can just need to add the tracks to your rtc peer connection object. You will need to obtain tracks of this audio you will generate, if it is a stream get its tracks, a stream (MediaStream) has getTracks method. A WebRTC Peer Connection object has an addTrack method you can use, iterate over the tracks and call this method to add them to you rrtc peer conneciton object.

sçuçu
  • 2,960
  • 2
  • 33
  • 60
  • Answer is unclear. All standart WebRTC tutorials shows only way to get audio from microphone but not pow to pass audio into it. – Artsiom Jul 29 '20 at 13:59
  • It is descriptive. I just did not have example code since you may have a different setup among many possible ones so I have left it your possible use case. If you have one in mind tell me. Anyways I will try to give an example when I have it. Can you clarify that you want an example too, since you asked how and the answer is clear enough? – sçuçu Jul 29 '20 at 19:32
  • What do you mean under "may have a different setup" when in question I wrote that setup is Test Automation on JS for Electron app ? – Artsiom Jul 30 '20 at 20:29
  • I meant the source you get your stream and tracks, not what technology/framework you use. Since that way the given example code in answer would change and may not be so useful. Other than that I think the description I gave can be followed to achieve what you want. Also, although the title includes WebRTC, and you do not use it but use only mediaDevices.getUserMedia(), please tell me since the WebRTC methods and solution I gave was really for a WebRTC use case. – sçuçu Jul 31 '20 at 08:18
  • Even then you will need to `addTracks` to a stream. Generate you rmedia tracks and add them to your stream you got from your mic via `getUserMedia`. – sçuçu Jul 31 '20 at 08:25