2
votes

I'm implementing an Offline Continuos Speech Recognition Android Application with Google Speech Recognition to manage an Arduino device connected to the smartphpone via Bluetooth. When I use Bluetooth Headset, I want to use the Bluetooth Microphone instead of the phone microphone. I specified the following code:

private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
    public void onServiceConnected(int profile, BluetoothProfile proxy) {
        if (profile == BluetoothProfile.HEADSET) {
            mBluetoothHeadset = (BluetoothHeadset) proxy;
        }
    }
    @Override
    public void onServiceDisconnected(int profile) {
        if (profile == BluetoothProfile.HEADSET) {
            mBluetoothHeadset = null;
        }
    }
};

and the BluetoothHeadsetReceiver:

public class BluetoothHeadsetReceiver extends BroadcastReceiver {

    public BluetoothHeadsetReceiver(Context context) {
        IntentFilter intentFilter = new IntentFilter(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);        intentFilter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);         intentFilter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
        context.registerReceiver(this, intentFilter);
        mBluetoothHeadsetReceiver = true;
    }
    public void onReceive(Context context, Intent intent) {
        int state = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
        if (state == BluetoothHeadset.STATE_AUDIO_CONNECTED) {
            deviceBTName = mBluetoothHeadset.getConnectedDevices().get(0).getName();
            deviceBT = mBluetoothHeadset.getConnectedDevices().get(0);
            audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
            audioManager.startBluetoothSco();
            audioManager.setBluetoothScoOn(true);
            audioManager.setMicrophoneMute(true);
          }
        }
        else if (state == BluetoothHeadset.STATE_AUDIO_DISCONNECTED)
        {
            audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
            audioManager.startBluetoothSco();
            audioManager.setBluetoothScoOn(true);
            mBluetoothConnected = false;
        }
    }
}

but the application always use the Phone Microphone.

How can I route the voice input via Bluettoth Microphone? Thanks

1

1 Answers

0
votes

Solved using: audioManager.setSpeakerphoneOn(false);