蓝牙麦克风 android,带有蓝牙麦克风的Android语音识别器

我一直在编写一个聊天应用程序,以与蓝牙耳机/耳机配合使用。

到目前为止,我已经能够通过蓝牙耳机中的麦克风录制音频文件,并且

我已经能够使用RecogniserIntent等与Android设备的内置麦克风一起使用语音转文本功能。

但是我找不到让SpeechRecogniser通过蓝牙麦克风收听的方法,甚至可以这样做,如果可以的话,怎么办呢?

当前设备:三星Galax

安卓版本:4.4.2

编辑:我发现我的平板电脑设置中隐藏了一些语音识别器选项,其中之一是一个标记为“使用蓝牙麦克风”的复选框,但似乎没有作用。

最佳答案

找到了我自己问题的答案,因此我将其发布给他人使用:

为了获得语音识别以与Bluetooth Mic一起使用,您首先需要将设备作为BluetoothHeadset Object获取,然后在其上调用.startVoiceRecognition(),这会将模式设置为语音识别。

完成后,您需要调用.stopVoiceRecognition()。

您可以这样获得BluetoothHeadset:private void SetupBluetooth()

{

btAdapter = BluetoothAdapter.getDefaultAdapter();

pairedDevices = btAdapter.getBondedDevices();

BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {

public void onServiceConnected(int profile, BluetoothProfile proxy)

{

if (profile == BluetoothProfile.HEADSET)

{

btHeadset = (BluetoothHeadset) proxy;

}

}

public void onServiceDisconnected(int profile)

{

if (profile == BluetoothProfile.HEADSET) {

btHeadset = null;

}

}

};

btAdapter.getProfileProxy(SpeechActivity.this, mProfileListener, BluetoothProfile.HEADSET);

}

然后,您将调用startVoiceRecognition()并发送语音识别 Intent ,如下所示:

private void startVoice()

{

if(btAdapter.isEnabled())

{

for (BluetoothDevice tryDevice : pairedDevices)

{

//This loop tries to start VoiceRecognition mode on every paired device until it finds one that works(which will be the currently in use bluetooth headset)

if (btHeadset.startVoiceRecognition(tryDevice))

{

break;

}

}

}

recogIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

recogIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

recog = SpeechRecognizer.createSpeechRecognizer(SpeechActivity.this);

recog.setRecognitionListener(new RecognitionListener()

{

.........

});

recog.startListening(recogIntent);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值