HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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 – 将音频从麦克风通过蓝牙传输到另一个iPhone全部内容,希望文章能够帮你解决ios – 将音频从麦克风通过蓝牙传输到另一个iPhone所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。