0

Currently I have working speech recognition but RecognizerIntent.EXTRA_PROMPT is shown as text only on mobile as well as on wearable watch.

Is there any way or other option to make prompt to speak (play as audio)?

Have tried VoiceInteraction API but it is limited to picking an option and have to start through one of the system voice command.

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

2 回答 2

0

我认为你正在走上正轨。您必须使用 Voice Interaction API 才能进行语音交互,Google Voice Actions 可以识别许多口头和键入的动作请求,并为它们创建 Android 意图。

根据语音交互API的录像:

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

在代码实验室中,您将学习如何使用语音交互 API 将语音交互添加到您的应用程序中。语音交互 API 允许您的应用程序的用户仅使用他们的语音来确认操作并从选项列表中进行选择。

笔记:

Google Voice Interaction API 允许 Activity 使用语音与用户交互以获取以下输入:

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

有用的参考资料:

于 2016-09-13T15:17:16.850 回答
0

你首先播放音频如何在android中播放音频文件

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

于 2016-09-14T20:36:30.110 回答