SmartThings Community

Better an Reloaded Fix for TTS (TextToSpeech)

tts
sonos

(Ule) #1

Hi, This is a try to work around the TextToSpeach function Problem,

I have created a new function using Google TTS,
Google API is now requesting captcha to use the function, but the parameters here avoid the captcha, I have tested and works fine to me.

Google function have a limit to avoid abuse, but most of common users will have not problems, heavy duty users can be blocked for some minutes

Update:

Google have some problems with several request, they block for some time if you request frequently,

I have found a great service, this service allows free 350 request per day, with almost not characters limit and great quality voice.

You must to register to get an API Key, the register is so easy and you don´t need to answer the email to confirm registration.

http://www.voicerss.org/registration.aspx

You can known more about Voice RSS in http://www.voicerss.org/

The TTS Function verify if the API Key exists, and creates the link, if no API Key is found a Google Link is created (google no need API Key but can be blocked if many request occurs )

you can see the sound url start with x-rincon-mp3radio , this is the protocol used by sonos to play streaming, it´s the unique way I have found to make sonos compatible, the DLNA Player replace the x-rincon-mp3radio: for http: and all works fine, but the new speakers from smarthings (Samsung and Bose) could not to work with this protocol, I cant replece the url inside those speakes “unless they use the DLNA Player”, then you can change the sonos compatiblity by a general compatibility changing x-rincon-mp3radio by http: in the fuction


How to use the Fix


1.- Create the new TTS function

private textToSpeechT(message){
if (message) {
if (ttsApiKey){
[uri: “x-rincon-mp3radio://api.voicerss.org/” + “?key=$ttsApiKey&hl=en-us&r=0&f=48khz_16bit_mono&src=” + URLEncoder.encode(message, “UTF-8”).replaceAll(/+/,’%20’) +"&sf=//s3.amazonaws.com/smartapp-" , duration: “${5 + Math.max(Math.round(message.length()/12),2)}”]
}else{
message = message.length() >100 ? message[0…90] :message
[uri: “x-rincon-mp3radio://www.translate.google.com/translate_tts?tl=en&client=t&q=” + URLEncoder.encode(message, “UTF-8”).replaceAll(/+/,’%20’) +"&sf=//s3.amazonaws.com/smartapp-", duration: “${5 + Math.max(Math.round(message.length()/12),2)}”]
}
}else{
[uri: “https://s3.amazonaws.com/smartapp-media/tts/633e22db83b7469c960ff1de955295f57915bd9a.mp3”, duration: “10”]
}
}

2.- You can see an API Key is needed key=$ttsApiKey , then you must to create an input to get the API Key, this can be created inside your smart app options

input “ttsApiKey”, “text”, title: “TTS Key”, required: false

3.- Replace the textToSpeech(string) function with the new textToSpeechT(string)

And that’s all


Safe Text to Speach


You can Use a Safe text to speach function to verify if Smartthings function works and if it fails go to the fix,

This safe function does not work in “update()” and “install()” methods, this is because Smarthings platform avoid to save the smart app if an error occurs in those methods even if the error its catched, you must create your sound before save the smartapp

private safeTextToSpeech(message) {
message = message?:"You selected the Text to Speach Function but did not enter a Message"
try {
textToSpeech(message)
}
catch (Throwable t) {
log.error t
textToSpeechT(message)
}
}


You can test a working smart app in

I hope you enjoy a better TTS experience with this fix


SmartThings Text-To-Speech for Sonos (playText) not working?
Sonos Issues
Sonos Weather with DLNA Render
Sonos - Custom Message Failed to Save
SmartThings Text-To-Speech for Sonos (playText) not working?
SmartThings Text-To-Speech for Sonos (playText) not working?
RELEASE Generic Media Renderer (DLNA Speakers). Cheap Sonos Alternative (Update V2)
How to TTS
RELEASE Generic Media Renderer (DLNA Speakers). Cheap Sonos Alternative (Update V2)
Amazon Polly TTS code
Sonos ~ "Failed to save page: mainPage" error when trying to add a new SmartApp
[RESOLVED] TTS Not working (May 2016)
[OBSOLETE 1.1.6 5/25/16] Big Talker - Talk when events occur
(Mike Maxwell) #2

@ule
Doesn’t work on the Samsung M7’s at least.
Getting this in the M7 logs

playTrackAndRestore(http://www.translate.google.com/translate_tts?tl=en&client=t&q=This+Is+The+Free+Man+Test&, 3, 40) 

When I execute this link in a browser the resulting MP3 is fine, just doesn’t render on the M7 :confused:


(Ule) #3

Hi @Mike_Maxwell, Could you try increasing the parameter Delay Before Messages, maybe the http request is taking more time , does not hurt to try.

Thanks for feedback


(Mike Maxwell) #4

Sorry, don’t know where that parameter value change is supposed to be…


(Ule) #5

Hi @Mike_Maxwell, I have verified, you must update again the Dlna_player_external TTS , there is a crash with the & from the url

https://github.com/SmartThingsUle/DLNA-PLAYER/blob/master/MediaRenderer_Player_External_TTS.groovy

Ule


(Mike Maxwell) #6

Unfortunately I can’t modify the ST Samsung speaker device as it’s not community published.


(Ule) #7

Hi @Mike_Maxwell, Are you not using the DLNA PLAYER with M7?

Are you using a different device type?

if you are using the DLNA PLAYER just replace with the new

https://github.com/SmartThingsUle/DLNA-PLAYER/blob/master/MediaRenderer_Player_External_TTS.groovy

If you are not using the DLNA player, could you explain what device type are you using?

update***

Sorry I confuse you with vernondraper who inform that the M7 works With DLNA PLayer, You can use the DLNA PLAYER to use with your speakers, maybe the smartthings device have more functionality, but the DLNA PLAYER could play text messages right now

Ule


(Mike Maxwell) #8

I’m using St’s SamsungAudio device.
I was unable to install your MediaRender (connect) app, as it fails after the DLNA selection with "Error - bad state…"
Both your device and smart app are published correctly…


(Ule) #9

Hi @Mike_Maxwell, I Have Update the MediaRenderer Connect, You must to update the smartaspp to install the DLNA PLAYER from android, try it


(Mike Maxwell) #10

Yes, DLNA player installed.


(Pizzinini) #11

I just installed this for one of my speakers by updating the device type and using the new app… It works great! No problems at all. Thank you @ule for all the work!!! My kids love it when the house can talk to them. They tend to listen to the house more then to me when I try to get them to go to bed :wink:

Just a note. I found that the “old” app and device type still works for new custom messages that are very short like “light on”, even if they were not cached previously. Just for longer messages it does not work.


(The Viking AKA "Holy Crap You're a Giant!") #12

@pizzinini, how did you get it to work?
I installed it and it isn’t working.
I’m using DLNA Renderer with multiple Windows systems in the home. These work for everything else I throw at them except any kind of TTS with regards to ST.
The funny thing is, they DID work with ST without issue until the TTS function stopped working.


(Pizzinini) #13

I am using a Veetop Airmusic Box. I had it setup with the original device type and sonos notify with sound app. I use the DLNA connect app to connect it to the Smartthings hub. Now I went to the IDE and created a new device type with the TTS code above, saved and published it to myself and then changed the device rype of the Airmusic box to the new type. Then I created a new app with the TTS code above and saved, published to self. Then I installed the app using the Smartthings mobile app selecting the Airmusic box as a speaker .


#14

I cannot get the Sonos part of this to work. It simply plays a few seconds of music and stops when I try to use it.


(Ule) #15

Hi @paulsown, Could yuu be more specific? Are you using a sonos speaker or DLNA speaker?, What smartapp are you using?


#16

Sonos. I am using Sons_Notify_with_Sound_External_TTS above.


(Ule) #17

Hi @paulsown, The Smartapp is working fine, please verify the logs to known what error appears.


(Bobby) #18

Are the custom messages working fine for you? Everything but the custom messages works for me.


#19

Same problem I have. I guess I should have been more clear. When I try to play a custom message, it plays music that is approximately the length of the message I was attempting. Also, a custom message works fine on a VLC thing I have setup. The logs show no errors.

All other sounds play normally including the speaking parts. Just the custom messages fail.


(Ule) #20

Hi @paulsown, I dont have a sonos speaker, I have test the fix with several dlna speakers, maybe the sons device type do no accept the new url.
I think you known how to work with the IDE, could you replace the next code in Sonos Notify with Sound External TTS smart app

case “Lightsaber”:
state.sound = [uri: “http://s3.amazonaws.com/smartapp-media/sonos/lightsaber.mp3”, duration: “10”]
break;

with this

case “Lightsaber”:
state.sound = [uri: “http://www.translate.google.com/translate_tts?tl=en&client=t&q=The+Alarm+Has+Been+Armed+In+All+Zones+Right+Now&”, duration: “10”]
break;

After you have change the code, saved and publish for you, select the Lightsaber in the Sonos Notify with Sound External TTS and save

With this action you can send the uri to sonos, and verify if the sonos is working with the uri.

If the uri plays, then the problem can be in other place, if the uri does not plays, then the sonos device type have problems with the uri.

Please try it and send me the results, thanks