Better an Reloaded Fix for TTS (TextToSpeech)

In @geko’s VLCThing 1.2.2 Device Type, I was getting the following error when attempting TTS with BigTalker 1.1.2: java.lang.reflect.UndeclaredThrowableException @ line 584

Line 584 of VLCThing calls: def sound = textToSpeech(text, true)
So there is definitely still a problem with calling textToSpeech(text, true) against the current platform.

I replaced the “myTextToSpeech()” function in my VLCThing Device Type with your code and it is now working. Thanks for this info!

private def myTextToSpeech(message) {
    //Disabled due to SmartThings TTS platform issue.
        //def sound = textToSpeech(text, true)
        //sound.uri = sound.uri.replace('https:', 'http:')
        //return sound
    //Below is a fix until SmartThings TTS platform is fixed
    if (message) {
        [uri: "http://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: "http://www.translate.google.com/translate_tts?tl=en&client=t&q=" + URLEncoder.encode("You selected the Text to Speach Function but did not enter a Message", "UTF-8").replaceAll(/\+/,'%20') +"&sf=//s3.amazonaws.com/smartapp-&", duration: "10"]
    }
}