Reputation: 31
I want to record with Bluetooth Speaker connected to iPad. However, when using AVAudioRecorder, it turns into built-in speaker.
let session = AVAudioSession.sharedInstance()
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try! session.setActive(true)
let recordSetting: [String: Any] = [AVSampleRateKey: NSNumber(value: 16000),
AVFormatIDKey: NSNumber(value: kAudioFormatLinearPCM),
AVLinearPCMBitDepthKey: NSNumber(value: 16),
AVNumberOfChannelsKey: NSNumber(value: 1),
AVEncoderAudioQualityKey: NSNumber(value: AVAudioQuality.max.rawValue)
];
do {
self.audioRecorder = try AVAudioRecorder(url: url as URL, settings: recordSetting)
} catch {
fatalError(“error”)
}
Upvotes: 1
Views: 237
Reputation: 31
OK I Solved the question. If you want to AVAudioRecording with bluetooth speaker or microphone, set the options at "setCategory" method as below.
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord,
mode:AVAudioSessionModeDefault,
options:AVAudioSessionCategoryOptions.allowBluetoothA2DP)
Thanks.
Upvotes: 2