Hi Dirk
I created a script which is working well, same time about a second, but will reduce 200 dedicated talking events.
The SONOS switches in about a second, the same as the events.
Any less and it chops off the beginning of the TTS.
I did want to ask if you would help me out with a piece of my code:
' Set Speaker to Line-In of Master Bedroom Connect Amp
hs.TriggerEvent("SONOS LineIn Select")
Can you help me with the script to replicate the event in my picture:
Maybe by a CAPI action or someway that I can:
play audio output (variable1) using audio source (variable2)
Thank you
Chris
I created a script which is working well, same time about a second, but will reduce 200 dedicated talking events.
Code:
'---------------------------------- ' SONOS Script by Chris Coles ' Note this does not UNLINK/LINK Groups, LINKGROUPS should be used for this. ' This is a crude script for speeding up responses at the loss of functionality. '---------------------------------- '--------------------------------------------------------------------------- ' Public Variables '--------------------------------------------------------------------------- Dim DefaultSystemRefID As Integer = 235 Dim DefaultSystemAlarmRefID As Integer = 236 '--------------------------------------------------------------------------- ' Main Method '--------------------------------------------------------------------------- Sub Main(parm As Object) End Sub '--------------------------------------------------------------------------- ' Speak Method using Pipes to Seperate Values ( Speaker | Volume | TTS String | Voice ) '--------------------------------------------------------------------------- Public Sub speakSomething(ByVal Parms As Object) Dim parmArray() As String = Parms.ToString.Split("|") Dim setSpeakerName As String = parmArray(0) Dim setVolume As Integer = parmArray(1) Dim setTTS As String = parmArray(2) Dim setName As String = parmArray(3) Dim speakerNameID As Integer Dim speakerVolumeID As Integer Dim getOriginalVolume As Integer Dim getOriginalVoice As Integer = hs.DeviceValueEx(DefaultSystemRefID) Dim getOriginalAlarmVoice As Integer = hs.DeviceValueEx(DefaultSystemAlarmRefID) Select Case setSpeakerName Case "upstairs" speakerNameID = -1 speakerVolumeID = -1 Case "bathroom" speakerNameID = 11 speakerVolumeID = 77 Case "ensuite" speakerNameID = 1369 speakerVolumeID = 1379 Case "masterbedroom" speakerNameID = 8 speakerVolumeID = 22 Case "guestbedroom" speakerNameID = -1 speakerVolumeID = -1 Case "office" speakerNameID = -1 speakerVolumeID = -1 Case "livingroom" speakerNameID = 10 speakerVolumeID = 59 Case "frontroom" speakerNameID = 292 speakerVolumeID = 321 Case "downstairs" speakerNameID = 293 speakerVolumeID = 339 Case "frontdoor" speakerNameID = 12 speakerVolumeID = 95 Case "frontdoor" speakerNameID = 12 speakerVolumeID = 95 Case "kitchen" speakerNameID = -1 speakerVolumeID = -1 Case else hs.WriteLogEx("SONOS TTS", "Destination Speaker Incorrect", "#ff0000") End Select Select Case setName Case "Amy" changeVoice("Amy") Case "Brian" changeVoice("Brian") Case "Skippy" changeVoice("Normal") Case "Emma" changeVoice("Emma") Case "Eric" changeVoice("Eric") Case "Geriant" changeVoice("Geriant") Case "Gwyneth" changeVoice("Gwyneth") Case "Ivy" changeVoice("Ivy") Case "Jennifer" changeVoice("Jennifer") Case "Joey" changeVoice("Joey") Case "Kendra" changeVoice("Kenda") Case "Kimberly" changeVoice("Kimberly") Case "Nicole" changeVoice("Nicole") Case "Russell" changeVoice("Russell") Case "Salli" changeVoice("Salli") Case "Hazel" changeVoice("Hazel") Case "Zira" changeVoice("Zira") Case "Alarm" 'Use System Default Alarm Voice hs.WriteLog("SONOS TTS", "Default Alarm Voice is: " & getVoiceName(getOriginalAlarmVoice)) changeVoice(getVoiceName(getOriginalAlarmVoice)) Case "Normal" 'Use System Default Normal Voice hs.WriteLog("SONOS TTS", "Default Voice is: " & getVoiceName(getOriginalVoice)) changeVoice(getVoiceName(getOriginalVoice)) Case Else 'Do Nothing End Select If speakerNameID >-1 Then ' Get Original Volume getOriginalVolume = hs.DeviceValueEx(speakerVolumeID) hs.WriteLog("SONOS TTS", "Speaker Number: " & speakerNameID & " has an original volume of: " & getOriginalVolume) ' Set Pause on Speaker hs.CAPIControlHandler(hs.CAPIGetSingleControl(speakerNameID,True,"Pause",False,False)) ' Set Speaker to New Volume Dim cc as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(speakerVolumeID, True, "Volume (value)%", False, False) cc.ControlValue = setVolume Dim cr as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc) ' Set Speaker to Line-In of Master Bedroom Connect Amp hs.TriggerEvent("SONOS LineIn Select") ' Set Resume on Speaker hs.CAPIControlHandler(hs.CAPIGetSingleControl(speakerNameID,True,"Play",False,False)) ' Speak TTS through 3.5mm Jack to Connect AMP LineIn Input hs.waitsecs(1) hs.Speak(setTTS, True,"EAGLE54-HA:DEFAULT") ' Set Speaker to Original Volume Dim cc2 as HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(speakerVolumeID, True, "Volume (value)%", False, False) cc2.ControlValue = getOriginalVolume Dim cr2 as HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc2) ' Set speakerNameNumber to stop hs.CAPIControlHandler(hs.CAPIGetSingleControl(speakerNameID,True,"Stop",False,False)) ' Reset Normal Voice back to System Default changeVoice(getVoiceName(getOriginalVoice)) End If End Sub '--------------------------------------------------------------------------- ' Returns the Name of the Voice by sending an Integer (from Default Normal or Alarm Devices) '--------------------------------------------------------------------------- Public Function getVoiceName(number As Integer) Select Case number Case 0 Return "Amy" Case 1 Return "Brian" Case 2 Return "Skippy" Case 3 Return "Emma" Case 4 Return "Eric" Case 5 Return "Geriant" Case 6 Return "Gwyneth" Case 7 Return "Ivy" Case 8 Return "Jennifer" Case 9 Return "Joey" Case 10 Return "Kendra" Case 11 Return "Kimberly" Case 12 Return "Nicole" Case 13 Return "Russell" Case 14 Return "Salli" Case 15 Return "Hazel" Case 16 Return "Zira" Case Else hs.WriteLogEx("SONOS TTS", "Number not recgonised", "#ff0000") End Select End Function '--------------------------------------------------------------------------- ' Detects a change of the Normal Voice (done in HSTouch) and updates HomeSeer with the new Default '--------------------------------------------------------------------------- Public Sub detectChangeVoice(parm as Object) Dim Voice As Integer = hs.DeviceValueEx(DefaultSystemRefID) Dim changedName As String hs.WriteLog("SONOS TTS", "Voice is: " & Voice) Select Case Voice Case 0 'Amy (E/F) changedName = "Amy" Case 1 'Brian (E/M) changedName = "Brian" Case 2 'Skippy (U/M) changedName = "Skippy" Case 3 'Emma (E/F) changedName = "Emma" Case 4 'Eric (U/M) changedName = "Eric" Case 5 'Geriant (W/M) changedName = "Geriant" Case 6 'Gwyneth (W/F) changedName = "Gwyneth" Case 7 'Ivy (U/F) changedName = "Ivy" Case 8 'Jennifer (U/F) changedName = "Jennifer" Case 9 'Joey (U/M) changedName = "Joey" Case 10 'Kendra (U/F) changedName = "Kendra" Case 11 'Kimberly (U/F) changedName = "Kimberly" Case 12 'Nicole (A/F) changedName = "Nicole" Case 13 'Russell (A/M) changedName = "Russell" Case 14 'Salli (U/F) changedName = "Salli" Case 15 'Hazel (E/F) changedName = "Hazel" Case 16 'Zira (E/F) changedName = "Zira" Case Else hs.WriteLogEx("SONOS TTS", "Voice Control Not Detected", "#ff0000") End Select changeVoice(changedName) End Sub '--------------------------------------------------------------------------- ' Sets the HSSpeaker SAPI Voice '--------------------------------------------------------------------------- Public Sub changeVoice(toSetName as String) Select Case toSetName Case "Amy" hs.setvoice("IVONA 2 Amy - British English female voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Brian" hs.setvoice("IVONA 2 Brian - British English male voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Skippy" hs.setvoice("IVONA 2 Skippy the Chipmunk - US English male voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Emma" hs.setvoice("IVONA 2 Emma - British English female voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Eric" hs.setvoice("IVONA 2 Eric - US English male voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Geriant" hs.setvoice("IVONA 2 Geraint - Welsh English male voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Gwyneth" hs.setvoice("IVONA 2 Gwyneth - Welsh English female voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Ivy" hs.setvoice("IVONA 2 Ivy - US English female voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Jennifer" hs.setvoice("IVONA 2 Jennifer - US English female voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Joey" hs.setvoice("IVONA 2 Joey - US English male voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Kendra" hs.setvoice("IVONA 2 Kendra - US English female voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Kimberly" hs.setvoice("IVONA 2 Kimberly - US English female voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Nicole" hs.setvoice("IVONA 2 Nicole - Australian English female voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Russell" hs.setvoice("IVONA 2 Russell - Australian English male voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Salli" hs.setvoice("IVONA 2 Salli - US English female voice [22kHz]","EAGLE54-HA:DEFAULT") Case "Hazel" hs.setvoice("Microsoft Hazel Desktop - English (Great Britain)","EAGLE54-HA:DEFAULT") Case "Zira" hs.setvoice("Microsoft Zira Desktop - English (United States)","EAGLE54-HA:DEFAULT") Case Else hs.WriteLogEx("SONOS TTS", "Voice Not Found: " & toSetName, "#ff0000") End Select End Sub '--------------------------------------------------------------------------- ' Other/Misc Speaking Commands '--------------------------------------------------------------------------- Sub speakSunset(parm As Object) hs.speak("Sunset is at " & hs.sunset & " tonight", True, "EAGLE54-HA:DEFAULT") End Sub Sub speakSunrise(parm As Object) hs.speak("Sunrise is at " & hs.sunrise, True, "EAGLE54-HA:DEFAULT") End Sub
Any less and it chops off the beginning of the TTS.
I did want to ask if you would help me out with a piece of my code:
' Set Speaker to Line-In of Master Bedroom Connect Amp
hs.TriggerEvent("SONOS LineIn Select")
Can you help me with the script to replicate the event in my picture:
Maybe by a CAPI action or someway that I can:
play audio output (variable1) using audio source (variable2)
Thank you
Chris
Comment