我正在使用AVAudioEngine捕捉用户的声音,同时对声音应用一些实时效果(如混响或某事)。这是我的代码
import UIKit
import AVFoundation
class ViewController: UIViewController{
var audioEngine:AVAudioEngine!
var audioReverb:AVAudioUnitReverb!
var audioInputNode:AVAudioInputNode!
override func viewDidLoad() {
super.viewDidLoad()
let session = AVAudioSession.sharedInstance()
session.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
session.setActive(true, error: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func recordWithReverb(sender: AnyObject) {
audioEngine = AVAudioEngine()
audioEngine.stop()
audioEngine.reset()
audioInputNode = audioEngine.inputNode
audioReverb = AVAudioUnitReverb()
audioReverb.loadFactoryPreset(.LargeRoom)
audioReverb.wetDryMix = 50
audioEngine.attachNode(audioReverb)
let inputFormat = audioReverb.inputFormatForBus(0)
audioEngine.connect(audioInputNode, to: audioReverb, format: inputFormat)
audioEngine.connect(audioReverb, to: audioEngine.outputNode, format: inputFormat)
audioEngine.startAndReturnError(nil)
}
}
当我用带有麦克风的耳机(如耳机)进行测试时,一切正常。但是当我使用其他没有麦克风的耳机时(所以我只能使用iphone上的麦克风作为输入源) ),耳机的右扬声器总是听起来比耳机的左扬声器小。我怎么修理它?
当我编写代码时,我还想提出另一个问题
var audioEngine:AVAudioEngine!
var audioReverb:AVAudioUnitReverb!
var audioInputNode:AVAudioInputNode!
在函数内部" recordWithReverb",代码无法正常工作,我无法获得任何输出,为什么会发生这种情况?
答案 0 :(得分:0)
似乎设置wetDryMix值更大可以解决这个问题。
audioReverb.wetDryMix = 80