首页 文章

通过蓝牙连接实现Android语音识别

提问于
浏览
2

我正在实施一个带有Google语音识别功能的离线连续语音识别Android应用程序来管理通过蓝牙连接到smartphpone的Arduino设备 . 当我使用蓝牙耳机时,我想使用蓝牙麦克风而不是手机麦克风 . 我指定了以下代码:

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;
        }
    }
};

和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;
        }
    }
}

但应用程序始终使用电话麦克风 .

如何通过Bluettoth麦克风路由语音输入?谢谢

1 回答

  • 0

    解决使用:audioManager.setSpeakerphoneOn(false);

相关问题