ios – 将音频从麦克风通过蓝牙传输到另一个iPhone

我正在尝试将传入的麦克风音频传输到另一个iPhone.基本上一个电话,但通过蓝牙.我有音频通过AVAudioRecorder进来:
func startRecording() {
    audioRecorder = nil
    let audioSession:AVAudioSession = AVAudioSession.sharedInstance()
    audioSession.setCategory(AVAudioSessionCategoryRecord,error: nil)

    var recordSettings:NSMutableDictionary = NSMutableDictionary(capacity: 10)
    recordSettings.setObject(NSNumber(integerLiteral: kAudioFormatLinearPCM),forKey: AVFormatIDKey)
    recordSettings.setObject(NSNumber(float: 44100.0),forKey: AVSampleRateKey)
    recordSettings.setObject(NSNumber(int: 2),forKey: AVNumberOfChannelsKey)
    recordSettings.setObject(NSNumber(int: 16),forKey: AVLinearPCMBitDepthKey)
    recordSettings.setObject(NSNumber(bool: false),forKey: AVLinearPCMIsBigEndianKey)
    recordSettings.setObject(NSNumber(bool: false),forKey: AVLinearPCMIsFloatKey)

    soundPath = documentsDirectory.stringByAppendingPathComponent("record.caf")
    refURL = NSURL(fileURLWithPath: soundPath as String)
    var error:NSError?

    audioRecorder = AVAudioRecorder(URL: refURL,settings: recordSettings as [NSObject : AnyObject],error: &error)

    if audioRecorder.prepareToRecord() == true {
        audioRecorder.meteringEnabled = true
        audioRecorder.record()
    } else {
        println(error?.localizedDescription)
    }
}

然后我尝试从@ martin-r从HERE – StreamReader使用StreamReader

使用:

if let aStreamReader = StreamReader(path: documentsDirectory.stringByAppendingPathComponent("record.caf")) {
                while let line = aStreamReader.nextLine() {
                    let dataz = line.dataUsingEncoding(NSUTF8StringEncoding)
                    println (line)

然后使用以下方式将数据发送到另一台设备:

self.appDelegate.mpcDelegate.session.sendData(data: NSData!,toPeers: [AnyObject]!,withMode: MCSessionSendDataMode,error: NSErrorPointer )

我将线转换为NSData,然后使用dispatch_after 0.5秒不断运行,我通过蓝牙发送到另一个设备.

这似乎不起作用,我不认为这是一个实际的做法.我已经做了大量的搜索,并没有看到太多的流数据通过蓝牙.关键字流(可理解)将我发送到有关服务器流的页面.

我的问题是,如何从麦克风接收音频并通过蓝牙发送到另一个iPhone?我有蓝牙部分全部设置,它的工作非常好.我的问题非常类似于THIS,除了iPhone和Swift – 我想通过蓝牙打电话.

先谢谢你.

解决方法

要同时录制和重定向输出,您需要使用类别AVAudioSessionCategoryMultiRoute.

以下是类别列表的链接:
https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/#//apple_ref/doc/constant_group/Audio_Session_Categories

如果其他所有失败都可以使用预制的解决方案:
http://audiob.us

它有一个API,可以将音频流从一个应用程序集成到另一个应用程序:
https://developer.audiob.us/

它支持多个输出端点.

希望这可以帮助.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...