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