Mute microphone in speakers but still be able to analyze (createAnalyser) with Web Audio Api?

旧城冷巷雨未停 提交于 2020-01-03 19:58:09

问题


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)


回答1:


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);



回答2:


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



来源:https://stackoverflow.com/questions/34482708/mute-microphone-in-speakers-but-still-be-able-to-analyze-createanalyser-with-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!