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

这篇博客介绍了如何通过BluetoothHeadset对象在Android中启用语音识别功能。首先获取蓝牙适配器和已配对设备,然后设置蓝牙耳机服务监听器。一旦连接到耳机,调用.startVoiceRecognition()启动语音识别模式,完成后使用.stopVoiceRecognition()停止。接着创建并启动语音识别意图,设置识别监听器来处理识别结果。
摘要由CSDN通过智能技术生成

找到我自己的问题的答案,所以我发布给其他人使用:

为了使用蓝牙麦克风进行识别识别,您首先需要将设备作为BluetoothHeadset对象,然后在其上调用.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()并发送你的语音识别意图,如下所示:

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、付费专栏及课程。

余额充值