带有蓝牙麦克风的Android语音识别器 [英] Android Speech Recognizer with Bluetooth Microphone
问题描述
我一直在编写一个聊天应用程序,以与蓝牙耳机/耳机配合使用. 到目前为止,我已经能够通过蓝牙耳机中的麦克风录制音频文件,并且 我已经能够使用RecogniserIntent等在Android设备的内置麦克风上使用语音转文本"功能.
I've been writing a chat app to work with bluetooth headsets/earphones. So far I've been able to record audio files via the mic in a bluetooth headset and I've been able to get Speech-to-text working with the Android device's built in microphone, using RecogniserIntent etc.
但是我找不到让SpeechRecogniser通过蓝牙麦克风收听的方法,甚至有可能这样做,如果可以,怎么办?
But I can't find a way of getting SpeechRecogniser to listen through the Bluetooth mic.Is it even possible to do so, and if so, how?
当前设备:三星Galax
Current Device: Samsung Galax
Android版本:4.4.2
Android Version: 4.4.2
我在平板电脑的语音识别器设置中隐藏了一些选项,其中之一是标有使用蓝牙麦克风"的复选框,但似乎没有作用.
I found some options hidden in my tablets settings for the Speech Recognizer, one of these is a tick box labeled "use bluetooth microphone" but it seems to have no effect.
推荐答案
找到了我自己问题的答案,因此我将其发布给他人使用:
Found the answer to my own question so I'm posting it for others to use:
要获得语音识别以与Bluetooth Mic配合使用,您首先需要将该设备作为BluetoothHeadset对象,然后在其上调用.startVoiceRecognition(),这会将模式设置为语音识别.
In order to get speak recognition to work with a Bluetooth Mic you first need to get the device as a BluetoothHeadset Object and then call .startVoiceRecognition() on it, this will set the mode to Voice recognition.
完成后,您需要调用.stopVoiceRecognition().
Once finished you need to call .stopVoiceRecognition().
您将这样获得BluetoothHeadset:
You get the BluetoothHeadset as such:
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()并发送语音识别意图,如下所示:
Then you get call startVoiceRecognition() and send off your voice recognition intent like so:
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);
}
这篇关于带有蓝牙麦克风的Android语音识别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!