ios - 无法在 iPad + Swift 3 上使用蓝牙扬声器进行录音

标签 ios swift swift3 avfoundation avaudiorecorder

我想用连接到 iPad 的蓝牙音箱录音。 但是,当使用 AVAudioRecorder 时,它变成了内置扬声器。

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”)
   }

最佳答案

好的,我解决了这个问题。 如果您想使用蓝牙扬声器或麦克风进行 AVAudioRecording,请在“setCategory”方法中设置选项,如下所示。

try! session.setCategory(AVAudioSessionCategoryPlayAndRecord,
        mode:AVAudioSessionModeDefault,
        options:AVAudioSessionCategoryOptions.allowBluetoothA2DP)

谢谢。

关于ios - 无法在 iPad + Swift 3 上使用蓝牙扬声器进行录音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44489801/

相关文章:

iphone - 在此代码段中使用 NSThread

swift - CLGeocoder geocodeAddressString() 达到极限

ios - 如何创建 pinterest 布局?

ios - 从 Node.js (Express) 服务器发送字符串到 iOS Swift 3

ios - 标签为空时的 UITableView 单元格垂直居中

ios - 调整 UITableViewCell 中的 UILabel 显示错误

ios - Swift imageView 动画不起作用

ios - for循环的swift 3.0索引1超出范围[0 .. 0]错误

iphone - 如何从底部对齐 UILabel 文本?

ios - 使用@IBDesignable 更改标签字体