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"]
}
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âŚ
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]
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.
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 )
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
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.