Android语音到文本转换: Android Application is receiving repeated words when spoken through Voice input using Android Virtual keyboard

标签 android speech-to-text

示例应用程序(步骤):

  1. 没有 EditText 控件的 Android 应用程序。
  2. 应用程序有一个包含 TextView 的 Activity 。
  3. 在Activity的onCreate()方法中,带上Virtual 应用程序时的键盘即 SoftKeyBoard 推出。
  4. 按下虚拟键盘的麦克风(语音输入)按钮。
  5. 说“你好吗”。

语音输入的结果:
Android 应用程序在三个迭代中接收上述口语,例如,
“如何”
"is"
“你好吗”

这是不正确的。如果您看到了,“如何”"is" 这两个词在第三次迭代中重复出现。

预期结果:
应用程序应该像这样在三个迭代中接收口语
“如何”
"is"
“你”

这是示例应用程序代码:

公共(public)类 TestSpeechToText 扩展 Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_url);
    /* Default display keyboard */
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_test_url, menu);
    return true;
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    return true;
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    return true;
}

@Override
public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) {
    String text = event.getCharacters();
    Log.d("Testing", "Text is " + event.toString());
    return true;
}

在这种情况下,覆盖的方法 onKeyMultiple() 被调用了三次,文本为 “怎么样”、"is"和“你好吗”

注意:
1.没有EditText控件
2.xml布局只包含一个TextView

有人知道这个问题吗?如果是,如何解决?

最佳答案

如果没有 EditText,我会自己执行 Intent 调用,而不是通过 SoftKeyboard。然后你会得到一个包含所有可识别单词的数组。纯粹而简单。

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

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);
        // Manipulate your data or do whatever you like with the result
    }
}

关于Android语音到文本转换: Android Application is receiving repeated words when spoken through Voice input using Android Virtual keyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13117764/

相关文章:

android - 自定义圆形按钮

java - 使用aapt2手动生成R.JAVA文件

c# - WP8 中的 SpeechRecognizerUI 导致高崩溃次数?

audio - Google Cloud Speech:单词开始时间

Java - 获取字符串的第一个字母

android - 使用带有枕头的 buildozer 构建 apk : _imaging issue

android - 奥利奥地理围栏,打瞌睡模式

android - 如何在Gradle最新版本4.1中将本地库添加到产品 flavor

python - 用于语音识别的流输入

python - 导入错误: cannot import name 'enums'