gpt4 book ai didi

ios - 有没有办法将语音处理io音频单元路由到蓝牙设备?

转载 作者:行者123 更新时间:2023-11-29 02:41:48 30 4
gpt4 key购买 nike

我正在开发一个应用程序,需要语音处理 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);

我还将输出路由到扬声器,而不是默认的耳机扬声器,该扬声器的音量非常低。但是,我未能实现将输出路由到蓝牙。有人能帮我解决这个问题吗?谢谢。

最佳答案

所以这实际上取决于蓝牙设备的类型,无论是BluetoothHFP(输入和输出)、BluetoothA2DP(仅输出)还是BluetoothLE(仅输出)。如果设备仅输出,您将无法连接和路由 kAudioSessionCategory_PlayAndRecord 类别中的音频。

关于ios - 有没有办法将语音处理io音频单元路由到蓝牙设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25679077/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com