Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


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


davanha

Recommended 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 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. 
 

Description
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:

Please login or register to see this attachment.

 

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

Please login or register to see this image.

/monthly_2017_03/hc2_fibaro_speaker_seq_dia.png.ba5bc0b86d93d088e3e68d781e5dab2a.png" />

 

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.
hc2_android.png.ee9f39a70fc8d703018d4bbd2ae19f7a.png

 

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 (

Please login or register to see this attachment.

), 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:

Please login or register to see this attachment.

 

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 

Please login or register to see this link.

New releases of the app will be available at 

Please login or register to see this link.

 

Let me know if you run into problems.

Cheers

 

Edited by davanha
Added link to sourcecode
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
  • Topic Author
  • 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 comment
    Share on other sites

    Great job:)

    Is it possible to change the voice from english to another language?

    Link to comment
    Share on other sites

  • Topic Author
  • Hi,

    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 

    Please login or register to see this link.

     where you can try out different voices and languages in a webbrowser 

     

     

    Link to comment
    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 comment
    Share on other sites

  • Topic Author
  • 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 comment
    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 comment
    Share on other sites

  • Topic Author
  • 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 comment
    Share on other sites

    You can install this:

    Please login or register to see this link.

    and voice

    Please login or register to see this link.

     

    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 comment
    Share on other sites

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

    ..

    Please login or register to see this code.

     ..

    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.

     

     

     

    Please login or register to see this attachment.

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

    @davanha

     

    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 comment
    Share on other sites

  • Topic Author
  • 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 comment
    Share on other sites

    @davanha

     

    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 comment
    Share on other sites

  • Topic Author
  • @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. 

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    @davanha

    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. 

    @davanha

    It work very well ! Thanks.

    Link to comment
    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.

    Guest
    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...