[英]how to record microphone and piano at same time
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.我正在尝试制作一个应用程序,它可以在 swift 4 中同时录制 AudioKit AKOscillatorBank 制作的钢琴声音和来自麦克风的人声。我尝试了 AVFoundation 的 AVAudioRecorder,但是在我弹钢琴时它失败了。 I have tried using AVAudioSessionCategoryPlayAndRecord but it still seems not work:我曾尝试使用 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 {
}
}
I have no Idea what can I do, is there any way to do it by swift or objective C?我不知道我能做什么,有什么办法可以通过 swift 或objective C 来做? any advice and suggestions will be greatly appreciated.任何意见和建议将不胜感激。
To record different AudioKit nodes, use AKNodeRecorder.要录制不同的 AudioKit 节点,请使用 AKNodeRecorder。 There is a "Recorder" example project included with AudioKit: AudioKit 包含一个“录音机”示例项目:
https://github.com/AudioKit/AudioKit/blob/v4-master/Examples/iOS/Recorder/Recorder/ViewController.swift https://github.com/AudioKit/AudioKit/blob/v4-master/Examples/iOS/Recorder/Recorder/ViewController.swift
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.