Android Text To Speech Application Tutorial - Part 2
Submitted by donbermoy on Tuesday, January 14, 2014 - 11:35.
In my previous example with my first tutorial, I came up with the image of fading in and out. Now, in this tutorial I will introduce to all of you the power of Basic4Android that convert the text to become a speech.
Before we begin with the code you must need to have three buttons for speech, clear, and exit, and the other one is the EditText(Textbox). You must design your layout like this:
Then the emulator will look like this one:
This is the complete code and I will explain one by one the following syntax:
Note: This code is for initializing TextToSpeech Application.


- Sub Process_Globals
- End Sub
- Sub Globals
- Dim tts As ICOSTextToSpeech
- Dim Button1 As Button
- Dim EditText1 As EditText
- Dim Button2 As Button
- Dim Button3 As Button
- End Sub
- Sub Activity_Create(FirstTime As Boolean)
- Activity.LoadLayout("Main")
- Activity.Title="TextToSpeech - Lyndon Bermoy"
- tts.InitializeTTs("tts", "en")
- End Sub
- Sub Activity_Resume
- End Sub
- Sub Activity_Pause (User Closed As Boolean)
- End Sub
- Sub Button1_Click
- If EditText1.Text = "" Then
- Msgbox ("Please input message to the box","")
- EndIf
- tts.Speaking(EditText1.Text)
- End Sub
- Sub Button3_Click
- ExitApplication
- End Sub
- Sub Button2_Click
- EditText1.Text = ""
- End Sub
Dim tts As ICOSTextToSpeech
- The tts here is our variable for ICOSTextToSpeech in which I created as the library for my text to speech application. It is like importing the important packages in your program.
Syntax like this one tts.InitializeTTs("tts", "en")
is that you initialize tts as "tts" for the title and the "en" here is for the default language "English".
The code for our speak button is named Button1 that if the user will click without entering a string in the EditText it will prompt "Please input message to the box". Otherwise this syntax will follow
tts.Speaking(EditText1.Text)
This syntax is for speaking the text you inputted in EditText1. The word "Speaking" here is the method name to convert text to speech.
Button2 is used to clear our Textbox and Button3 is for exiting the application.
Best regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Mobile Developer
09126450702
[email protected]
Visit my page on Facebook at: https://www.facebook.com/BermzISware
Add new comment
- 72 views