Offline Speech Recognition in Android

瘦欲@ 提交于 2019-12-01 23:04:08

问题


I searched a lot on StackOverFlow for this Problem but the Threads are older than 3 years old.

I implemented the Google Voice Recognition which requires a Internet Connection. Searching how i can use the Offline Voice Recognition brought no success.

Is it now available to use the Voice Recognition when you're offline?

My code until yet:

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

King Regards


回答1:


Not with Google.

You have to use another solution like CMU Sphinx. Check here : Android: Speech Recognition without using google server




回答2:


Actually you can use SpeechRecognizer offline.

  • Go to Setting -> “Language and Input”
  • Choose the keyboard from “Keyboard & Input methods” section and enable “Google Voice Typing“
  • Go back to the previous screen “Language & input“, you will see the “Google voice typing” enabled.
  • Tap on “Offline speech recognition“.
  • Download the languages.
  • Now you should be able to use Speech To Text in offline mode.

The problem with this is it is not continuous without using a loop and using a loop with SpeechRecognizer is absolutely annoying due to the constant beeping sound. There are ways around the beeping sound but most of them mute the beeping sound and everything on the same audio stream as it.

Also mentioned in the steps, you also have to download "Google Voice Typing" and a language for it taking up a lot more storage space. Overall you can use SpeechRecognizer offline but it's a major hassle.



来源:https://stackoverflow.com/questions/31562229/offline-speech-recognition-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!