TTS on Android Phone or Tablet

I make my own Text to Speech App on Android with Droidscript.
I send some Text with Http Post with openhab to the Phone.
And the Phone says the Text. The Droidscript must run in the Background.

here is the droidscript for that:

//Called when application is started.
function OnStart()
{

//Check wifi is enabled.
var ip = app.GetIPAddress();
if( ip == "0.0.0.0" ) { 
	alert( "Please Enable Wi-Fi" ); 
	app.Exit();
}
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );	

//Create a text label and add it to layout.
var s = "Type the following address into your" + 
		" browser\n\n" + ip +":8081";
txt = app.CreateText( s, 0.8, 0.5, "MultiLine" );
txt.SetTextSize( 22 );
lay.AddChild( txt );

//Add layout to app.	
app.AddLayout( lay );

//Create and run web server.
serv = app.CreateWebServer( 8081,"NoWelcome");
serv.AddServlet( "/message", OnServlet );
serv.Start();

}

//Handle servlet requests.
function OnServlet( request, info )
{
serv.SetResponse( “” );
// app.ShowPopup( info.remoteAddress + " says: " + request.msg );
ausgabe=request.msg;
ausgabe2="";
if (ausgabe.length>0)
{
for (i=0; i<ausgabe.length; i++)
{
if (ausgabe[i]=="_") { ausgabe2=ausgabe2+" "} else {ausgabe2=ausgabe2+ausgabe[i]};
}
}
var pitch = 1.0, speed = 0.8;
app.ShowPopup( info.remoteAddress + " says: " + ausgabe2);
app.TextToSpeech( ausgabe2, pitch, speed );

}

And that ist the openhab http for example:

Switch Light_C_Workshop “Workshop” (gC, Lights)
{ http=">[ON:POST:http://192.168.0.181:8081/message?msg=Lampe_an]" }

In the droid do replace from underline to blank.
and says “Lampe an”. Ip adress is that from the Phone. In my network athHome

To say thomething in the rule. for example you can use this

rule "test"
when
Item Light_C_Workshop changed to ON
then
{
sendHttpPostRequest((“http://192.168.0.181:8081/message?msg=Kellerlampe an “).replaceAll(” “,”_”))
}
end

1 Like