Ios 是否有办法将语音处理io音频单元路由到蓝牙设备?

Ios 是否有办法将语音处理io音频单元路由到蓝牙设备?,ios,audio,bluetooth,core-audio,audiounit,Ios,Audio,Bluetooth,Core Audio,Audiounit,我正在做一个应用程序,它需要语音处理io音频单元来做一些回声消除工作。它工作正常,但结果是音频输出无法路由到蓝牙设备(它不是免提蓝牙设备,而是蓝牙立体声扬声器)。下面是我如何启动音频的东西 AudioComponentDescription desc; desc.componentType = kAudioUnitType_Output; desc.componentSubType = kAudioUnitSubType_VoiceProcessingIO; desc.componentManu

我正在做一个应用程序,它需要语音处理io音频单元来做一些回声消除工作。它工作正常,但结果是音频输出无法路由到蓝牙设备(它不是免提蓝牙设备,而是蓝牙立体声扬声器)。下面是我如何启动音频的东西

AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;

AudioComponent comp = AudioComponentFindNext(NULL, &desc);
AudioComponentInstanceNew(comp, &_audioUnit);

UInt32 one = 1;

AURenderCallbackStruct callbackStruct;
callbackStruct.inputProc = recordingCallback;
callbackStruct.inputProcRefCon = (__bridge void *)self;

AudioUnitSetProperty(_audioUnit, kAudioOutputUnitProperty_SetInputCallback,
                                 kAudioUnitScope_Global,
                                 kInputBus,
                                 &callbackStruct,
                                 sizeof(callbackStruct));

_audioFormat.mSampleRate = kSampleRate;
_audioFormat.mFormatID = kAudioFormatLinearPCM;
_audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
_audioFormat.mFramesPerPacket = 1;
_audioFormat.mChannelsPerFrame = 1;
_audioFormat.mBitsPerChannel = 16;
_audioFormat.mBytesPerPacket = 2;
_audioFormat.mBytesPerFrame = 2;

AudioUnitSetProperty(_audioUnit, kAudioUnitProperty_StreamFormat,
                                 kAudioUnitScope_Output,
                                 kInputBus,
                                 &_audioFormat,
                                 sizeof(_audioFormat));
AudioUnitSetProperty(_audioUnit, kAudioUnitProperty_StreamFormat,
                                 kAudioUnitScope_Input,
                                 kOutputBus,
                                 &_audioFormat,
                                 sizeof(_audioFormat));
AudioUnitSetProperty(_audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof(one));
AudioUnitSetProperty(_audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &one, sizeof(one));


// Configure the audio session
AVAudioSession *sessionInstance = [AVAudioSession sharedInstance];
[sessionInstance setCategory:AVAudioSessionCategoryPlayAndRecord
                 withOptions:AVAudioSessionCategoryOptionDuckOthers | AVAudioSessionCategoryOptionAllowBluetooth
                       error:NULL];

[sessionInstance overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleRouteChange:)
                                             name:AVAudioSessionRouteChangeNotification
                                           object:nil];

[[AVAudioSession sharedInstance] setActive:YES error:NULL];
AudioUnitInitialize(_audioUnit);
AudioOutputUnitStart(_audioUnit);

我还将输出路由到扬声器,而不是默认的耳朵扬声器,因为它的音量非常低。但是,我未能实现将输出路由到蓝牙。有人能帮我吗?谢谢。

所以这实际上取决于蓝牙设备的类型,它是蓝牙HFP(输入和输出)、蓝牙A2DP(仅输出)还是蓝牙(仅输出)。如果设备仅输出,您将无法连接和路由kAudioSessionCategory\u Play和Record category中的音频。

AirPlay有助于其功能。这是系统中的默认设置,当设备连接到ios中相同的wifi和蓝牙时。我认为你们的回答并没有解决我的问题。我想Airplay是用于视频播放的,但我的情况是我需要在一些蓝牙输出设备上播放音频。