使用蓝牙耳机录制(语音识别)

时间:2013-12-26 19:59:27

标签: android bluetooth voice-recognition headset

我尝试在我的应用程序中添加功能,您可以通过蓝牙耳机与其进行通信。

我是这样的:

BluetoothHeadset mBluetoothHeadset;
AudioManager mAudioManager;
// Get the default adapter
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
    public void onServiceConnected(int profile, BluetoothProfile proxy) {
        if (profile == BluetoothProfile.HEADSET) {
            mBluetoothHeadset = (BluetoothHeadset) proxy;
            Log.d("bt", "connected");
            // mAudioManager.startBluetoothSco();
            Log.d("bt",
                    "devices:"
                            + Integer.toString(mBluetoothHeadset
                                    .getConnectedDevices().size()));
            if (mBluetoothHeadset.startVoiceRecognition(mBluetoothHeadset
                    .getConnectedDevices().get(0))) {
                Log.d("bt", "recognize");
                myRecognizer.startListening(); // this starts google voice recognition;
            } else
                Log.d("bt", "no recognize");
        }
    }

    public void onServiceDisconnected(int profile) {
        if (profile == BluetoothProfile.HEADSET) {
            mBluetoothHeadset = null;
            Log.d("bt", "disconnected");
        }
    }
};

在我的活动中的OnResume中:

mAudioManager = ((AudioManager) getSystemService(AUDIO_SERVICE));
if (mAudioManager.isBluetoothScoAvailableOffCall()) {

    mBluetoothAdapter.getProfileProxy(this, mProfileListener,
            BluetoothProfile.HEADSET);
    Log.d("bt", "true");

} else {
    Log.d("bt", "false");
}

logcat的:

bt true
bt connected
bt devices 1
bt recognize

它仍然使用内置麦克风,而不是BT耳机麦克风。

0 个答案:

没有答案