4

Im trying to create an Analyser node to get the signal from a microphone, and be able to create a graphic with the received input. But I dont want to the speakers to still recive the microphone signal.

Source (microphone) -> Analyser -> Destination(?)

The destination is always the speakers... Can I put the destination to a void or similar, and be able to still analyze the microphone?

I tried to play with the Volumne (gain node) but that affects the analyser in the end.

In summary: I need to be able to analyze an input from the microphone but mute that signal on the speakers.

EDIT: Here is what I'm doing.

analyser = context.createAnalyser();
analyser.smoothingTimeConstant = 0.4;
analyser.fftSize = 64;

microphone.connect(analyser)
analyser.connect(context.destination);

This is working fine... but Im getting the sound on the speakers. If I ask for example:

var data = new Uint8Array(analyzer.frequencyBinCount);
analyzer.getByteFrequencyData(data)

Then data will contain the reponse from microphone.

But if I add gain after like this

volume.gain.value = 0; 
microphone.connect(analyser)
analyser.connect(volume);
volume.connect(context.destination);

or I do not make the connect to context.destination, then the data array will be all 0 (not reponse from microphone)

JsStack
  • 109
  • 1
  • 8

2 Answers2

4

Actually, you don't even need to connect the analyser. It should process without being connected to the destination.

cwilso
  • 13,610
  • 1
  • 30
  • 35
  • I did that as well, and the analyser get reponse an array of 0 as well. – JsStack Dec 27 '15 at 20:17
  • Would you mind checking out my similar question? https://stackoverflow.com/questions/47799590/audiocontext-gain-node-does-not-mute-audio-source-web-audio-api – Surz Dec 13 '17 at 18:43
  • Hi, thanks, I remove ```audioGain.connect(audioContext.destination); ``` and problem was solved – kolserdav Sep 19 '22 at 10:01
2

Add a gain node after the analyser node and set its value to 0. So..

var volume = context.createGain();
volume.gain.value = 0;

microphone.connect(analyser);
analyser.connect(volume);
volume.connect(context.destination);
Stuart Memo
  • 1,138
  • 4
  • 14
  • 30
  • That was the first thing that I did, but I get a array of 0 from the analyser – JsStack Dec 27 '15 at 20:17
  • Would you mind checking out my similar question? https://stackoverflow.com/questions/47799590/audiocontext-gain-node-does-not-mute-audio-source-web-audio-api – Surz Dec 13 '17 at 18:43