8

我想实现一个按钮,单击该按钮会激活 android 的语音到文本翻译器,就像 android 的键盘提供的那样。具体来说,我想要一个按钮,让应用程序实时转录用户所说的内容,并在editText框中逐字(实时)记录。这样做的最佳方法是什么?

谢谢

4

3 回答 3

2

如果你还没有检查过你的Voice Recognition样品Api demos,你应该继续检查它。它应该给你一个良好的开端。演示在/android-sdk/samples/...文件夹中可用。如果您还没有安装它们,这里是您如何将 android api 演示应用程序安装到我的手机中的方法。

还有以下(任何其他)教程将帮助您开始:

1)Android语音识别教程

2) Android: Speech To Text 使用 API

以下也可能是一个很好的阅读:

将文本转语音和语音识别添加到您的 Android 应用程序使用 Android 语音识别 API

希望这可以帮助。

于 2013-06-24T03:37:20.650 回答
0
private void startVoiceRecognitionActivity()
{
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
    startActivityForResult(intent, REQUEST_CODE);
}

/**
 * Handle the results from the voice recognition activity.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
    {
        // Populate the wordsList with the String values the recognition engine thought it heard
        ArrayList<String> matches = data.getStringArrayListExtra(
                RecognizerIntent.EXTRA_RESULTS);
        myEditText.setText(matches.get(0));
    }
    super.onActivityResult(requestCode, resultCode, data);
}
于 2019-05-06T12:03:02.167 回答
0

在您的应用程序中,您startActivityForResult()使用ACTION_RECOGNIZE_SPEECH操作调用。这将启动语音识别活动,然后您可以在onActivityResult().

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);
// 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);
        // Do something with spokenText
    }
    super.onActivityResult(requestCode, resultCode, data);
}

更多信息可以在参考资料中找到

于 2017-01-24T11:05:33.537 回答