Android - Voice recognition

房东的猫 提交于 2019-12-06 08:36:04

Not sure about V-R libraries because the Play Store max App size is 50megs and those voice packages are about 15 to 20 megs each so it will impossible to include multiple languages directly into the App.

There may be an online service to use but you need to search the net for that.

What most people use is the inbuilt Android voice recognition Intent. For different languages should be ok for the ones you want as they are included. However i'm not sure if for example in France when you buy a phone or a tablet the default V-R language will be French and not English, therefore the user will need to go into Language settings and Download the French V-R package.

To start V-R in Android you do

    startVoiceRecognitionActivity();

       private void startVoiceRecognitionActivity() {
            Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

            intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());

            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

            intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);

            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");

            startActivityForResult(intent, 1234);
        }

//To get the Voice data back as Text string

   @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            //pull all of the matches
            ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            String topResult = matches.get(0);

}};

The String topResult is the speech in text

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