How to Convert Speech to Text in Android?
In this article, speech to text feature is implemented in an application in Android. Speech to text means that anything that the user says is converted into text. This feature has come out to be a very common and useful feature for the users. In various places where search feature is implemented like Google Search also in apps like google keyboard, etc because it gives users a great experience.
Step 1: Add the below code in activity_main.xml. Here an image view for the mic icon and a textview to show the text that is converted from the speech is added.
Step 2: Add the below code in MainActivity.java. Here onClickListener is added with the mic icon so when the user clicks on the icon(image) of mic it is invoked. RecognizerIntent.ACTION_RECOGNIZE_SPEECH is used in the listener that starts an activity that prompts the user for speech and send it through a speech recognizer. The results will be returned via activity results in the onActivityResult() method, when the intent is started using startActivityForResult(). In onActivityResult() method a list of strings is returned and the text is replaced with it in the textview.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.