Capture audio from Microphone without playing it back

不羁的心 提交于 2019-12-01 10:00:26

问题


I am trying to use a microphone and process the audio captured. I managed to do all that, but I have a problem... My audio captured is automatically played to the user, and I don't want that.

    audioSrc.clip = Microphone.Start(null, true, 1000, 44100);
    while (!(Microphone.GetPosition(null) > 0)) { }
    audioSrc.Play();

I tried to disable the audio listener and lower the volume of the audio source, but that didn't work.

Anyone knows how I can capture audio without playing it back?

EDIT 1:

void Start()
{
    GameObject a = new GameObject("AudioSource");
    audioSrc = a.AddComponent<AudioSource>();
    Instantiate(a);

    string deviceName = Microphone.devices[0];
    audioSrc.clip = Microphone.Start(deviceName, true, 1000, 44100);
    audioSrc.volume = 0;
    while (!(Microphone.GetPosition(null) > 0)) { }

    audioSrc.Play();
}

void Update()
{
    audioSrc.GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);
    frq = findPitch(spectrum);
    txtFreq.text = "Hz: " + frq;
    trigger.update(Time.deltaTime, frq);
}

回答1:


Anyone knows how I can capture audio without playing it back?

There are two methods to do this:

1.Set the volume to a very low number. This cannot be 0. The value of 0.001f is totally fine.

audioSrc.volume = 0.001f;

Works in the Editor. Not tested on any other platform except on Windows. Use method 2 if there is a problem.


2.Use AudioMixer to handle it

If setting the volume to 0.001f did not completely mute the audio then use AudioMixer to fix it.

A.Create AudioMixer. Assets ---> Create ---> Audio Mixer and name is "MicMixer".

B.Create new Group under the Mixer and name it "MuteMic".

C.Change the attenuation of that "MuteMic" group to -80.

D.Drag that "MuteMic" group to your Mic's AudioSource's Output slot. That's it. The GetOutputData function properly without any sound coming out from the speaker.

Animated gif for this:



来源:https://stackoverflow.com/questions/37787343/capture-audio-from-microphone-without-playing-it-back

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