How to add Google Speech to Text to your android app

Doing so makes it easy for users to use your app but it is not that easy to implement it in your app. Well, if you try it isn't that hard either. Let me show you how to add Google Speech to text to your app.

      Nowadays, each and every app on the Playstore uses voice search from Google. Well, because it is much easier to just speak and have your app interpret what you say and give appropriate results instead of typing the whole thing and this makes more and more developers to add Google Speech to Text in their android app. Doing so makes it easy for users to use your app but it is not that easy to implement it in your app. Well, if you try it isn't that hard either. Let me show you how to add Google Speech to text to your app.
How to add Google Speech to Text to your android app

How to add Google Speech to Text to your android app

First create a function prompt speech input and call one intents ACTION_RECOGNIZE_SPEECH with 3 input actions viz
EXTRA_LANGUAGE_MODEL
EXTRA_LANGUAGE
EXTRA-PROMPT

[public void promptSpeechInput() {         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,                 getString(R.string.speech_prompt));         try {             startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);         } catch (ActivityNotFoundException a) {             Toast.makeText(getApplicationContext(),                     getString(R.string.speech_not_supported),                     Toast.LENGTH_SHORT).show();         }     } ]
If the code doesn't automatically adjust press CTRL+ALT+L to reformat the code.

Now just start activity for result and get speech output.

[ @Override     protected void onActivityResult(int requestCode, int resultCode, Intent data) {         super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {             case REQ_CODE_SPEECH_INPUT: {                 if (resultCode == RESULT_OK && null != data) {
                    ArrayList<String> result = data                             .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);                     txtSpeechInput.setText(result.get(0));                              }                 break;             }
        }     } ]
Now you get need to declare two variables. A text view named txtSpeechInput to receive the text and one speech req code.

[ TextView txtSpeechInput;     ImageButton speakButton;     final int REQ_CODE_SPEECH_INPUT = 100; ]
You are done. Now just call promptSpeechInput() whenever you want to convert speech to text. It can be on click or by setting onclicklistener to any button.

Hope you liked the post. If you have any thoughts about the post let us know it in comments 

COMMENTS

BLOGGER
Name

Affiliate marketing tutorial,2,Android,60,Android Development,22,Android tutorials,41,Blogging tactics,8,Deals,1,DSA,4,Elite Youtube Tutorial,4,Firebase,1,Flutter,4,Fuchsia,1,Hosting Guides,3,Leetcode,4,Miscellaneous,10,Mobile Gaming,17,NTN,94,Problogging,7,PUBG,16,Reviews,1,SEO Tutorial,5,Start a blog,9,Start a channel,6,Top 5,4,Travel Blogging,4,Windows,12,Windows Security,4,Windows tutorials,7,Wordpress Tutorials,4,Youtube Tutorials,11,
ltr
item
A Passionate Developers Creation: How to add Google Speech to Text to your android app
How to add Google Speech to Text to your android app
Doing so makes it easy for users to use your app but it is not that easy to implement it in your app. Well, if you try it isn't that hard either. Let me show you how to add Google Speech to text to your app.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGT1uCfsuFfIO61V69CP2IoN1uEDUTyFDldoaO_EWg6ITSAz0SFJsWUTDPoTzT7UMCJdqngDuj6hAhJJDOyQbsyBqlmO2L4YeRGWePhAXJPjwHMve1HzGZurc_Zvd35o2cJpY5Pqfw5qk/s1600/ZomboDroid+26092019121236.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGT1uCfsuFfIO61V69CP2IoN1uEDUTyFDldoaO_EWg6ITSAz0SFJsWUTDPoTzT7UMCJdqngDuj6hAhJJDOyQbsyBqlmO2L4YeRGWePhAXJPjwHMve1HzGZurc_Zvd35o2cJpY5Pqfw5qk/s72-c/ZomboDroid+26092019121236.jpg
A Passionate Developers Creation
https://www.apdevc.com/2019/09/how-to-add-google-speech-to-text-to.html
https://www.apdevc.com/
https://www.apdevc.com/
https://www.apdevc.com/2019/09/how-to-add-google-speech-to-text-to.html
true
3690156770086819421
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content