Android 语音转文本示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11789791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:52:45  来源:igfitidea点击:

Android Speech to Text Example

androidspeech-to-text

提问by Palagerini

I've looked at the Android example for VoiceRecognition, but I don't really understand what it is suppose to do or how it works. In the manifest there isn't any sort of main activity to run and so when I install the app on my phone I can't run it.

我已经查看了 VoiceRecognition 的 Android 示例,但我真的不明白它应该做什么或它是如何工作的。在清单中没有任何类型的主要活动要运行,因此当我在手机上安装应用程序时,我无法运行它。

I'm also trying to find a simple example of Speech to text that takes speech as input and outputs the text on the screen. Just so I can study it to see how it works, but I haven't been able to find any sort of example on the web that shows it.

我还试图找到一个简单的 Speech to text 示例,它将语音作为输入并在屏幕上输出文本。只是为了我可以研究它以了解它是如何工作的,但是我无法在网上找到任何显示它的示例。

回答by Cdr. Powell

I did it like that:

我是这样做的:

in onCreate:

在 onCreate 中:

List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);

In the method starting the voice recognition:

在启动语音识别的方法中:

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

onActivityResult:

活动结果:

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

Hope I'm not missing anything, been a time since. Drop me a note if something doesn't work. About the text output: I'm sure you can handle that once you have a populated matches array.

希望我没有错过任何东西,已经有一段时间了。如果有什么不起作用,请给我留言。关于文本输出:我相信一旦你有了一个填充的匹配数组,你就可以处理它。