Android Tutorial Android Text To Speech example

Status
Not open for further replies.

pmsmc

Member
Licensed User
Longtime User
Thanks Erel, going to try that,
and what about the TTS error, after I use VR ?
 

pmsmc

Member
Licensed User
Longtime User
I get this error
java.lang.RuntimeException: Method: IsSpeaking not found in: android.speech.tts.TextToSpeech
 

Humberto

Active Member
Licensed User
Longtime User
I´m using the TTS library in my program but it lock the software for about 3 seconds until is ready.
I don´t need it to run the program just in some cases that the user press to listen a contact name.
I tried to load the library in a thread but still lock the program for 3 seconds.
There is any other way to load in background ?

<code>
If TTS1.IsInitialized = False Then
Dim args(0) As Object
Thread_TTS.Initialise("Thread_TTS")
Thread_TTS.Name = "Thread TTS"
Thread_TTS.Priority = Thread_TTS.MinPriority
Thread_TTS.Start(Me, "threadSub_1", args) 'o nome da thread tem que ter undescore
End If

Sub threadSub_1
If TTS1.IsInitialized = False Then
TTS1.Initialize("TTS1")
End If
end sub
</code>
 

Humberto

Active Member
Licensed User
Longtime User
I build a list with received calls and without loading the library just after the program starts I can scroll the list, but when I initialize the library the scroll starts after 3 seconds
 

Humberto

Active Member
Licensed User
Longtime User
Erel
I put the software in "Share your creation" and you can download from Play Store.
Now, for default, it is disabled the option to talk the contact and receveid calls but you can enable in configuration favorites sound and Register Sound.
You will be able to see the difference between load the library and not.
Ypu must change the language
 

Humberto

Active Member
Licensed User
Longtime User
I wrote I project that build a list view with the calls received and if I load the TTS library still take more than 3 seconds to be able to scroll the list.
If I don´t load the library the scroll start instantly.

The english library took more time than portuguese library
 

Attachments

  • Teste_TTS.zip
    494.3 KB · Views: 416

Humberto

Active Member
Licensed User
Longtime User
Erel

there was some library that I didn´t used.

Now need just one library from outside please send your e-mail to send it . I already have the permission to send to you
 

Attachments

  • Teste_TTS.zip
    432.2 KB · Views: 394

Humberto

Active Member
Licensed User
Longtime User
Ok
Now just build a listview.
If I try to initialize a TTS I can not scroll the list just after start.
 

Attachments

  • Teste_TTS.zip
    241.7 KB · Views: 355

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is a mistake to set the language before TTS is initialized.

Test with this code:
B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim listView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Main")
  listView1.Initialize("ListView1")
  For i = 1 To 300
  listView1.AddSingleLine("Item #" & i)
  Next
  Activity.AddView(listView1, 0, 0, 100%x, 100%y)
End Sub

Sub Activity_Resume
   If TTS1.IsInitialized = False Then
     TTS1.Initialize("TTS1")
   End If
End Sub

Sub TTS1_Ready (Success As Boolean)
   Log("ready")
   If Success  Then
'     TTS1.SpeechRate = 1
'     TTS1.Pitch = 2
     If TTS1.SetLanguage("en" , "") = False Then  'en.fr,de
       ToastMessageShow( "TTS library not found", True)
       Return
     End If
'para falar
'     TTS1.Speak(EditText1.Text, True)
   Else
     Msgbox("Error initializing TTS engine.", "")
   End If
End Sub

I wasn't able to reproduce it as it takes a few milliseconds for the Ready event to be raised.
 

Humberto

Active Member
Licensed User
Longtime User
I tested, but still the same problem.

I put another LOG after the language setup and we can see that takes 4 to 5 seconds ( samsung galaxy S3 ) to do the setup and during that time the activity is locked


B4X:
Sub TTS1_Ready (Success As Boolean)
   DateTime.DateFormat = "yyyyMMdd HH:mm:ss"
   Log("ready: " &  DateTime.Date(DateTime.Now))
   If Success  Then
'     TTS1.SpeechRate = 1
'     TTS1.Pitch = 2
     If TTS1.SetLanguage("en" , "") = False Then  'en.fr,de
       ToastMessageShow( "TTS library not found", True)
       Return
     End If
    Log("setlanguage: " &  DateTime.Date(DateTime.Now))

   Else
     Msgbox("Error initializing TTS engine.", "")
   End If

End Sub

There is anything to do ?
 

Humberto

Active Member
Licensed User
Longtime User
I Tested in LG -II dual chip ( android 4.12 same as Galaxy S3). if "IsFirst = True" takes almost 5 seconds between the messages, but if I call again and IsFirst = False then there is no difference between the messages.

In Galaxy S3 always takes 3 seconds between the messages ( "ready" and "setlanguage" Logs)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…