Offline Speech Recognition in Android
Asked Answered
K

2

7

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

Knighton answered 22/7, 2015 at 11:47 Comment(0)
I
6

Not with Google.

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

Indirection answered 22/7, 2015 at 11:58 Comment(3)
Thanks for your informations! Could it be that sourceforge is offline?Knighton
The website side, it seems. sourceforge.net/projects/cmusphinx/?source=directoryIndirection
This library is not accurate :(Adlare
W
6

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.

Weisman answered 18/5, 2018 at 16:50 Comment(1)
Is there an easy way to check if an offline engine is available. I know there's the RecognizerIntent.EXTRA_PREFER_OFFLINE option to only use a offline speech recognition engine but I want to fall back to online if it's not available. It doesn't seem to fallback even though the naming implies itLipscomb

© 2022 - 2024 — McMap. All rights reserved.