从麦克风捕获音频而无需播放 [英] Capture audio from Microphone without playing it back
问题描述
我正在尝试使用麦克风来处理捕获的音频.我设法做到了所有这些,但是有一个问题...我捕获的音频会自动播放给用户,我不想要那样.
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?
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);
}
推荐答案
任何人都知道如何在不播放音频的情况下捕获音频吗?
Anyone knows how I can capture audio without playing it back?
有两种方法可以做到这一点:
There are two methods to do this:
1 .将音量设置为非常低的数字. 不能为0 . 0.001f
的值完全可以.
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;
在编辑器中工作.除Windows之外,未在任何其他平台上进行测试.如果有问题,请使用方法2.
Works in the Editor. Not tested on any other platform except on Windows. Use method 2 if there is a problem.
2 .使用AudioMixer对其进行处理
2.Use AudioMixer to handle it
如果将音量设置为0.001f
并没有完全静音,请使用AudioMixer
对其进行修复.
If setting the volume to 0.001f
did not completely mute the audio then use AudioMixer
to fix it.
A .创建AudioMixer. 资产 ---> 创建 ---> 音频混音器,名称为"MicMixer" .
A.Create AudioMixer. Assets ---> Create ---> Audio Mixer and name is "MicMixer".
B .在混音器下创建新的组,并将其命名为"MuteMic".
B.Create new Group under the Mixer and name it "MuteMic".
C .将静音麦克风" 组的衰减更改为-80
.
C.Change the attenuation of that "MuteMic" group to -80
.
D .将"MuteMic" 组拖动到Mic的AudioSource的 Output 插槽中.而已. GetOutputData
功能正常,扬声器没有声音发出.
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.
为此的动画gif:
这篇关于从麦克风捕获音频而无需播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!