I am attempting to setup a lambda to call the say command and then restore the volume afterwards. This is what I have
import org.eclipse.xtext.xbase.lib.Functions
val mySay= [ Dimmer playerVolume, String chromecastChannel,
String message, Number volume |
var lastVolume = playerVolume.state
playerVolume.sendCommand(volume)
say("<speak>"+message+"</speak>",
"pollytts:Joanna",
chromecastChannel)
Thread::sleep(5000)
playerVolume.sendCommand(lastVolume)
]
This doesn’t really save me a lot of time - the reason is that say requires a channel… It would be nice if I could somehow just pass in a Chromecast Item and have it get everything it needs from there. I tried extracting the channel from an item but couldn’t figure that out.
Is there a way to do this? Is there a better way than what I currently have?
I can’t say if it works for your voice and audiosink, however this is the rule I am using with VoiceRSS and Sonos speakers ( it did work with a single chrome cast).
rule "SaySomething"
when
Item SayCommand received update
then
var String AudioSink
switch AudioSink {
case Lautsprecher.state.toString=="KĂĽche" : AudioSink="sonos:PLAY1:PlayKueche"
case Lautsprecher.state.toString=="Wohnzimmer" : AudioSink="sonos:PLAY1:PlayWohnzimmer"
case Lautsprecher.state.toString=="BĂĽro" : AudioSink= "sonos:PLAY1:PlayBuero"
case Lautsprecher.state.toString=="Gästezimmer" : AudioSink= "sonos:PLAY1:PlayGaestezimmer"
default:AudioSink="sonos:PLAY1:PlayWohnzimmer"
}
say(SayCommand.state.toString,"voicerss:deDE",AudioSink)
logInfo("SayCommand","Es ist alles gesagt!")
end
SayCommand is an item that holds the string to be spoken, AudioSink is an item that holds the human readable name of the to be selected Audiosink. Both are set on an HABPanel UI.
Note that using the Sonos binding resetting the volume is handled by the binding (thanks goto Lolodomo).