【问题标题】:Offline Speech Recognition in AndroidAndroid 中的离线语音识别
【发布时间】:2023-09-14 15:03:01
【问题描述】:

我在 * 上搜索了很多有关此问题的信息,但线程已超过 3 年。

我实现了需要 Internet 连接的 Google Voice Recognition。搜索我如何使用Offline Voice Recognition 没有成功。

现在可以在离线时使用Voice Recognition 吗?

到目前为止我的代码:

speechStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            promtSpeechInput();
        }
    });

private void promtSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            "Recording...");
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(getApplicationContext(), "Language not supported", Toast.LENGTH_SHORT).show();
    }
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case CAMERA_PIC_REQUEST: {
            try {
                Bitmap image = (Bitmap) data.getExtras().get("data");
                ImageView imageView = (ImageView) findViewById(R.id.taskPhotoImage);
                imageView.setImageBitmap(image);

            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }
        case REQ_CODE_SPEECH_INPUT: {
         if(resultCode == RESULT_OK && null != data) {
             ArrayList<String> result = data
                     .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
             speechToTextField.setText(speechToTextField.getText()+" " +result.get(0));
         }
            break;
        }
    }
}

国王的问候

【问题讨论】:

    标签: android voice-recognition voice


    【解决方案1】:

    谷歌没有。

    您必须使用其他解决方案,例如 CMU Sphinx。 在这里查看:Android: Speech Recognition without using google server

    【讨论】:

    • 感谢您的信息!难道是sourceforge下线了?
    • 网站方面,似乎。 sourceforge.net/projects/cmusphinx/?source=directory
    • 这个库不准确:(
    【解决方案2】:

    其实你可以离线使用 SpeechRecognizer。

    • 进入设置 -> “语言和输入法”
    • 从“键盘和输入法”部分选择键盘并启用“Google 语音输入”
    • 返回上一个屏幕“语言和输入”,您将看到“谷歌语音输入”已启用。
    • 点击“离线语音识别”。
    • 下载语言。
    • 现在您应该可以在离线模式下使用 Speech To Text。

    问题在于,如果不使用循环,它是不连续的,并且由于不断发出哔哔声,使用带有 SpeechRecognizer 的循环绝对令人讨厌。有很多方法可以绕过哔声,但其中大多数都会使哔声和所有在同一音频流上的东西静音。

    在步骤中也提到,您还必须下载“Google Voice Typing”和一种语言,因为它会占用更多的存储空间。总的来说,您可以离线使用 SpeechRecognizer,但这很麻烦。

    【讨论】:

    • 有没有简单的方法来检查离线引擎是否可用。我知道有 RecognizerIntent.EXTRA_PREFER_OFFLINE 选项只能使用离线语音识别引擎,但如果它不可用,我想回退到在线。即使命名暗示它,它似乎也不会回退
    最近更新 更多