Android中的离线语音识别

kor*_*nos 3 android voice voice-recognition

我在StackOverFlow上搜索了很多有关此问题的内容,但是这些线程的使用时间已超过3年。

我实现了Google Voice Recognition,需要Internet连接。搜索如何使用我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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

国王的问候

Wil*_*obo 6

不适用于Google。

您必须使用另一种解决方案,例如CMU Sphinx。在这里检查:Android:不使用Google服务器的语音识别


小智 5

实际上,您可以离线使用 SpeechRecognizer。

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

这样做的问题是不使用循环就不是连续的,并且由于持续的哔哔声,使用带有 SpeechRecognizer 的循环绝对令人讨厌。有很多方法可以解决哔哔声,但大多数方法都会使哔哔声以及与它相同的音频流中的所有内容静音。

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