Jump to content

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


Recommended Posts

  • 4 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

Really, really good app!
Now, my wall-mounted tablet can finally talk to me! It works really well in my own language (Swedish).

But I have a point on my wish list.

 

Can you get a message starting with a "Ding-Dong" or similar sound. Selectable sound or Off (no sound).

Then you should have more time to listen to the message.
Example:
Ding-Dong, (short break), message

Link to post
Share on other sites

Hi, good to hear you like it!

 

Regarding Ding-Dong message, I agree it is a good idea, I have thought about it myself and as I see it there are 3 different use cases that would need to work.

1. Play speech directly via headphone/bluetooth speaker

2, Play speech using callback method to rpi/hc2 etc.

3. Play speech using callback to wifi speaker

 

For the first case, playing the speech in a speaker connected(headphone/bluetooth) to the android device. 

I think it might already work although it is not controlled via configuration parameter instead I earlier added support for playing local media files stored on the device:
http://<device ip>:8080/play=<full path to media file on device>

or
http://<device ip>:8080/play=<full path to media file on device>&vol=<volume level normally 0-15>

So in theory, you store (or choose an existing) a ding-dong file on the device and then before playing your speech you play the ding-dong file.

 

The second and third case can probably be implemented in different ways, I haven't really thought about details, but I will add it to my todo list :=)  

 

 

Link to post
Share on other sites

Please, can anyone help me with this?

I have modified a (borrowed) Telegram-code to send messages via TTS.


When I write something to the global TTS variable, the text will be sent to my Android tablet and read up there.

The message is sent, but only the first word is read, then an error message appears.

 

So, how do I write a code that reads all the words?
I can not find where in my code the error exists.

 

--[[
%% properties
%% globals
TTS
--]]
-- This line is for test purposes only
fibaro:setGlobal("TTS", "Hello World&vol=10")

local debug = true;
local url = "http://192.168.XX.XX:8080/tts="

local function log(str) if debug then fibaro:debug(str); end; end
local function errorlog(str) fibaro:debug("<font color='red'>"..str.."</font>"); end

--Prevents the scene from running again
if (tonumber(fibaro:getGlobalValue("TTS")) == 0) then
  fibaro:abort();
end

local selfhttp = net.HTTPClient({timeout=2000})
local message = fibaro:getGlobalValue("TTS")

log("Message: "..message);
url = url..message

selfhttp:request(url, {
  options={
   headers = selfhttp.controlHeaders,
    data = requestBody,
    method = 'GET',
    timeout = 5000
}, 
  success = function(status)
    local result = json.decode(status.data);
    if result.ok == true then
      log("successful");
    else
      errorlog("failed");
      log(status.data);
    end
  end,
  error = function(error)
    errorlog("ERROR")
    log(error)
  end
})
--Reset the global Telegram variable to 0
fibaro:setGlobal("TTS", "0") 

The ERROR message

Quote

[DEBUG] 15:39:58: Message: Hello World&vol=10
[DEBUG] 15:39:58: [1;31m2017-05-10 15:39:58.426091 [ fatal] LUA error: /usr/share/lua/5.2/json/decode/util.lua:35: unexpected character @ character: 1 0:1 [<] line:
[DEBUG] 15:39:58: <

 

Link to post
Share on other sites

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 ascii format, for example :
fibaro:debug("OrigMsg:" .. message)
encodedmsg = string.gsub(message,'%s','%%20')
fibaro:debug("EncodedMsg" .. encodedmsg )

Since you are swedish you might also want to encode å,ä,ö, you can find correct conversion here :https://www.w3schools.com/tags/ref_urlencode.asp

 

Link to post
Share on other sites

Thanks davanha, I'll try to solve this with your tips.

Edit:

Now it works! Many thanks for your help!

Edited by RH_Dreambox
Link to post
Share on other sites

Hi. I try to play ttsFetch on my lms server but it generate wav file so it can't work.

Is it possible to generate mp3 file.

Link to post
Share on other sites
  • 4 weeks later...

As I see, the App requires manual initialization at Android startup. I have to run it, than select TTS mode.

I have an idea to make TTS speaker with board as RapberryPi or Pine64, with build in small amplifier and speaker, normally not connected to any display, and put it somewhere, bit hidden.

Is it easy way to make the app active at startup of the Android system?

 

I did some tests with Pine64. The app works fine. I was really looking for something like that. So many thanks for this application.

Meanwhile I found at Google Play app Text to speech (TTS): https://play.google.com/store/apps/details?id=com.textsprecher

It also has option to TTS via HTTP, but also requires manual start, and even more steps that this app.

 

Small bug: my Pine64 board is connected to network via LAN. HTTP service works fine, but application does not show IP at it status page, it shows 0.0.0.0:8000 as a hint. So it is not able to read IP from LAN interface. But as I wrote - API works fine.

Edited by Albert
Link to post
Share on other sites

Hi,

Getting the app to auto start after reboot seemed pretty easy, at least for android 5.0 and 7.0.

However on android 6.0 there seem to be some kind of bug related to permissions which cause the app not to autostart (not for me anyway).

What version of android are you running on your Pine64

 

Regarding the displayed ip address, yes there are multiple ways of retrieving the ip address and I just picked one way that seemed to work. I have updated the app but I don't have any device to test this on, so please feel free to test it.

You can download an updated version of the app from:

https://github.com/davandev/AlarmController/releases/tag/v.0.1.573

  

Link to post
Share on other sites

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" -> "Play Speech on device" 

Check "Play intro announcement before speech" and select the audio file to use as announcement message.

 

@Albert

I have added option to restart application after reboot.

In settings choose "Application Settings"

Check "Autostart application after reboot"

 

The settings starts to become a bit gory I know I will try to restructure it somehow.

 

You find the latest build here https://github.com/davandev/AlarmController/releases/tag/v.0.1.587

 

Link to post
Share on other sites
On ‎10‎.‎06‎.‎2017 at 2:13 PM, davanha said:

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" -> "Play Speech on device" 

Check "Play intro announcement before speech" and select the audio file to use as announcement message.

 

@Albert

I have added option to restart application after reboot.

In settings choose "Application Settings"

Check "Autostart application after reboot"

 

The settings starts to become a bit gory I know I will try to restructure it somehow.

 

You find the latest build here https://github.com/davandev/AlarmController/releases/tag/v.0.1.587

 

Hi

 

Thank you very much or updates. Yes, it become very nice and complete TTS app.

 

I tested it at Pine64 with Android 6. They released Android 7, I will have to retest.

For Android 6 service does not start at system startup indeed. I changed permissions of your app, allowing it to change Android system settings. But it does not solve the case. So I will better check it with Android 7.

I see the change in the way you display IP. But it is still wrong. Now it displays IP6, so as hint I see: http://fe80::206:dcff:.  etc

I set intro sound to play - small WAV file taken from Windows sounds. I copied it to Pine64 memory to Music folder, so it is local at the device. And I set it to play it at Settings of your app. Audio is played by external speaker connected to Audio-out (recognized as headphones). Standard output at Pine64 is with video, via HDMI.It works fine just after setting it.

The problem is that after restart and startup of the app, it accepts http commands (confirms HTTP calls, and increments statistic counter on the screen), but no speech via speakers. Speaker works, I can hear system sounds, as keyboard clicks etc. But your app does not play. It start to play after few, sometimes several calls, and than plays stable. I was not able to find the rule. It is also not time-releated. When I waited 1minute from start, it still didn't play. Pine64 is at LAN, so network is stable, internet access also looks stable.

When I switched off Intro playback - I had no such problem anymore. Speech was played always from beginning.

And also small thinks:

- when you select or change intro file to play, "Announcement intro file" option in settings is not updated, shows old value.

- when app works in the background, and you activate it via its icon (as if you start it), it breaks the service, and restart it after selecting TTS green icon in main menu. Maybe it could find running instance and just open it.

 

I see also other problem, but it is Android related, maybe Android 6 at Pine64 only. When system starts with headphones plugged in, it does not switch audio to headphones. Just does not recognize it. I have to unplug and plug again (than it shows headphone icon near the clock at top bar)

Link to post
Share on other sites

Checking and playing with the App, and using it as TTS extension for Fibaro, I got one more idea. Simply, to repeat last message.

I see button "Play Speech" on the screen - for me it does nothink, maybe it is for other mode. I initially thought that it is to play last generated speech. My idea is to have HTTP command to repeat last message. Same as in some GPS maps systems in cars. Fibaro controller can send such request, when user push as button on remote etc. Just when he miss the message.

Of course, HC2 can also buffer last message or last few messages and can simple send it again. This is how I plan to do the VD. And for repeat I will probably add time stamp... yes, via VD it would be more flexible. If I will allow to repeat last three messages, if message is older than let say 5min, it will add at the beginning "Message from XX:YY am/pm: ...". I like the app and all these ideas more and more ;-)

But I wanted to share my the idea here.

---

I did some next tests at Pine64 and Android 7.1. It looks as not stable (Android). But the App starts at startup indeed. And shows proper LAN IP too.

I have some performance issues and other, with your App and other Apps, so I cannot trust that Android version. I also had problems with first commands sent after startup of the device and the system. Sometimes it started to tell all after 2 minutes. So it buffered all inside. Usually it skips also first word. It can be my Android issue, it bad version.

There is also Android TV v7 version available for Pine64. Mayby it will be more stable.

Can you please also check, if is all fine with ping called via http ([IP]:8080/ping). After ping I had problems with playing next speech. As if the app get blocked. Ping (sent as URL from webbrowser) always return ServiceEnabled[flase]. Is that fine, shall it be "false"? 

Edited by Albert
Link to post
Share on other sites

Hi, @Albert

Seems you have been busy testing during the afternoon :=) 

I will try to fix the faults you found (including a workaround for autostart in android 6), just a few comments.

 

- I have also noticed on my devices that it takes some time after android is booted until the app is actually auto-started. Could you after a reboot when the app starts to respond to http requests, but no speech, try to run "http://<ipaddress:8080>/log" then you should get the logfile, maybe it is possible to determine what is the cause of the failure with it.

-  The reason for restarting the app when icon is selected was actually by intention, I had problems that android seem to close the server socket when the battery level decreases under some level even though the app service was suppose to always run, when that happened the socket was not released and would be hanging and required some manual enable/disable things start working again.  

-  The "play speech" button only applies for the case when the app is configured to send a "ttsCompleted" callback. When configured to send a ttsCompleted callback it needs to store the generated speech to be able to return it when the initiator asks for it and this is the only case when the play message button works. When the app is configured to play speech on device it does not store the speech, it simply generates it and plays it immediately. 
I realize that the button is a bit miss leading, I can probably disable the button in case it is configured to play on device only or maybe remove it since the purpose is really only for testing.


I like your idea, a message cache could be useful.

I have also some more ideas, the highest on my wish list is currently to implement support for speech recognition as a service running in background, then I would for example be able to say "status" to the android device and it would then invoke some scene on hc2 to collect house status and then get the status read in speakers. 

 

This home automation is like an addict and I am totally hooked.. I don't dare to think about how many hours I spent on it since I bought my HC2 last year, all other house projects are currently put on hold :=)

Link to post
Share on other sites
  • 1 month later...


Sometimes, ZenitGatekeeper stops reading messages. I can see at the statistics that it receives the message, but does not read it in the speaker.
The only way i found it to get started again is to uninstall the app and then reinstall it.
Is there any easier way to restart the app?

Link to post
Share on other sites
  • 3 weeks later...

ok, next time this happens can you run following in a webbrowser : "http:<ip address>:8080/log" this should give you the apps log file and with it I might be able to determine the cause.

Edited by davanha
Link to post
Share on other sites

Probably my question has nothing to do with zenitgatekeeper but still hope if anyone has the same experience.

I have a bluetooth speaker connected to the tablet, recently it cannot play the complete TTS statement. It skipped around 3 seconds from the beginning, feel like the BT connection is not established fast enough.

 

For example, the original statement is : It is now 3 PM but tablet read as "ow 3 PM"

 

Can it be resolved?

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.

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