Announcement

Collapse
No announcement yet.

Random Speak a line.

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

    #16
    Solved my problem anyway.

    Command:
    &hs.runscriptfunc("SpeakRandomLine.vb","Main","Scripts\Data\ Speak Time Attitude.txt|It's $Time{silence msec='250'}|Homeseer",False,False)

    Result:
    PHP Code:
         Feb-21 1:01:09 PM     TTS  Speak (Homeseer):It's 1:01 PM. Keep in mind that neither success nor failure is ever final. 
         Feb-21 1:01:07 PM     System  Control Panel Immediate Script: &hs.runscriptfunc("SpeakRandomLine.vb","Main","Scripts\Data\Speak Time Attitude.txt|It'
    s $Time{silence msec='250'}|Homeseer",False,False) 
    Real courage is not securing your Wi-Fi network.

    Comment


      #17
      A note. Once we're both happy, I'll clean up a bit and then post this in the library. It'll be called "Speak Random Line" (SpeakRandomLine.zip).
      Real courage is not securing your Wi-Fi network.

      Comment


        #18
        Sorry it took so long, We are having a snow storm and I have Honey-Dos to get done.

        It worked with my current set of parameters. I'll play with it some, but looking good!

        Comment


          #19
          Originally posted by ViperJD View Post
          Sorry it took so long, We are having a snow storm and I have Honey-Dos to get done.

          It worked with my current set of parameters. I'll play with it some, but looking good!
          We're expecting that storm tonight/tomorrow. Snow over night then well above freezing early tomorrow morning with tons of rain. Like I need either. It's going to be a huge mess.

          Glad to hear it's working as expected. I'll start cleaning it up some and get it into the library. For me, this has replaced three (so far) similar scripts I'd written for slightly different purposes.
          Real courage is not securing your Wi-Fi network.

          Comment


            #20
            Originally posted by Wadenut View Post
            We're expecting that storm tonight/tomorrow. Snow over night then well above freezing early tomorrow morning with tons of rain. Like I need either. It's going to be a huge mess.

            .

            That's some storm on the radar. Stretching from Ottawa to Houston. Just started snowing here on the Jersey shore. Thankfully we've climbed out of the freezer (-19C the last two nights) all the way up to shorts weather (-3C).
            cheeryfool

            Comment


              #21
              Here's my version (only changing the comment header):

              Code:
              '  -----------------------------------------------------------------------------------------------------------
              '        Random Speech Generator 
              '            by Wadenut (HomeSeer Forum User)
              '  -----------------------------------------------------------------------------------------------------------
              '  File: SpeakRandomText.vb
              '  --------------------------------
              '
              '  This script will generate "random" speech based on a list text file.
              '  Example: under "Scripts\Data\" create a file called "SayHello.txt" and add a number of lines to it like:
              '	Hello
              '	Hi
              '	Hey there
              '	Good to see you
              '	Good day
              '
              '
              '   Parameters:
              ' 	"FileName|SayBefore|Host1,Host2..." 	' FileName, Line to speak before Random Line, Speaker Client List
              '  	"FileName|Host1,Host2..."  		' FileName, Speaker Client List
              ' 	"FileName"    				' FileName specified. All Speaker Clients.
              ' 	""     					' No Parameters SCRIPT WILL FAULT.
              '   Example:
              ' 	"Scripts\Data\Speak Time Attitude.txt|It's $Time{silence msec='250'/}|Homeseer,Nero,Android:Garage"
              '
              '   Selects file \Homeseer\Scripts\Data\Speak Time Attitude.txt
              '   Inserts the phrase It's $Time before the random text adding a short pause between.
              '   Speaks to hosts Homeseer,Nero and Android:Garage
              '   Parameter 1 must be present.
              '   Parameter 2 and 3 are optional.  If Hosts are required but no 'Before' Text is included, use format FileName||Hosts
              '
              '   Include replacement variables
              '    	$Time, $Date, $DV, $DS
              '
              '   Syntax Ex: ("SpeakRandomText.vb","Main","Scripts\Data\SayHello.txt|Jeanette, you say goodbye, but I say |FAMILY-PC:default",false,false)
              '     This example executes the SpeakRandomText.vb using SayHello.txt (under Scripts\Data\) as the source list and 
              '     has says the Jeanette...Text before and the random "hello" afterwards  
              ' 
              '   Control Panel ex: &hs.RunScriptFunc("SpeakRandomText.vb","Main","Scripts\Data\SayHello.txt|Jeanette, you say goodbye, but I say |FAMILY-PC:default",false,false) 
              '	 
              '  -----------------------------------------------------------------------------------------------------------
                
                Try
                Dim Hosts As String
                Dim RandomNum As New Random '(System.DateTime.Now.Millisecond)
                Dim Choice,Count As Integer
                Dim SayFile As String = hs.GetAppPath + "\" 
                Dim SpeakAry() As String
                Dim Say As String
                Dim SayBefore As String = ""
                Dim ParmAry() As String
                
                If InStr(FileAndHosts,"|") > 0 Then
                 ParmAry = Split(FileAndHosts,"|")
                 If UBound(ParmAry) > 1 Then
                  ' Includes filename + SpeakBefore + Hosts
                  SayFile = SayFile + ParmAry(0)
                  SayBefore = ParmAry(1)
                  SayBefore = Replace(SayBefore,"{","<")
                  SayBefore = Replace(SayBefore,"}",">")
                  Hosts = ParmAry(2)
                 Else
                  ' Includes FileName + Hosts
                  SayFile = SayFile + ParmAry(0)
                  Hosts = ParmAry(1)
                 End If
                Else
                 ' Contains only FileName
                 SayFile = SayFile + FileAndHosts
                 Hosts = ""
                End If
                 Randomize
                Count = 0
                Dim fobjCount As New System.IO.StreamReader(SayFile)
                Do While fobjCount.Peek() >= 0
                 Count = Count + 1
                 Redim Preserve SpeakAry(Count)
                 SpeakAry(Count) = fobjCount.ReadLine()
                Loop
                fobjCount.Close()
                fobjCount.Dispose()
                 Choice = Int(RandomNum.Next(1,Count))
                If InStr(SpeakAry(Choice),"(") > 0 Then 
                 Say = SayBefore + mid(SpeakAry(Choice),1,InStr(SpeakAry(Choice),"(")-1)
                Else
                 Say = SayBefore + SpeakAry(Choice)
                End If
                hs.Speak(Say,True,Hosts)
                RandomNum = Nothing
                SpeakAry = Nothing
               Catch ex As Exception
                hs.Writelog("SpeakRandomLine",ex.Message)
               End Try
              End Sub
              NICE WORK! Thanks again!

              Comment


                #22
                My pleasure. It was either work on this today or watch the snow fall
                The final script is here: http://board.homeseer.com/showthread...43#post1163743
                Real courage is not securing your Wi-Fi network.

                Comment


                  #23
                  Just an FYI:
                  &hs.RunScriptFunc("rn_SpeakRandomText.vb","Main","Scripts\Da ta\rn_SayHello.txt|It's $Time <silence msec='250'/> |FAMILY-PC:default",false,false)

                  works. No need to use and replace {}. Not sure if there is another place where you would need to use {} instead the direct <>.

                  Comment


                    #24
                    Originally posted by ViperJD View Post
                    Just an FYI:
                    &hs.RunScriptFunc("rn_SpeakRandomText.vb","Main","Scripts\Da ta\rn_SayHello.txt|It's $Time <SILENCE msec="250" />|FAMILY-PC:default",false,false)

                    works. No need to use and replace {}. Not sure if there is another place where you would need to use {} instead the direct <>.
                    You would normally use < & /> in the parameter when specifying some SAPI directive, like the pause I use in the examples.
                    I used the { & } characters as a replacement for < & /> because HS or the browser (IE at least) tends to interpret the latter, when used as part of an event action, as HTML, which it is actually, and not display anything between the brackets when you look at the event later. The script substitutes { } with < & /> before processing the speech.

                    In an immediate script, I think you'd see the same behaviour if you look at your immediate script later, even though HS does seem to execute the SAPI directives as it should.

                    Within a script, you could actually enter the HTML characters and everything would be fine unless you happened to edit the script using HS's internal editor then re-save the script. If that happened, the HTML would seem to disappear and you'd end up scratching your head for a very long time (been there).

                    BTW: If, in your example, you included HTML, I'm not seeing it.

                    Here is my original example
                    using braces: It's $Time{silence msec='250'}

                    and using HTML:
                    It's $Time <silence msec='250'/>
                    Believe me, the characters are there.
                    Real courage is not securing your Wi-Fi network.

                    Comment

                    Working...
                    X