iOS獲取音訊裝置資訊
方法1:
CFDictionaryRef descDictRef = nil;
UInt32 refSize = sizeof(descDictRef);
status = AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription, &refSize, &descDictRef);
列印資訊如下:
Printing description of dictRef:
{
"RouteDetailedDescription_Outputs" = (
{
"RouteDetailedDescriptionKey_EndpointType" = Headphones;
"RouteDetailedDescription_ChannelDescriptions" = (
{
"ChannelDescription_Label" = 1;
"ChannelDescription_Name" = "AirPods \U5de6";
},
{
"ChannelDescription_Label" = 2;
"ChannelDescription_Name" = "AirPods \U53f3";
}
);
"RouteDetailedDescription_ID" = 486;
"RouteDetailedDescription_IsHeadphones" = 1;
"RouteDetailedDescription_IsVoiceProcessingSupported" = 0;
"RouteDetailedDescription_Name" = AirPods;
"RouteDetailedDescription_NumberOfChannels" = 2;
"RouteDetailedDescription_PortType" = BluetoothA2DPOutput;
"RouteDetailedDescription_UID" = "7C:04:D0:8A:43:33-tacl";
}
);
}
方法2:
NSArray* availableInputs = [[AVAudioSession sharedInstance] availableInputs];
列印資訊如下:
Printing description of availableInputs:
<__NSSingleObjectArrayI 0x17400cb30>(
<AVAudioSessionPortDescription: 0x17400cae0, type = MicrophoneBuiltIn; name = iPhone 麥克風; UID = Built-In Microphone; selectedDataSource = 下>
)
如果是藍芽裝置,採集的時候取樣率設定比較高,傳輸的時候可能會丟資料,可以取樣率設定小一點,後面再做重取樣處理。