SmartThings Community

Better an Reloaded Fix for TTS (TextToSpeech)

Here is some good news:

I am using the “old” device type (“DLNA Player” not “DLNA Player_TTS”) with a Lario HD and the “new” “Sonos Notify with Sound External TTS” app and custom messages work just fine. I tried a couple of different ones to make sure they were not cached ones from before text to speech broke.

So it looks like for this setup, a new device type is not even needed.

Hi @pizzinini, The new device type is needed because the commands playTextAndResume, playTextAndRestore, speech , need to convert the text to audio, internally the device type calls the function and will crash if is not modified, Sonos Notify with Sound External TTS convert directly the audio inside app, but other smart apps will send the message instead the url, if you want a fully compatible its necessary to update the device type to

Got it - thank you for clarifying! I only use the devices for notification so I did not notice. (maybe I should have read your post above more diligently :wink: )

Hi @Alyc100,

I have update the function to remove the plus sign after the urlencoder, maybe the sonos does not recognize the + in uri, could you try again?


I cant see an answerd from the sonos speakers in log you have sent.

I have to adjust the delay between action when changing volume apply, this adjust is not present in sonos player, could you avoid to use the volume change, just to verify if the sonos is not crashing for small delay between actions

@ule Still nothing with latest code. Here are the logs. Disabled volume change.

7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:18 PM: trace has XML body
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:18 PM: trace NOTIFY /notify HTTP/1.1 3375 bytes, body = 2284 bytes, sid = RINCON_000E58814DBE01400_sub0000000328
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:18 PM: trace uuid; RINCON_000E58814DBE01400
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace has XML body
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace HTTP/1.1 200 OK 639 bytes, body = 240 bytes, sid =
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace has XML body
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace HTTP/1.1 500 Internal Server Error 807 bytes, body = 347 bytes, sid =
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace Returning 4 commands
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace sonosAction(SetAVTransportURI, AVTransport, /MediaRenderer/AVTransport/Control, [InstanceID:0, CurrentURI:x-rincon-cpcontainer:10062a6cspotify%3auser%3aalyc100%3aplaylist%3a2WNDsGBK60gugZIIt6c1qN, CurrentURIMetaData:<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10062a6cspotify%3auser%3aalyc100%3aplaylist%3a2WNDsGBK60gugZIIt6c1qN" parentID="10082664playlists" restricted="true"><dc:title>Good Old Mellow</dc:title><upnp:class>object.container.playlistContainer</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite>])
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: info setTrack(x-rincon-cpcontainer:10062a6cspotify%3auser%3aalyc100%3aplaylist%3a2WNDsGBK60gugZIIt6c1qN, null, 570 B})
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace setTrack(x-rincon-cpcontainer:10062a6cspotify%3auser%3aalyc100%3aplaylist%3a2WNDsGBK60gugZIIt6c1qN, 570 B)
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace Restoring track x-rincon-cpcontainer:10062a6cspotify%3auser%3aalyc100%3aplaylist%3a2WNDsGBK60gugZIIt6c1qN
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace Delaying 10000 ms before restoration
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace sonosAction(Play, AVTransport, /MediaRenderer/AVTransport/Control, [InstanceID:0, Speed:1])
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace sonosAction(SetAVTransportURI, AVTransport, /MediaRenderer/AVTransport/Control, [InstanceID:0, CurrentURI:http://www.translate.google.com/translate_tts?tl=en&client=t&q=Alex%20Is%20Arriving&sf=//s3.amazonaws.com/smartapp-&, CurrentURIMetaData:])
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: info setTrack(http://www.translate.google.com/translate_tts?tl=en&client=t&q=Alex%20Is%20Arriving&sf=//s3.amazonaws.com/smartapp-&, null, 0 B})
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: trace Setting sound track: http://www.translate.google.com/translate_tts?tl=en&client=t&q=Alex%20Is%20Arriving&sf=//s3.amazonaws.com/smartapp-&
7978f7a8-fcf6-4af2-80e4-8a6db2ede268 7:28:17 PM: debug playTrackAndRestore(http://www.translate.google.com/translate_tts?tl=en&client=t&q=Alex%20Is%20Arriving&sf=//s3.amazonaws.com/smartapp-&, 7, null)

I have yet to implement this in code, but isn’t the Sonos looking for something that ends in MP3 in order to play? This does work in a browser, however.

Will play with this tomorrow to see if it works with the Sonos, but I have a feeling it won’t be a direct replacement since Sonos is looking for MP3 files.

I noticed that if you make a small change to the code in Line 427+ (change the country code) in the Sonos Notify with Sound External TTS app you can send custom messages in languages other than English. Below is an example for French (fr). I only tried German (de) but I am sure many of the other languages work, too.

private textToSpeechT(message){
if (message) {
def duration = Math.max(Math.round(message.length()/8),2)
[uri: “http://www.translate.google.com/translate_tts?tl=fr&client=t&q=” + URLEncoder.encode(message, “UTF-8”) +"&", duration: “$duration”]
}else{
[uri: “http://www.translate.google.com/translate_tts?tl=fr&client=t&q=” + URLEncoder.encode(“You selected the Text to Speach Function but did not enter a Message”, “UTF-8”) +"&", duration: “10”]
}
}

HI @MichaelS, Yes, sonos do not play all direct url, that is the problem, almost all mediarenderers can play the direct url, but no sonos, like @alyc100 show us, sonos need a x-rincon-mp3radio protocol to play a generic url, I try to avoid this call to be more generic to all speakers, the goal is to find somethig simple and working to all.

Good point…but to that point, will the other speaking systems NOT work with the x-rincon-mp3radio protocol in place?

Hi @MichaelS, Yes, other mediarenderes do not works with x-rincon-mp3radio, I can mod the generic media renderer device type to be compatible, but the new official speakers could have the same problem (do not recognize the x-rincon-mp3radio ) , I think is better to change the sonos device type, even to fix some timing problems, for me its a better work around, I´m going to request help to try some urls , maybe it will work. I hope you can help to test it

I am going to play with it this weekend…my main goal is to get the Sonos stuff working for the apps that I have published…but want to make it as compatible as I can.

Thanks!

Hu, Could some one help me to test this functions?

first test:

private textToSpeechT(message){
if (message) {
[uri: “http://www.translate.google.com/translate_tts?tl=en&client=t&q=” + URLEncoder.encode(message, “UTF-8”).replaceAll(/+/,’%20’) +"&file=ule.mp3", 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”]
}
}

Second test:

private textToSpeechT(message){
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-&file=ule.mp3", 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”]
}
}

Both of these give the following error:

java.util.regex.PatternSyntaxException: Dangling meta character ‘+’ near index 0

In addition, the "x-rincon-mp3radio protocol " doesn’t work with my sonos but throws no errors.

This isn’t workin for me at all. I just want to be able to change my Sonos text, and it isn’t working at all.

Is ST working on this soon?

@Tyler anyone?

Is this working now? It must be. I had installed the BigTalker app several weeks ago to test it out and it did not work. Today I rebooted my hub and then came home and opened one of the test sensor a TTS over Sonos played. Hope it keep working.

Hi @pmusselman, Smartthings has fixed the TTS Function, if you are using some smartapp with TTS fix you must to revert to original SmartApp

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"]
    }
}

Well, that worked for a little while (a few hours) and then quit. So I did some digging and found that I’m now being blocked by Google for unsual traffic.

Our systems have detected unusual traffic from your computer network. Please try your request again later. Why did this happen?

This page appears when Google automatically detects requests coming from your computer network which appear to be in violation of the Terms of Service. The block will expire shortly after those requests stop.

This traffic may have been sent by malicious software, a browser plug-in, or a script that sends automated requests. If you share your network connection, ask your administrator for help — a different computer using the same IP address may be responsible. Learn more

Sometimes you may see this page if you are using advanced terms that robots are known to use, or sending requests very quickly.

I’m using the original unmodified VLCThing 1.2.2 Device Type again (@geko) with the standard SmartThings textToSpeech(txt,true) call and it’s working again… for now… #ConsistentlyInconsistentPlatform

@ule,

I just attempted today to generate a new TTS message for Sonos device, and its still not working. Its only working with pre-generated TTS messages still…

Can anybody else confirm if their TTS is working correctly for Sonos?

-Rob

I just wanted to say - I updated the Smartapp & Device type but it appears to have caused a few issues.

I now cant delete the 2 devices that were connected with Media renderer connect. I get the follwoing message:

No signature of method: script14459763896711909525532.getChildDevices() is applicable for argument types: () values: []

Anyone able to help here?