Changing volume for Say commands after Restart

High,
I’m using the VoiceRSS TTS service in order the let my Sonos Boxes say the given text.
That works great!
However, I’m having problems when setting the volume for those commands.
Using the “notificationvolume” channel of the Sonos boxes, the volume can be set. This setting is kept through a restart of OH2, but when using the command for the first time on a specific box, the notificationvolume of that box is set to the value of the volume-channel. Resetting the notificationvolume manually and sending another command will use the correct setting.
Am I missing something? I tried to find the code which does the volume changing when using the say-command, but stupid.me couldn’t find it.

My log shows when running the command for the first time:
Setting of NotificationVolume=20, Volume=6

11:45:33.641 [DEBUG] [ntime.internal.engine.RuleEngineImpl] - Executing rule 'SagEtwas'
11:45:33.680 [INFO ] [se.smarthome.model.script.SayCommand] - SayCommand =SayCommand (Type=StringItem, State=Mist, Label=null, Category=null)
11:45:33.719 [INFO ] [se.smarthome.model.script.SayCommand] - Volume = 0.2
11:45:33.819 [INFO ] [marthome.event.ItemStateChangedEvent] - PlayGaestezimmer_NotificationVolume changed from 20 to 6
11:45:34.810 [INFO ] [marthome.event.ItemStateChangedEvent] - PlayGaestezimmer_Controller changed from PAUSE to PLAY
11:45:35.652 [INFO ] [marthome.event.ItemStateChangedEvent] - PlayGaestezimmer_Controller changed from PLAY to PAUSE
11:45:35.782 [INFO ] [se.smarthome.model.script.SayCommand] - Es ist alles gesagt!

Running for the second time with
Setting of NotificationVolume=20, Volume=6

11:46:22.323 [DEBUG] [ntime.internal.engine.RuleEngineImpl] - Executing rule 'SagEtwas'
11:46:22.327 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'SayCommand' received command Mist
11:46:22.363 [INFO ] [se.smarthome.model.script.SayCommand] - SayCommand =SayCommand (Type=StringItem, State=Mist, Label=null, Category=null)
11:46:22.397 [INFO ] [se.smarthome.model.script.SayCommand] - Volume = 0.2
11:46:22.620 [INFO ] [marthome.event.ItemStateChangedEvent] - PlayGaestezimmer_Volume changed from 6 to 20
11:46:23.183 [INFO ] [marthome.event.ItemStateChangedEvent] - PlayGaestezimmer_Controller changed from PAUSE to PLAY
11:46:24.303 [INFO ] [marthome.event.ItemStateChangedEvent] - PlayGaestezimmer_Controller changed from PLAY to PAUSE
11:46:24.411 [INFO ] [se.smarthome.model.script.SayCommand] - Es ist alles gesagt!

My rule-file

rule "SagEtwas"

when 
  Item SayCommand received update
then
  logInfo ("SayCommand", "SayCommand ={}", SayCommand)
  var string AudioSink
  switch AudioSink {
    case Lautsprecher.state.toString=="Küche" : AudioSink="sonos:PLAY1:RINCON_xx1400"
    case Lautsprecher.state.toString=="Wohnzimmer" : AudioSink="sonos:PLAY1:RINCON_yy1400"
    case Lautsprecher.state.toString=="Gästezimmer" : AudioSink= "sonos:PLAY1:RINCON_zz1400"
    default:AudioSink="sonos:PLAY1:RINCON_xx1400"
    }
  setMasterVolume(new PercentType(20),AudioSink)
  Volume= getMasterVolume()  
  logInfo("SayCommand","Volume = {}", Volume)   
  say(SayCommand.state.toString,"voicerss:deDE",AudioSink)
  logInfo("SayCommand","Es ist alles gesagt!")
end

I am not sure whether the say command is interpreted as sonos notification.
Therefore I would assume that the notification volume is not applied.

I am using the say command and storing the volume before the say command in a variable and them restoring it after the command is finished.

This has the disadvantage that I have to insert a “sleep:Thread” that lasts long enough to finish the spoken output because otherwise the volume will be changed during the say statement.

But I would be great to have an independent volume setting as with the notification channel.

Using sonos notification channel has the downside that it cannot handle text to speech which is so greatly supported by the new say command.

User @Lolodomo pointed me to the NotificationVolume and for me it is working.
I still have the “setMasterVolume” in the rule, however that seems to be overruled somehow on the first use after startung OH.
Looking at the logs, the volume is set and logged somehow by the say-command. However I’m still searching for the used code (Sonos binding, Voice or Audio…)

Thanks for the reply. I will test this immediately.

TTS with sonos as audio sink is using the sound notification of the Sonos binding including the sound management.

I did some more testing.
Notice in the above posted logs, in case of the initial say-command the NotificationVolume gets set, incase of the second call its the Volume that gets set.
If the NotificationVolume is changed manually before using the say-command the correct volume is used on the first try. So the workaround is to manually set the NotificationVolume for each Box after a restart. Maybe setting the NotificationVolume for the selected box in the rule is possible, I have to check that.
[Edit:]
Using the rule works also, however in the rule I have the selected Box only as a string. Setting the NotificationVolume with sendcommand needs the item itself. So I just do a sendcommand to all boxes instead of the selected.

With the help of @MikeH I found more elegant version:

val Number NotificationVolume = 20

rule “SagEtwas”

when
Item SayCommand received update
then
var string AudioSink
switch AudioSink {
case Lautsprecher.state.toString==“Küche” : AudioSink="sonos:PLAY1:RINCON_xx1400"
case Lautsprecher.state.toString==“Wohnzimmer” : AudioSink="sonos:PLAY1:RINCON_yy1400"
case Lautsprecher.state.toString==“Gästezimmer” : AudioSink= "sonos:PLAY1:RINCON_zz1400"
default:AudioSink=“sonos:PLAY1:RINCON_xx1400”
}
gPlayer_NotificationVolume.allMembers.filter(s | s.state!=NotificationVolume ).forEach [item | sendCommand(item,NotificationVolume)]
say(SayCommand.state.toString,“voicerss:deDE”,AudioSink)
logInfo(“SayCommand”,“Es ist alles gesagt!”)
end

Hi @opus

Must all NotificationVolume Items be member of group gPlayer_NotificationVolume in

gPlayer_NotificationVolume.allMembers.filter(s | s.state!=NotificationVolume ).forEach [item | sendCommand(item,NotificationVolume)]

also do you have a solution to say somthing in all speakers at the same time?

/Mike

Yes, sorry I forgot that.

…and No, I didn’t work on something like that.

1 Like

This is working for me but it does not go back and play without SaveAll.

rule "Say Notify"

when 
  Item Say_Notify received update
then
  var String AudioSink = "sonos:PLAY5:RINCON_XXXXXXXXXXXX1400"
  var boolean sayall = false
  
  switch (Say_Speaker.state.toString) {
    case "Kök"    : AudioSink="sonos:PLAY5:RINCON_XXXXXXXXXXXX1400"
    case "Badrum" : AudioSink="sonos:CONNECT:RINCON_BXXXXXXXXXXX1400"
    case "Lekrum" : AudioSink= "sonos:CONNECT:RINCON_CXXXXXXXXXXX1400"
    case "Alla"   : sayall = true
    default: AudioSink = "sonos:PLAY5:RINCON_XXXXXXXXXXXX1400"	
    }
    if (sayall){	AudioSink="sonos:PLAY5:RINCON_XXXXXXXXXXXX1400"
//    	SonosKok_SaveAll.sendCommand(ON) Does not work for me depending on issue #1988
    	SonosKok_Add.sendCommand("RINCON_BXXXXXXXXXXX1400")
    	SonosKok_Add.sendCommand("RINCON_CXXXXXXXXXXX1400")
    }
    
  gPlayer_NotificationVolume.allMembers.filter(s | s.state!=Say_NotifyVolume.state ).forEach [item | item.sendCommand(Say_NotifyVolume.state)]
  
  say(Say_Notify.state.toString,"voicerss:svSE",AudioSink)
  
  if (sayall){
//  	SonosKok_RestoreAll.sendCommand(ON) No use without working SaveAll
    	SonosKok_Remove.sendCommand("RINCON_BXXXXXXXXXXX1400")
    	SonosKok_Remove.sendCommand("RINCON_CXXXXXXXXXXX1400")

  }
    
  logInfo("Say","Detta är sagt! "+Say_Notify.state.toString)
end

Interesting and thanks!

I am surprise that the various "SonosKok_Add.sendCommand"s are working without adding Thread::sleep(…) in between.

But I will try your approach.
Could you do me a favor and show your items definition especially the one for the
SonosKok_Add and SonosKok_Remove.

What is the best way to show the Item definition when i have configured them in PaperUi?

/Mike

I honestly do not know because I am still using manual item definitions and never used the paper UI. So forget my request and thanks again for the example code.

Hi,

i´m using the notification channel for my doorbell and it works great. Now am trying to use it for the say commands but i´m not able to raise the volume(only for SAY command…Doorbell notify works)

Part of my rule:

  //Lautstärke setzen
  gSonosNotificationVolume?.members.forEach[sonosV |
    logInfo(filename, "Setze Notify Lautstärke auf \"50\" für Sonos Member \"" + sonosV.name + "\"")
            sonosV.sendCommand(50 as Number)
    	]
    	//Sende Notification
            say ("Die Garage ist noch offen")

    ]

so in the logs i can see it changes the Volume:

EGWZ_Sonos_Notificationsoundvolume changed from 18 to 50

but it feels like 10 :face_with_raised_eyebrow:
I can also change it to 100…still sound like 10.

My Sonos Boxes are paired

IMHO the notificationsoundvolume is used only in case of the say command, when playing the “doorbell” file the “normal” volume will be used.

Hi opus,

i´ve tried now to raise both…still sounds like 10(only the say commands). If i raise the notificationsoundvolume for the doorbell to 100, the whole neighborhood is “notified” :joy: