Android - 语音识别一个词?

标签 android speech-recognition voice-recognition speech

有没有办法让 SpeechRecognizer 收听,等待一个词,然后停止收听?我只需要用户说的第一个词。

最佳答案

你需要使用:

EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS

标记而不是:

SPEECH_INPUT_MINIMUM_LENGTH_MILLIS 标志。

如果我们设置 EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS 标志,则语音识别将在指定的静音时间后终止。所以在你的情况下,用户说出一个词并暂停 100 毫秒,它只会给你这个词。下面是我使用和测试过的代码。根据您的要求编辑静默时间。只需在您的 Activity 中调用此函数进行测试即可。

    public void provideTextToConvert()
{
    Intent speechintent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    speechintent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS , 100);
    speechintent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,  RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    speechintent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    speechintent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));


    try {
        startActivityForResult(speechintent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}

关于Android - 语音识别一个词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29789154/

相关文章:

Android:将蓝牙经典扫描与低功耗扫描分开,或区分经典设备与低功耗设备

android - 从 IIS 7.5 下载 APK 下载失败

python - Python 中的 Azure 认知语音翻译服务的自定义音频输入字节

google-chrome - attr “x-webkit-speech”输入的语言可以不是英语吗?

android - 如何将 AudioRecord 类中已识别的语音保存在文件中?

android - 将 Firebase 数据快照反序列化为 Kotlin 数据类

android - TopAppBar 与 Navigation 集成的脚手架

python - 使用 selenium 将音频从文件传递到 Chrome

audio - 检测录音中的不同说话者

android - 如何覆盖 Android 键盘上的语音输入键?