[英]how to switch audio input between inbuilt mic and headset mic after a bluetooth headset is connected in android?
I am working with a voice recognition app. 我正在使用语音识别应用程序。 After a bluetooth headset is successfully connected to my android device, I want to freely switch audio input between the inbuilt mic and headset mic, how to do it?
蓝牙耳机成功连接到我的android设备后,我想在内置麦克风和头戴式麦克风之间自由切换音频输入,该怎么办?
You can use the following code to switch bluetooth headset mic. 您可以使用以下代码来切换蓝牙耳机麦克风。
AudioManager audiomanager= (AudioManager)mContext.getSystemService(Context
.AUDIO_SERVICE);
IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
mContext.registerReceiver(mBluetoothScoReceiver, intentFilter);
audiomanager.startBluetoothSco();
and listen for the broadcast receiver. 并收听广播接收器。
private BroadcastReceiver mBluetoothScoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
// Start recording audio
log("audio connected");
startRecording();
} else if(state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED){
log("audio disconnected");
}
}
};
and for switching(to disconnect bluetooth headset mic) you can use this code. 对于切换(断开蓝牙耳机麦克风),您可以使用此代码。
mAudioManager.stopBluetoothSco();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.