Reputation: 23
I am trying to make a app which can record the piano sound make by AudioKit AKOscillatorBank and vocal from microphone at same time in swift 4. I tried AVFoundation's AVAudioRecorder, but it failed when I playing piano. I have tried using AVAudioSessionCategoryPlayAndRecord but it still seems not work:
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 {
}
}
I have no Idea what can I do, is there any way to do it by swift or objective C? any advice and suggestions will be greatly appreciated.
Upvotes: 1
Views: 195
Reputation: 4573
To record different AudioKit nodes, use AKNodeRecorder. There is a "Recorder" example project included with AudioKit:
Upvotes: 2