Android Text To Speech Application Tutorial - Part 2

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: TextToSpeechDesign1 Then the emulator will look like this one: emulator design This is the complete code and I will explain one by one the following syntax:
  1. Sub Process_Globals
  2. End Sub
  3.  
  4. Sub Globals
  5.          Dim tts As ICOSTextToSpeech
  6.          Dim Button1 As Button
  7.          Dim EditText1 As EditText
  8.          Dim Button2 As Button
  9.          Dim Button3 As Button
  10. End Sub
  11.  
  12. Sub Activity_Create(FirstTime As Boolean)
  13.          Activity.LoadLayout("Main")
  14.          Activity.Title="TextToSpeech - Lyndon Bermoy" 
  15.          tts.InitializeTTs("tts", "en")
  16. End Sub
  17. Sub Activity_Resume
  18. End Sub
  19.  
  20. Sub Activity_Pause (User Closed As Boolean)
  21. End Sub
  22.  
  23. Sub Button1_Click
  24.          If EditText1.Text = "" Then
  25.          Msgbox ("Please input message to the box","")
  26.          EndIf
  27.          tts.Speaking(EditText1.Text)
  28. End Sub
  29. Sub Button3_Click
  30.          ExitApplication
  31. End Sub
  32. Sub Button2_Click
  33.         EditText1.Text = ""
  34. End Sub
Note: This code is for initializing TextToSpeech Application.  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