简体   繁体   中英

Offline Speech Recognition in Android

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

Not with Google.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM