Jump to content

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

Recommended Posts

I have the OnePlus 6.
And I can go to Battery optimization to prevent not going into sleep.

Problem is I often close apps in my android device (recent apps that are open in device)

When doing this the tts app closes also, and nothing will work. 


Link to post
Share on other sites
  • 6 months 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

The line looks OK,  but the error is very weird... it points to line #1 ???  Why do you think that the error in on this line?

Could you please post entire scene code? As a text not a screenshot ...



Edited by cag014
Link to post
Share on other sites

Hi thanks for your reply !


I'am a little confused in the TTS scen file the execution line is          fibaro:startScene('sceneID',\{"text",""\})  

but in the forum i also found following line                                  fibaro:startScene('ttsSceneID',{"text",""})

its not the same. Whats the correct line to execute the TTS scen?


This is the code i copied from the TTS file and pasted in to my scen.



{\rtf1\ansi\ansicpg1252\deff0\nouicompat{\fonttbl{\f0\fnil\fcharset0 Calibri;}{\f1\fnil\fcharset1 Segoe UI Symbol;}{\f2\fnil\fcharset1 Cambria Math;}{\f3\fnil\fcharset1 Segoe UI Symbol;}}
{\*\generator Riched20 10.0.17134}{\*\mmathPr\mmathFont2\mwrapIndent1440 }\viewkind4\uc1 
\pard\sl240\slmult1\f0\fs22\lang9 --[[ \par
V1.0 Scene functionality:\par
1. Sendi text (and volume level-optional) to specific IP address of ZenitGatekeeper.apk \par
2. The scene designed for external execuiton only with parameters of text and IP address.\par
    An example:\par
      * fibaro:startScene('sceneID',\{"text",""\})   \par
      * fibaro:startScene('sceneID',\{"text","",volLevel\}) \par
   Please notice that the volume level of your phone or tablet will be changed\par
                 accordingly. Usualy volume range is 1-15.\par
======================== USER CONFIGURABLE PARAMETERS ===============================\par
--------------------------------- v1.0 ---------------------------------------------------------]]\par
local httpTimeout = 7000   -- HTTP timeout in mSec. \par
local debug       = false  -- Display debug information.\par
function errProcess(httpStatus)\par
   mStr = mStr .. "<font color=orangered><sup>[" .. httpStatus .. "]</sup>"\par
    if (tonumber(httpStatus) >= 500 ) then\par
           mStr = mStr .. "<small> [X] </small>Server error while processing the request"\par
    elseif (tonumber(httpStatus) >= 400 ) then\par
           mStr = mStr .. "<small> [X] </small>lient request error"\par
    elseif (tonumber(httpStatus) >= 300 ) then\par
      mStr = mStr .. "<small> [X] </small>Redirection to another location"\par
    fibaro:debug(mStr .. "</font>")\par
mStr =""\par
local IP_address,PAMessage = "",""\par
local TTS_delay,sleepTime,sCnt=0,0,fibaro:countScenes()\par
if (fibaro:args() ~= nil) then \par
   PAMessage  = fibaro:args()[1] \par
   IP_address = fibaro:args()[2]\par
   if fibaro:args()[3] then ttsVol = fibaro:args()[3] end\par
  fibaro:debug ("<font color=pink>No data received. Aborting scene...</font>")\par
-- In case that more than one messages received at the same time, \par
--    create delay between scenes to allow TTS to speak all messages.\par
if fibaro:countScenes() > 1 then\par
  while sleepTime ❤️ do sleepTime = math.random()*7.5 end\par
  if debug then fibaro:debug("\f1\u-10180?\u-8276?\f0 "..fibaro:countScenes() .. " \f1\u-10179?\u-8950?\f0 ".. PAMessage .. " \f2\u10711?\f0 "..sleepTime) end\par
  sleepTime = 6\par
TTS_delay = PAMessage:len() * 170--mSec per character\par
x=os.clock(); while (fibaro:countScenes() > 1 and os.clock() - x < sleepTime) do end \par
uri="/tts=" .. PAMessage  \par
if PAMessage == "wakeup" or PAMessage == "ping" then uri="/"..PAMessage ; ttsVol=nil end \par
mStr = "<font color=lightblue><sub>\f1\u-10180?\u-8276?\f0 "..fibaro:countScenes().."/"..sCnt ..\par
       "</font></sub><font color=yellowgreen><small> "..string.match(IP_address,"(.*):") .. \par
       "</small></font><font color=wheat> \f1\u-10179?\u-8950?\f0  "..PAMessage.." </font><sup>\f2\u10711?\f0 "..TTS_delay/1000 .. "</sup>"\par
if ttsVol then \par
  mStr=mStr.. "\f1\u-10180?\u-8267?\f0 <font color=wheat>".. ttsVol.." </font>"\par
  uri = uri.."&vol="..ttsVol \par
end \par
uri = string.gsub(string.gsub(uri, "%%", "%%25"), "%s+", "%%20")\par
if debug then fibaro:debug("URL [ " .. uri .. " ]") end\par
TTS = net.HTTPClient(\{timeout=httpTimeout\})\par
TTS:request("http://" ..IP_address .. uri,\par
  \{success = function(resp)\par
                if resp.status >= 300 then  errProcess(resp.status) \par
                else \par
                   fibaro:debug(mStr .. "<font color=lightgreen><small> [\f3\u10004?\f0 ]</small></font>")\par
             end, -- function(resp) \par
   error = function(error)\par
               if string.find(error,"Operation canceled") then\par
                 fibaro:debug(mStr.."<font color=orangered><small> [X] </small>"..error..". timeout " .. httpTimeout/1000 .."sec.</font>")\par
                 fibaro:debug(mStr.."<font color=orangered><small> [X] </small>"..error.."</font>")\par
    option = \{method = "GET"\}\par

Link to post
Share on other sites
  • 11 months later...

Good morning to all,
I am trying to bring this solution for HC3 using Quick Apps via this code:

function QuickApp:ChiamareTTS()
       self:debug("ChiamareTTS ")
    local address = ""
    self.http:request(address, {
           headers = { 
               Accept = "application/json"
            checkCertificate = true,
            method = 'GET'
        success = function(response)
            self:debug("response status:", response.status) 
            self:debug("headers:", response.headers["Content-Type"]) 
            local data = json.decode(response.data)  
            self:debug("ChiamareTTS data " .. data)
            self:updateView("label""text", data) 
        error = function(error)
            self:debug('error: ' .. json.encode(error))
    self:debug("ChiamareTTS fine")
function QuickApp:setLabelWithTime()
function QuickApp:onInit()
    self.http = net.HTTPClient({timeout=3000})
function QuickApp:uibutton1OnReleased(event)
Ma ottengo sempre questa risposta:
[24.09.2020] [07:18:49] [TRACE] [QUICKAPP137]: UIEvent: {"eventType":"onReleased","values":[],"deviceId":137,"elementName":"button1"}[24.09.2020] [07:18:49] [DEBUG] [QUICKAPP137]: uibutton1OnReleased[24.09.2020] [07:18:49] [DEBUG] [QUICKAPP137]: ChiamareTTS[24.09.2020] [07:18:49] [DEBUG] [QUICKAPP137]: ChiamareTTS fine[24.09.2020] [07:18:52] [DEBUG] [QUICKAPP137]: error: "Operation canceled"
Do you have any suggestions?
it could be a port problem as shown in this post (I'm not very clear about the exposure): 
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...