我希望有人可以帮助我。我正在尝试获得一个基本的录音设置,但是AudioKit正在崩溃,我确信这是我的错,而且我做的不对。这是我的设置。在我的viewDidLoad
我正在配置AudioKit,如下所示:
// Session settings
do {
AKSettings.bufferLength = .short
try AKSettings.setSession(category: .playAndRecord, with: .allowBluetoothA2DP)
} catch {
AKLog("Could not set session category.")
}
AKSettings.defaultToSpeaker = true
// Setup the microphone
micMixer = AKMixer(mic)
micBooster = AKBooster(micMixer)
// Load the test player
let path = Bundle.main.path(forResource: "audio1", ofType: ".wav")
let url = URL(fileURLWithPath: path!)
testPlayer = AKPlayer(url: url)
testPlayer?.isLooping = true
// Setup the test mixer
testMixer = AKMixer(testPlayer)
// Pass the output from the player AND the mic into the recorder
recordingMixer = AKMixer(testMixer, micBooster)
recorder = try? AKNodeRecorder(node: recordingMixer)
// Setup the output mixer - only pass the player NOT the mic
outputMixer = AKMixer(testMixer)
// Pass the output mixer to AudioKit
AudioKit.output = outputMixer
// Start AudioKit
do {
try AudioKit.start()
} catch {
print("AudioKit did not start! \(error)")
}
应用程序构建正常,但只要我触发recorder.record()
,应用程序就会崩溃并显示以下消息:
必需条件为false:mixingDest。
我真的不想将麦克风传递给扬声器输出,但我想要录制它。
我希望能够通过“testPlayer”播放文件,通过扬声器收听,同时能够录制“testPlayer”和麦克风的输出,而无需通过麦克风将麦克风传回扬声器。
我确信这是可行的,但我不知道这些事情应该如何运作才能知道我做错了什么。
非常感谢任何帮助!!
答案 0 :(得分:4)
好的,所以在与AudioKit的人交谈后,我发现问题是因为我的recordingMixer没有连接到AudioKit.output。为了通过混音器提取音频,需要将其连接到AudioKit.output。
为了使我的recordingMixer的输出静音,我必须创建一个静音的虚拟录音混音器,并将其传递给outputMixer。
请参阅下面的更新示例:
// Session settings
do {
AKSettings.bufferLength = .short
try AKSettings.setSession(category: .playAndRecord, with: .allowBluetoothA2DP)
} catch {
AKLog("Could not set session category.")
}
AKSettings.defaultToSpeaker = true
// Setup the microphone
micMixer = AKMixer(mic)
micBooster = AKBooster(micMixer)
// Load the test player
let path = Bundle.main.path(forResource: "audio1", ofType: ".wav")
let url = URL(fileURLWithPath: path!)
testPlayer = AKPlayer(url: url)
testPlayer?.isLooping = true
// Setup the test mixer
testMixer = AKMixer(testPlayer)
// Pass the output from the player AND the mic into the recorder
recordingMixer = AKMixer(testMixer, micBooster)
recorder = try? AKNodeRecorder(node: recordingMixer)
// Create a muted mixer for recording audio, so AudioKit will pull audio through the recording Mixer, but not play it through the output.
recordingDummyMixer = AKMixer(recordingMixer)
recordingDummyMixer.volume = 0
outputMixer = AKMixer(testMixer, recordingDummyMixer)
// Pass the output mixer to AudioKit
AudioKit.output = outputMixer
// Start AudioKit
do {
try AudioKit.start()
} catch {
print("AudioKit did not start! \(error)")
}
我希望将来可以帮助某人。