简体   繁体   中英

Android offline speech recognition programmatically

I want to use speech recognition in my application. Starting from android jellybean I know the android systems supports offline speech recognition (dictation?) !

So far I am only able to use offline recognition with the inbuilt keyboard to type something ie press the microphone button on the keyboard and then speak,but this is of limited use because the user needs to press the button each time and it needs a text field

I want to be able to use the speech recognition to start listening when the program desires it, and call some call back functions when recognition is complete. It is indeed possible with google's online speech recognition but I want to do it using the offline recognition of jellybean.

I've heard of third party options like pocket sphinx but I want to stick to the inbuilt recognizer as it is very efficient and accurate according to my experience

is it possible? if yes then how?

I am not sure this will answer your question, but in my experience, in order to use the speech recognition library you should download the language packages in your device.

See this site with an interesting tutorial and how to download the language packs

For example, my device is in Catalan (there are no Catalan packs to download) but I can force the library to recognize another language, for example Spanish.

private final static String FORCED_VOICE_LANGUAGE = "es-ES";

[...]

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, FORCED_VOICE_LANGUAGE);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.speech_prompt));

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