简体   繁体   English

使用AVAudioEngine录制麦克风和声音效果

[英]Using AVAudioEngine to record mic and sound effects

I'm using AVAudioEngine to record input from the microphone as well as various sound effects to a single file. 我正在使用AVAudioEngine将来自麦克风的输入以及各种声音效果记录到单个文件中。 While recording, the sound is played back through the speakers, via the engine's outputNode. 录音时,声音通过扬声器,通过引擎的outputNode播放。 However, this causes a weird effect for users recording with headsets, since they can hear their own voice played back through the speakers/headphones. 然而,这对于使用耳机进行录制的用户来说会产生奇怪的效果,因为他们可以通过扬声器/耳机听到自己的声音。 Therefore, I only wish to output the sound of the sound files through the speakers and not the sound coming from the microphone. 因此,我只希望通过扬声器输出声音文件的声音,而不是来自麦克风的声音。

I haven't found a way to achieve this using AVAudioEngine, however. 但是,我还没有找到使用AVAudioEngine实现此目的的方法。 My latest attempt involved hooking up the sound file nodes to the main mixer, and have them played back using the mixer's outputNode and then hooking up the microphone to a second mixer. 我的最新尝试包括将声音文件节点连接到主混音器,然后使用混音器的outputNode播放它们,然后将麦克风连接到第二个混音器。 The mainMixer then sends its output (the audio from the sound files) to this mixer, which I installed a tap on, for writing the audio to my file. 然后mainMixer将其输出(来自声音文件的音频)发送到此混音器,我安装了一个水龙头,用于将音频写入我的文件。

However, mixer nodes only have one output, which means that no sound at all was played back through the speakers, since the mainMixer had been altered to route it's output to the second mixer instead of to the outputNode. 但是,混音器节点只有一个输出,这意味着根本没有声音通过扬声器播放,因为mainMixer已被改变以将其输出路由到第二个混音器而不是outputNode。

Here's my engine layout: 这是我的引擎布局:

soundfileNode ----> mainMixer ---> outputNode (speaker)
                        |
                        |
                        v
inputNode (mic) --> secondaryMixer ---> tap (write to file)

How can I solve my problem? 我怎样才能解决我的问题? Any ideas? 有任何想法吗?

Update: 更新:

I'm now using AVAudioConnectionPoint to split the output from the mainMixer. 我现在正在使用AVAudioConnectionPoint来分割mainMixer的输出。 However, the sound files played back (and recorded) sound distorted, with lots of crackling and noise. 然而,播放(和录制)的声音文件声音失真,有很多噼啪声和噪音。 This only occurs when I install a tap on my secondary mixer, for writing to the output file. 这只发生在我的辅助混音器上安装一个水龙头,用于写入输出文件。 Has anyone else experienced this? 还有其他人经历过这个吗?

However, mixer nodes only have one output 但是,混合器节点只有一个输出

Aha, but that's not true. 啊哈,但事实并非如此。 You're looking for AVAudioConnectionPoint. 您正在寻找AVAudioConnectionPoint。 By connecting to an array of connection points, you split the output. 通过连接到一组连接点,可以拆分输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM