#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Dim TTS2 As TTS
Dim four As Long
End Sub
Sub Service_Create
Log("service created")
If TTS2.IsInitialized = False Then
TTS2.Initialize("TTS2")
End If
TTS2.SetLanguage("en","")
DateTime.TimeFormat = "HH"
Dim s As Int
s = DateTime.Time(DateTime.now)
ToastMessageShow(s,False)
DateTime.TimeFormat = "mm"
Dim s2 As Int
s2 = DateTime.Time(DateTime.now)
Dim now As Long = DateTime.now
four = DateUtils.SetDateAndTime(DateTime.GetYear(now), DateTime.GetMonth(now), _
DateTime.GetDayOfMonth(now),s, s2+2, 0)
If four < now Then
'skip to tomorrow
Dim p As Period
p.Days = 1
four = DateUtils.AddPeriod(four, p)
End If
Log(DateUtils.TicksToString(four))
End Sub
Sub Service_Start (StartingIntent As Intent)
Log("service started")
StartServiceAt("",four,True)
End Sub
Sub Service_Destroy
Log("service destroyed")
TTS2.Release
End Sub
Sub TTS2_Ready (Success As Boolean)
If Success Then
Log("TTS ready!")
DateTime.TimeFormat = "HH:mm"
Dim DateNow, TimeNow As String
DateNow= DateTime.Date(DateTime.Now)
TimeNow = DateTime.Time(DateTime.Now)
Log("Today is " & DateNow & " The time is " & TimeNow)
TTS2.Speak("Today is " & DateNow & " The time is " & TimeNow, True)
Log("spoken")
Else
Log("Error initializing TTS engine.")
End If
End Sub
** Service (notifyuser) Create **
service created
04/13/2015 38
** Service (notifyuser) Start **
service started
TTS ready!
Today is 04/13/2015 The time is 20:36
spoken
** Service (notifyuser) Start **
service started
** Service (notifyuser) Start **
service started
** Service (notifyuser) Start **
service started
** Service (notifyuser) Start **
service started
** Service (notifyuser) Start **
Quickly because I have to prepare diner for the children :Here's the service module code
Thank you for replying!Quickly because I have to prepare diner for the children :
1/ have you checked you have the TTS data installed on the mobile
2/ have you checked the volume (I don't recall if it is the notification or the music channel)
Will come back to the thread a little later![]()
TTS2.SetLanguage("en","")
TTS2.SetLanguage("en","EN")
Something hurt me :
B4X:TTS2.SetLanguage("en","")
I would put instead
I will test your code laterB4X:TTS2.SetLanguage("en","EN")
#Region Service Attributes
#StartAtBoot: False
#StartCommandReturnValue: android.app.Service.START_STICKY
#End Region
Strange thing is that, if I run the example from the forum on which the zip file I sent you is based, TTS speaks from the activity but remains silent in the service.Hum... That message came from line 52 of the "ttsservice" service (sub "Say" of the service).
This means that the TTS engine was successfully initialized but something else was in error.
Please can you try restarting the phone or check if the specified language is installed ?
I too use TTS in both my Star trek and Tix Clock widgets. There are no issues whatsoever with TTS in a Service.
I've just tested the code in the zip file @padvou and all appears to be working correctly. I can switch the language from en to de and I can hear a different language too. Are you sure that your phones TTS is working correctly as that zip file works perfect for me on my N5 and S4 phones...
Add the following to your long running service.
B4X:#Region Service Attributes #StartAtBoot: False #StartCommandReturnValue: android.app.Service.START_STICKY #End Region
You app also appears to be speaking by itself every few minutes. I've added START_STICKY to your service so now I'll leave it running all night just to see what happens...