我试图制作一个可以同时快速录制AudioKit AKOscillatorBank和来自麦克风的人声的钢琴声音的应用程序。我尝试了AVFoundation的AVAudioRecorder,但是在弹钢琴时失败了。我尝试使用AVAudioSessionCategoryPlayAndRecord,但它似乎仍然无法正常工作:
func startRecording() {
fileName = String(format:"AudioFile%d.m4a",k)
k = k+1
let audioFilename = getDocumentsDirectory().appendingPathComponent(fileName)
address.append("\(audioFilename)")
print("adress = %s",address[num])
num = num + 1
let settings = [
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
AVSampleRateKey: 12000,
AVNumberOfChannelsKey: 2,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord, with:AVAudioSessionCategoryOptions.defaultToSpeaker)
try session.setActive(true)
SoundRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)
SoundRecorder.isMeteringEnabled = true
SoundRecorder.prepareToRecord()
SoundRecorder.delegate = self
SoundRecorder.record()
} catch {
}
}
我不知道该怎么办,有什么办法可以通过快速或客观C来做到?任何建议都将不胜感激。
答案 0 :(得分:2)
要录制不同的AudioKit节点,请使用AKNodeRecorder。 AudioKit附带一个“记录器”示例项目:
https://github.com/AudioKit/AudioKit/blob/master/Examples/iOS/Recorder/Recorder/ViewController.swift