Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Muting/unmutting & changing volume via Web Audio API in JavaScript

I have a few quick questions regarding the Web Audio API. I am developing in JavaScript (AngularJS).

A great demo app that I am using is at: https://webaudiodemos.appspot.com/AudioRecorder/index.html

Once I grant access to my audio microphone in my Chrome browser, using the Audio API, is there a way to:

  1. Mute and un-mute the microphone?
  2. Manually changing the microphone volume from JavaScript?
  3. An Audio API function returning a Boolean flag (or any object) letting me know if the microphone is inaccessible (not working)?

I have found a few links on StackOverflow, but they have not given me the key information that I can use for my need:

  • Volume control with Web Audio API
  • Mute microphone in speakers but still be able to analyze (createAnalyser) with Web Audio Api?
  • How to mute all sound in a page with JS?
like image 580
Sonny K Avatar asked Jun 25 '26 04:06

Sonny K


1 Answers

1) Just run the MediaStreamSource node through a Gain node, and set gain to 0 or 1 to mute or unmute.

2) Ditto. Just use the same gain node.

3) Not really - what do you mean by "not working"? If it's really not working, you'll never get the stream.

like image 193
cwilso Avatar answered Jun 27 '26 17:06

cwilso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!