Jump to content

Using an android device as a text-to-speech engine

Recommended Posts


I have been working for a while to get an android device working as a text-to-speech engine and to generate speech from text that I can play in any speaker at home, and now I have finally got it working! 
Android has a pretty good tts engine and you can even configure custom voices that creates speech on languages not yet supported by android itself. 

The scenario is the following: HC2 or some other device wants a text translated to speech, it sends an http request including the text towards the android device, on the android device there is a http server started that receives the request and generates the synthesized speech using androids builtin TextToSpeech api, the android device can then either immediately play the speech in the device and/or store the synthesized content in a file. After successfully generated the speech file the android device sends a request to a configurable "callback url" to notify that the generated .wav file can now be downloaded.

I realized during the work, that there are more scenarios than I from the beginning thought of, but the setup I was looking at was the following:


However it is not really needed to convert and cache the file, you could also just notify your wifi speaker to play it.


A third solution would be to let the android device itself play the speech, either through its internal speaker or via a speaker connected to headphone jacket.


Ok so that was the idea and description of different use cases, if you want to try this out you need:

  1. Download and install the app on a android device

      2. Start the app in Text-to-speech mode
      3. Initial configuration  

      4. Test it 
      5. Create a scene/vd that sends tts requests.
      6. Create a scene/vd that is invoked when tts speech is completed.
      7. Download the speech file or tell your speaker system to download and play it.

Download and install the app on a android device
The app can be downloaded from here (app-debug.apk), you need to allow installation from unknown sources in android this is normally configured through "Android Settings" --> "Security" --> "Unknown Sources"

I have tested the app on devices running android 5.0 and 6.0, earlier I also tested it on 4.4 but my samsung s2 finally seemed to give up so I dont know the current status on 4.4.
The app needs "Storage" permissions to store the wav file on device.

You can find and set the needed permission that by
Android Settings --> apps -->  --> permissions --> ZenitGatekeeper


Short background around the app, I wrote the app originally with another thought in mind and that was to make it easy for the rest of the family to arm/disarm the home alarm (I am currently using the fibaro system as my security system at home), so it is wall mounted in the entrance and works like a keypad where you can arm the alarm or enter a pin to disarm the alarm. Since the device is always on and always connected to wifi I thought I would try to re-use the app also for generating text-to-speech. 


The app will start a web server and wait for requests, it currently supports a few different types of requests,
- /ping : will just respond with 200 ok
- /wakeup : will turn on the device screen (I use a fibaro motion sensor that triggers this event)
- /tts=msg : will generate a tts file based on the provided message.
- /ttsFetch : will return the latest generated speech file.
- /log : returns the application logfile


At successful text-to-speech generation the app will invoke an configured url to notify that the .wav file is ready. 

Start the app in Text-to-speech mode

Start the app and push the text-to-speech button to start text-to-speech mode. As described above, the app was originally written to be used as a keypad, but I have added a "TTS mode" which only starts the app to be used as a TTS engine.


Initial configuration
The app needs some basic configuration to work properly, following configuration describes what is needed to get text-to-speech mode to work. 
Click "Settings" button (default password to settings menu is "1234")  -> Application Settings -> Http services -> 
* "Enable http services" : will start the http server that listens on port 8080.
* "Enable Text-To-Speech service" : will enable the text-to-speech function
* "Play speech in device" : will play the speech in the device speakers if enabled.
* "Text-To-Speech callback URL" : an callback url used to notify the requester that the speech is completed and can be downloaded. 


Push back button until you get to the TTS mode main page again, now it should look something like this and you should be ready to test it out:


Test it

To start with you could just open a webbrowser and type 
http://<ipadress to android device>:8080/tts=hey%20it%20works
If it works out properly your android device should now play the speech and you should also receive a callback to your configured callback url.

Next step would be to invoke it from your scenes/vd but I guess that is up to you decide how to do.


For the interested reader source is available at https://github.com/davandev/AlarmController

New releases of the app will be available at https://github.com/davandev/AlarmController/releases


Let me know if you run into problems.



Edited by davanha
Added link to sourcecode
  • Like 1
  • Thanks 1
Link to post
Share on other sites
  • 2 weeks later...
  • Replies 67
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Hi, I have been working for a while to get an android device working as a text-to-speech engine and to generate speech from text that I can play in any speaker at home, and now I have finally got

Hi,   @RH_Dreambox I have added an option to play a announcement message ("ding-dong") before the speech is played, In settings choose "Application Settings" -> "Http services" ->

Without looking into details of your code I would think your problem is the whitespace in the message it needs to be html encoded. You can use string.gsub to replace the whitespace with a valid asci

Posted Images

Nice to hear you got it working.

I guess there are different ways to call it from hc2, but a global variable that is updated with your text-to-speech message and then a scene that is automatically triggered when the global variable is changed and that sends the /tts= request would probably work.

Let me know if you need help.

Link to post
Share on other sites


Yes it is,but you have to install a tts-engine that supports your language, there are several different available from google play (some cost money though) 

I use Acapela tts-engine (it support my native language swedish). For the acapela tts-engine, they also provide a demo service on http://www.acapela-group.com where you can try out different voices and languages in a webbrowser 



Link to post
Share on other sites

It's strange because I have Polish TTS Ivona and built in Google with Polish voice and it works good, but when I send TTS command http://<ipadress to android device>:8080/tts=witaj I get english voice.

Do you have any idea?

Link to post
Share on other sites

well not really but I once noticed that I once had to explicitly select my acapela tts-engine in android settings (even though it was already selected) to make it take effect.

In android settings --> Languages and input --> Text-to-speech --> click on the selected tts-engine.

By the way which is the android system language you are using?

Link to post
Share on other sites

It's strange, beacuse I try this on two devices LG G5 and Teclast Air IV. On both I have the same problem.

I have Polish android language and all language are polish. In Text to speech the default language is Polish;)

Link to post
Share on other sites

Is it possible for me to download the same tts engine (Polish TTS Ivona) you use somewhere?

Then I could try it out and see if there is a bug hiding somewhere.

Link to post
Share on other sites

You can install this:


and voice



Did you try with built in TTS (Andoird TTS)?

I install your TTS aplication and after 2 restarts it starts saying in polish but ivona has the best polish voice. Also built in TTS in Android has quite good TTS.


Link to post
Share on other sites

I noticed when looking through the code that I had one line which looked suspicious...




this line didn't seem to make any difference when using Acapela engine but it seem to always choose english when using the builtin tts-engine.

After removing this line it seems to work better. 

I have built a new version (0.1.444) of the app, try it and see if it works better.


Regarding builtin tts, yes I have tried it but I didn't like the swedish female voice.





Edited by davanha
New build...
Link to post
Share on other sites



Would you add one parameter more for sentence -> http://ip_dev_android:8080/tts=text&vol=10

where vol = < 1,2,.....10> - level volume of media for tts

Link to post
Share on other sites

sure I can try to add that, just to be clear about the use case, you want to be able to control the media volume when playing the speech on the device right?, and you would like to have different volumes for different messages so using the physical volume buttons on the device is not an option.

Link to post
Share on other sites



I want to be able to control the media volume when playing the speech on the device. Early morning and late evening quietly. During the day loud. :-D

Do you write scripts with BeanShell Commands ?

Edited by Jacek Stark
Link to post
Share on other sites

@Jacek Stark

New version(0.1.453) with support for controlling the volume of the speech, test it and see if meets your expectations :-)

Implemented as you suggested so to change the volume use following :

http://ip_dev_android:8080/tts=text&vol=<volume level>


It seems like many android devices have 15 different volume levels (0-15) so for simplicity reasons I just pass the value through.

I added a debug print during startup of the app that prints the device max volume level in case you want to check.


There is one not so good thing and that is that the volume level is not restored to the original value after playing the speech, so it will remember the last set volume level. I will try to fix it but that will require some more work. 


Link to post
Share on other sites


Thank You very much for your work. That the volume level is not restored to the original value after playing the speech for me is not a problem. My android  is dedicated device for it  -  tts. I will try to use your aplication for arm/disarm my alarm system at home. 


It work very well ! Thanks.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...