微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我一直在写一个聊天应用程序,以配合蓝牙耳机/耳机.
到目前为止,我已经能够通过蓝牙耳机和麦克风录制音频文件
我已经能够使用Android设备的内置麦克风,使用RecogniserIntent等进行语音到文本的处理.

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

当前设备:三星galax

Android版本:4.4.2

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

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

为了使用蓝牙麦克风进行识别识别,您首先需要将设备作为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);
}

原文地址:https://www.jb51.cc/android/431205.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐