I'm trying to get TTS to run in the background. But, I never get any sound. I have a broadcast receiver which starts a service. I put my TTS code in both of those, but it never speaks. I know the method is being called (I put a breakpoint on it), but it still doesn't work.
Here's my log, but it doesn't seem to contain anything about the TTS service.
10-04 22:45:30.663: WARN/InputManagerService(209): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4423df40
10-04 22:45:37.363: INFO/PollingManager(449): calculateShortestInterval(): shortest interval is 540000
10-04 22:45:37.413: INFO/TLSStateManager(449): org.apache.harmony.nio.internal.SocketChannelImpl@4400ece0: Wrote out 29 bytes of data with 0 bytes remaining.
10-04 22:45:38.043: ERROR/IMAPEmailService(480): Can't create default IMAP system folder Trash. Please reconfigure the folder names.
10-04 22:45:40.123: ERROR/EONS(303): EF_PNN: No short Name
10-04 22:45:41.543: ERROR/WMSTS(171): Month is invalid: 0
10-04 22:45:42.043: WARN/AudioFlinger(172): write blocked for 212 msecs, 24 delayed writes, thread 0xb998
Thanks everyone in advance!
you can also try this,if the text to be spoken is coming from a broadcast listener.first create a service
then create the listener where you're insert your text
make sure you start the service before you use the tts engine and also check if a tts engine is available
Using Kotlin, the above answers can be re-written as:
Receiver
:Service
:And in the
Manifest
:Android-O onwards using service for things like this has background restrictions. One can use JobIntentService to achieve the same as shown here.
Its working for me (just add on mainfest permision)
Android TTS is a bounded service. Broadcast receiver has a limited context and can't bind himself to any service. However, It can START a service. All the examples shown here are of services that starting the TTS engine and of receiver that starts them. You can also do it with activity but if you don't need UI a service is better. I just think it's a good idea to understand how it works and why is works. Good luck.
It would help to see your TTS code to make it easier for people to help you. Since I already have TTS working in a BroadcastReceiver, here's an example trimmed down from my code.
Start the TTS service at the point in your BroadcastReceiver where you want it to speak:
I hope this helps someone if not the asker (I'm sure he got it working by now).