Announcement

Collapse
No announcement yet.

RepeatSpeak.vb - a script to repeatedly speak something

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    RepeatSpeak.vb - a script to repeatedly speak something

    This script repeatedly speaks a phrase until the requested maximum number of times or until the control device is turned off. The control device is a virtual device you can name anything you like. I use the device in HStouch screens so I can cancel the speech at any time by turning off the device. Useful for "nag announcements" that you want to keep going until someone responds. The device is automatically turned on and off by the script, so can be ignored unless you want to cancel the repeat early.

    You pass it four parameters:
    Parm 1 - what you want spoken
    Parm 2 - how many times to repeat it
    Parm 3 - how long to pause between repetitions (in seconds)
    Parm 4 - the device reference id of the control device
    Parm 5 - the speech client where it is to be spoken
    (if you want it on all clients, pass an asterisk as the client name)

    There is no error-trapping, so it will error-out if you pass the parms incorrectly. See below for an example of how to call it from an event.

    I created this for my use and just thought I'd share.

    Code:
    ' RepeatSpeak.vb
    '   Parm 1 - what you want spoken
    '   Parm 2 - how many times to repeat it
    '   Parm 3 - how long to pause between repetitions
    '   Parm 4 - the device reference id of the control device
    '   Parm 5 - the speech client where it is to be spoken
    '            (if you want it on all clients, pass an asterisk as the client) 
    
    Sub Main(ByVal parm as object)
    
      Dim Client as string
      Dim counter_value as integer = 0
      Dim Delay as integer
      Dim Device as integer
      Dim HScomputerName = Environment.MachineName
      Dim parms() As String
      Dim pClient as string
      Dim Phrase as string
      Dim Repeats as integer
    
     
      parms = Split(parm.ToString,",") 
      Phrase = parms(0)
      Repeats = parms(1)
      Delay = parms(2)
      Delay = Delay * 1000   'multiply passes seconds by 1000 to get milliseconds
      Device = parms(3)
      pClient = parms(4)
    
      'If passed speech client is null or blank, use *
      If pClient = "" OR pClient = " " Then
        pClient = "*"
      End if
    
      Client = HScomputerName + ":" + pClient
    
      hs.WriteLog("Test Script", "phrase: " & phrase)
      hs.WriteLog("Test Script", "repeats: " & repeats)
      hs.WriteLog("Test Script", "delay: " & delay)
      hs.WriteLog("Test Script", "device: " & device)
      hs.WriteLog("Test Script", "client: " & client)
    
      ' Set on the control device
      hs.SetDeviceValueByRef(Device, 1, True)
    
      ' If the control device is on, continue
      If hs.DeviceValue(Device) > 0
    
        ' Loop as long as the control device is on and the counter is less than 25
        Do While hs.DeviceValue(Device) > 0 and counter_value < Repeats
    
    	hs.Speak(Phrase, True, Client)
    
    	counter_value = counter_value + 1
    
    	' pause milliseconds
    	System.Threading.Thread.Sleep(Delay)
    
        Loop
    
      End if
    
      ' Set off the control device
      hs.SetDeviceValueByRef(Device, 0, True)
    
     End Sub
    Here's an example of calling it from an event.
    Attached Files
    Fred

    HomeSeer Pro 3.0.0.548, HS3Touch, Zwave 3.0.1.252, Envisalink DSC 3.0.0.40, WeatherXML, Z-stick, HS phone, Way2Call

    #2
    Thanks, Fred!
    Steve

    (System configuration is in my profile)

    Comment


      #3
      Please destroy this script immediately! If my wife ever figures out how to use it, the supplemental nagging will ruin me.
      Mark

      Comment


        #4
        Originally posted by Mark S. View Post
        Please destroy this script immediately! If my wife ever figures out how to use it, the supplemental nagging will ruin me.
        Fred

        HomeSeer Pro 3.0.0.548, HS3Touch, Zwave 3.0.1.252, Envisalink DSC 3.0.0.40, WeatherXML, Z-stick, HS phone, Way2Call

        Comment


          #5
          The script can also be used to repeat-play an audio file by passing the relative path name in the Phrase parm. Example event parameters: Media\Chime3.wav,4,4,228,*
          would play the Chime3.wav file found in the HS3 sub-directory Media.
          Fred

          HomeSeer Pro 3.0.0.548, HS3Touch, Zwave 3.0.1.252, Envisalink DSC 3.0.0.40, WeatherXML, Z-stick, HS phone, Way2Call

          Comment

          Working...
          X