Better an Reloaded Fix for TTS (TextToSpeech)

I have test the fix with several speakers except sonos (because I dont have a sonos speaker) , It must work since is a url and sonos plays mp3 urls

you can test the custom message play with the new app (wich has changed the tts function) and send a custom message to sonos.

remember you must update your smartapp with the fix or use some smartapps published here in first post.

1 Like

I have it working on my Sonos. Just needed to alter the textToSpeechT method in the Sonos Notify With Sound External TTS. I increased the duration calculation as there is a delay and changed the http protocol uri to x-rincon-mp3radio. Now custom message works on my Sonos.

private textToSpeechT(message){
if (message) {
	def duration =  Math.max(Math.round(message.length()/4),2)
    [uri: "x-rincon-mp3radio://www.translate.google.com/translate_tts?tl=en&client=t&q=" + URLEncoder.encode(message, "UTF-8") +"&", duration: "$duration"]
}else{
	[uri: "x-rincon-mp3radio://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") +"&", duration: "10"]
}

}

1 Like

For some reason only the “current temperature” is played (when using the Sonos Weather Forecast" smartapp )… regardless of what you select for Weather report options…

Any ideas?

I’ve having problems getting this to work consistently. It doesn’t seem to play any of the MP3 pre-recorded messages, and for custom messages, sometimes it works, sometimes not. Here are the log messages from when I changed to the pre-recorded flood message, and then tried to play it:

9:35:48 PM: error org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 25; The markup in the document following the root element must be well-formed. @ line 244
9:35:24 PM: trace Exiting takeAction()
9:35:24 PM: trace takeAction()
9:35:14 PM: debug state.sound : [uri:http://s3.amazonaws.com/smartapp-media/sonos/smartthings+detected+a+flood.mp3, duration:2]

I get that SAXParseException everytime it fails.

Hi @xcguy, I dont have a sonos to test the function, but @Alyc100 has mention the function does not works in sonos, I think the reason is becouse there are not a metadata in the message, this error do not appears in generic media renderer becouse GMR has a lot of fixes, but sonos is not, I have update the function to avoid the metadata without change the sonos player device type, please update the smart app sonos notify with sound external TTS and try again

Hi @someonexh, I think some zip codes does not have all the information, just try another zip just to verify if the smartapp works y have tested the zip code from NY 10001

You must to install the smartapp to use the fix, just now I have update the app to works with sonos, If you have installed before, please update the smartapp

Hi @Alyc100, I have update the function to be more generic, to use a radio tag just going to add the message to thr radio list , please help me testing the new function in a sonos device

private textToSpeechT(message){
if (message) {
[uri: “http://www.translate.google.com/translate_tts?tl=en&client=t&q=” + URLEncoder.encode(message, “UTF-8”) +"&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”) +"&sf=//s3.amazonaws.com/smartapp-&", duration: “10”]
}
}

Hi @ule, the new code doesn’t appear to work for me. I also checked the Sonos app to see if the messages were being added to a radio station list and it doesn’t appear to be the case. Happy to test out future code updates.

Hi @Alyc100, Thanks for testing, could you check if a error message appears in log when you use the custom message?

In player log must appears "Skipping event generation for sound file $trackUri " , please just confirm
Thanks

Same exact situation here too. I’ll help too if you’d like…Have installed your latest code last night, but no luck to make it work on Sonos

Hi @ule here is a dump of the logs. No announcement was played.

e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace setTrack(x-sonos-spotify:spotify%3atrack%3a6LpKziy8JtKAQG7C6KBxCn?sid=9&flags=8224&sn=1, 594 B)
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace Restoring track x-sonos-spotify:spotify%3atrack%3a6LpKziy8JtKAQG7C6KBxCn?sid=9&flags=8224&sn=1
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace sonosAction(GetVolume, RenderingControl, /MediaRenderer/RenderingControl/Control, [InstanceID:0, Channel:Master])
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace sonosAction(SetVolume, RenderingControl, /MediaRenderer/RenderingControl/Control, [InstanceID:0, Channel:Master, DesiredVolume:37])
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace volume = 37
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace setLocalLevel(37)
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace sonosAction(Stop, AVTransport, /MediaRenderer/AVTransport/Control, [InstanceID:0, Speed:1])
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace Restoring volume to 37
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace Delaying 11000 ms before resumption
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace sonosAction(Play, AVTransport, /MediaRenderer/AVTransport/Control, [InstanceID:0, Speed:1])
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace sonosAction(SetAVTransportURI, AVTransport, /MediaRenderer/AVTransport/Control, [InstanceID:0, CurrentURI:http://www.translate.google.com/translate_tts?tl=en&client=t&q=Alex+Is+Arriving+Now&sf=//s3.amazonaws.com/smartapp-&, CurrentURIMetaData:])
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: info setTrack(http://www.translate.google.com/translate_tts?tl=en&client=t&q=Alex+Is+Arriving+Now&sf=//s3.amazonaws.com/smartapp-&, null, 0 B})
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace Setting sound track: http://www.translate.google.com/translate_tts?tl=en&client=t&q=Alex+Is+Arriving+Now&sf=//s3.amazonaws.com/smartapp-&
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace sonosAction(GetVolume, RenderingControl, /MediaRenderer/RenderingControl/Control, [InstanceID:0, Channel:Master])
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace sonosAction(SetVolume, RenderingControl, /MediaRenderer/RenderingControl/Control, [InstanceID:0, Channel:Master, DesiredVolume:45])
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace volume = 45
7d0317bd-4c83-42fe-86c8-9ad86e590f24 1:45:05 PM: trace Exiting takeAction()
7d0317bd-4c83-42fe-86c8-9ad86e590f24 1:45:05 PM: trace takeAction()
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace setLocalLevel(45)
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace sonosAction(Stop, AVTransport, /MediaRenderer/AVTransport/Control, [InstanceID:0, Speed:1])
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: trace Stopping and setting level to 45
e68dde2f-edbd-49fd-afff-7f1d6f02ae35 1:45:05 PM: debug playTrackAndResume(http://www.translate.google.com/translate_tts?tl=en&client=t&q=Alex+Is+Arriving+Now&sf=//s3.amazonaws.com/smartapp-&, 7, 45)

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?