Announcement

Collapse
No announcement yet.

Enter text in HStouch Text box and speak it via speaker clients

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

    Enter text in HStouch Text box and speak it via speaker clients

    Use case: when I am away from home, I'd like to input text in a HStouch text box, press a button and have HS speak out loud the text string.

    I have created a text box in HSTOUCH where a user can input text, let's call it "textbox1"

    I have created a button that tiggers: "HomeSeer: Run a HomeSeer script with values from elements(s)"

    Click image for larger version

Name:	Capture.JPG
Views:	169
Size:	60.4 KB
ID:	1350693

    The script is as follows


    Public Sub Main(ByVal Parms As Object)

    Dim ParmArray() As String
    ParmArray = Parms.ToString.Split("|")
    hs.Speak(ParmArray(0))
    hs.WriteLog("SpeakAndLogMultipleParms", ParmArray(1))

    End Sub



    Click image for larger version

Name:	Capture2.JPG
Views:	139
Size:	101.1 KB
ID:	1350694
    (I know this is for two values but should work when only one value is provided, tested manually and it works)


    When I enter text in "textbox1" and press the button to trigger the script, what I hear is something like

    "System dot string" ?

    No errors in Log.

    I guess the script is wrong, can you provide assistance?

    Thank you!






    #2
    There is no reason to have this as a public sub. you also don't need the Main in the sub or function cell for the event as this is the default. This has caused me problems in the past. You also only have 1 parameter you are passing in HSTouch. Your event has no parameters. This is going to cause a problem on the stack. I think you want to call the event from HS Touch. A replacement variable can contain the text in the textbox.

    Events and HSTouch handle the calling of scripts differently. I'll get back to you tomorrow morning with a more detailed how-to.

    Comment


      #3
      Thanks AllHailJ, since I'm just starting with VBscripts, I was reusing a script template from another post so I was expecting some errors;
      Let me know what should be changed when you have a chance, I'll test it out,
      Cheers,

      Comment


        #4
        Calls from an HS Event will only pass one string. However, calls from HS Touch will pass an Array of Strings. (Declare the input parameter as Object is correct, since it allows both types of input).

        However, you need to determine in code which type of parameter is being passed.

        Code:
        Sub Main(parms As Object)
          If parms.GetType().ToString = "System.String" Then
            ' Call was from HS, one string. Use string split to get individual parameters
          Else
           ' Call was from HS touch. Use parms(0).ToString to get first parameter, parms(1).ToString to get second, etc
          End If
          ...
        End Sub

        Comment


          #5
          First - I am running linux so I do not speak to my clients with hs.speak so I cannot fully test. It is slightly more convoluted. That being said it does write to the log and there are no errors.

          First here is the text version of the script so you can cut and paste. This works from an event or from HSTouch

          -----------------------------------------------
          REM - SpeakHSTouch script that will work from both event and HSTouch
          REM - 12/31/2019
          REM - The Script is expecting two parameters. One the text spoken and 2 text to be written to the log

          IMPORTS System.Core

          Sub Main(parms As Object)

          Dim parm0, parm1 As String
          Dim sParm() As String

          If parms.GetType().ToString = "System.String" Then

          parm0 = parms.ToString()

          Else

          parm0 = parms(0).ToString() & "|" & parms(1).ToString()

          End If ' Now use parm as your input variable...

          sParm = Split(parm0, "|", -1, 1) 'Split the parameters

          hs.speak(sParm(0)) 'Speak the text - first parameter
          hs.writelog("Speak",sParm(1)) 'Write the text to the log

          End Sub
          --------------------------------------------------------------------------

          here is the script called from an event.

          Click image for larger version

Name:	Screenshot from 2019-12-31 10-11-31.png
Views:	126
Size:	80.3 KB
ID:	1350823

          Notice that the are two parameters in the 'Parameters' box and they are separated by a "|"

          To call the same script from HSTouch the

          Click image for larger version

Name:	Screenshot from 2019-12-31 10-15-28.png
Views:	105
Size:	363.7 KB
ID:	1350824

          The "Speak To Me" is TestBox and "Write to Log" is TestBox1 (excuse my typo's)

          If you only want 1 parameter the script would look like this


          -----------------------------------------------
          REM - SpeakHSTouch script that will work from both event and HSTouch
          REM - 12/31/2019
          REM - The Script is expecting one parameter.

          IMPORTS System.Core

          Sub Main(parms As Object)

          Dim parm0 As String
          Dim sParm() As String

          If parms.GetType().ToString = "System.String" Then

          parm0 = parms.ToString()

          Else

          parm0 = parms(0).ToString()

          End If ' Now use parm as your input variable...

          hs.speak(parm0) 'Speak the text - first parameter
          hs.writelog("Speak",parm0) 'Write the text to the log

          End Sub
          --------------------------------------------------------------------------

          Hope this helps explain what is going on

          Comment


            #6
            Thank you, works perfectly;
            Slowly learning new scripting concepts...
            Happy new year!

            Comment

            Working...
            X