Android语音通过音频而不仅仅是文本来识别提示

时间:2016-09-13 00:01:05

标签: android wear-os voice-recognition voice-interaction

目前我有语音识别工作,但RecognizerIntent.EXTRA_PROMPT仅在移动设备和可穿戴手表上显示为文字。

是否有任何方式或其他选项可以提示发言(播放为音频)?

尝试了VoiceInteraction API,但仅限于选择一个选项,必须从系统语音命令之一开始。

    private static final int SPEECH_REQUEST_CODE = 0;

 // Create an intent that can start the Speech Recognizer activity
    private void displaySpeechRecognizer() {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "How can I help you?");
        // Start the activity, the intent will be populated with the speech text
        startActivityForResult(intent, SPEECH_REQUEST_CODE);
    }

    // This callback is invoked when the Speech Recognizer returns.
    // This is where you process the intent and extract the speech text from the intent.
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
            List<String> results = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            String spokenText = results.get(0);
            Log.d(TAG, "spokenText: " + spokenText);
            // Do something with spokenText
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

2 个答案:

答案 0 :(得分:0)

我认为你正在走上正轨。您必须使用语音交互API进行语音交互,Google语音操作可识别许多语音和键入的操作请求,并为其创建Android意图。

根据语音互动API的视频录制:

  

无论您的应用使用系统语音还是自定义语音actions,有时候应用可能会在执行操作之前询问用户后续问题。例如,在用户说“播放一些音乐”后启动音乐应用程序后,它可能想要询问用户“什么类型?”或者当家庭自动化应用程序听到用户说“OK Google,打开灯”时,它可能想问“哪个房间?”语音交互API让Android M应用程序可以询问这些后续问题。

     

在codelab中,您将学习如何使用Voice Interaction API为您的应用添加语音交互。语音交互API允许您的应用用户确认操作,并仅使用他们的语音从选项列表中进行选择。

注意:

  

Google Voice Interaction API允许活动使用语音与用户进行交互,以获得以下输入:

     
      
  • 确认一个动作(例如,“你确定吗?”)
  •   
  • 从选项列表中选择
  •   

有用的参考资料:

答案 1 :(得分:0)

您首先播放音频how to play audio file in android

当音频结束时,您开始语音识别。

相关问题