gpt4 book ai didi

Android 语音转文本示例

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:42:04 25 4
gpt4 key购买 nike

我看过 VoiceRecognition 的 Android 示例,但我并不真正理解它应该做什么或它是如何工作的。在 list 中,没有任何类型的主要 Activity 要运行,因此当我在手机上安装该应用程序时,我无法运行它。

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

最佳答案

我是这样做的:

在onCreate中:

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

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

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

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

关于Android 语音转文本示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11789791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com