Learn to develop an application that converts text into speech in android

1
6043

In this tutorial we will learn how to convert text into speech using Android programming.
Here we are going to develop an application whose layout consists an EditText which will accept the text as input and Image button which will perform some event on the click i.e. whenever you provide the text as input and press on the image button, it will convert the text into speech.

  • To convert text into speech follow the steps given below :

  1. First of all download the ADT- Bundle from developer.android.com and extract it .
  2. For downloading and installation of eclipse you can follow the following link Installing Android SDK
  3. Now open up eclipse and click on File -> create new Android Application Projects
  4. text to speech

  5. Provide a project name for example ” TextSpeech ” and set the Minimum Required and Target SDK for the project as ” 19 “.
  6. Click on Next and select Blank from the appeared dialog box
  7. Now Click on Next and it will show you the dialog box which contains your java file i.e MainActivity and xml layout name : activity_main
  8. Click on Finish and your MainActivity.java and activity_main.xml files will be generated.
  9. Now just move to activity_main.xml file i.e in its Graphical Layout and drag and drop TextView on the layout as shown in the image and for example set the text as Text To Speech
  10. layout

  11. Similarly drag an Plain text i.e an EditText and Image button .
  12. Hence, your layout will look like as shown below :
  13. layout final

  14. Now go to the activity_main.xml file the tab besides the graphical layout and change the id’s of the EditText, TextView, ImageButton, etc for simplicity of understanding.
  15. Hence the complete code for your activity_main.xml file is given below :
  16. Here is the ImageView of the above code :
  17. speech
    text

  18. Now just move to MainActivity.java file and extend your class with Activity implements TextToSpeech.OnInitListener
  19. Hence, the complete code is given below which is self explanatory :
  20. Here is the image view of the above code :
  21. text to speech
    convert text to speech
    text
    speech application

  22. Now run your project and you will get your application running on the emulator as shown below :
  23. emulator

  24. Just type some text in the given EditText and click on the ImageButton i.e. image of a Boy in this example.
  25. hello

  26. Click on the image button and it will transform your text into speech.

Hence, we have successfully learnt to develop an application that converts text into speech in android.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here