0
我正在做一個應用程序,需要語音處理io音頻單元來做一些回聲消除工作。它工作正常,但事實證明,音頻輸出不能路由到藍牙設備(它不是一個免提藍牙設備,但藍牙立體聲揚聲器)。下面是我如何啓動音頻的東西有沒有辦法將語音處理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);
我也路由輸出到揚聲器,而不是默認的聽筒,其量非常低。但是,我未能實現路由輸出到藍牙。任何人都可以幫助我嗎?謝謝。
AirPlay對ITS有好處。當設備與ios中的wifi和藍牙連接時,這是系統默認設置。 – 2014-09-05 11:17:00
我不認爲你的答案解決了我的問題。我假設Airplay是用於播放視頻的,但我的情況是我需要在某些藍牙輸出設備上播放音頻。 – seanxiaoxiao 2014-09-06 03:27:26