【问题标题】:Android Speech Recognizer with Bluetooth Microphone带蓝牙麦克风的 Android 语音识别器
【发布时间】:2016-08-23 01:10:56
【问题描述】:

我一直在编写一个与蓝牙耳机/耳机配合使用的聊天应用程序。 到目前为止,我已经能够通过蓝牙耳机中的麦克风录制音频文件 我已经能够使用 Android 设备的内置麦克风,使用 RecogniserIntent 等实现 Speech-to-text。

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

当前设备:三星 Galax

安卓版本:4.4.2

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

【问题讨论】:

标签: android bluetooth


【解决方案1】:

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

为了让语音识别与蓝牙麦克风一起工作,您首先需要将设备作为蓝牙耳机对象,然后在其上调用 .startVoiceRecognition(),这会将模式设置为语音识别。

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

你得到蓝牙耳机是这样的:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    • 2021-10-03
    • 2013-03-31
    • 2020-09-12
    • 1970-01-01
    相关资源
    最近更新 更多