Announcement

Collapse
No announcement yet.

Randomize waves?

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

    Randomize waves?

    Is it possible to have a random wave played from a directory?

    --------------
    -=A.J. Griglak

    #2
    Its very funny you asked this. I am currently writing a script that will speak the time and temperature every half an hour that plays a random was file and then speaks the time and temperature. I have my own wether station and its kinds neat knowing the temperature throughtout the day. As far as the random wav goes give this a try:

    <pre class="ip-ubbcode-code-pre">
    sub main()


    dim r, strPathX


    ' Set r to zero
    r=0

    ' Set the path to the wav files
    strPathX = "c:\program files\homeseer\html\wavs"

    ' Create our FSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    ' Get a handle on our folder
    Set objFolder = objFSO.GetFolder(strPathX)


    ' Turn on the randomize function
    Randomize

    ' Set the upper limit of the random function to the number of files in the directory.
    upperlimit = objFolder.Files.count

    ' Set the lower limit to 1
    lowerlimit = 1

    ' Assign the random number to the wavfilenum variable
    wavfilenum = Int((upperlimit - lowerlimit + 1)*Rnd() + lowerlimit)


    ' Loop through the files until you get to the one the random function choose to play.
    For Each objItem In objFolder.Files
    r = r + 1
    if r = wavfilenum then
    wavfilename = objItem.name
    end if
    next


    ' Set the path to the wav file
    wavfile = "c:\program files\homeseer\html\wavs\" & wavfilename

    ' Play the wavfile
    hs.PlayWavFile wavfile

    ' Clear the object memory
    Set objFSO = Nothing
    Set objFolder = Nothing
    end sub
    </pre>

    -Rupp

    [This message was edited by Rupp on Monday, 06 January 2003 at 08:02 AM.]
    💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

    Comment


      #3
      Works "right out of the box!"

      When you sent that message requesting attention waves, I got looking through my waves... I realized I have over 8,000 sound files collected over the years. Didn't even know that I had that many... Most of them, I have no idea what they are from... attached is an example. [img]/infopop/emoticons/icon_biggrin.gif[/img]

      BTW, I was kinda kidding around when I sent those two waves in that other thread... ;-)

      --------------
      -=A.J. Griglak
      Attached Files

      Comment


        #4
        1. Is it possible to specify multiple directories, or have the script look in sub directories too?

        2. Anyway to have the wav play in the background? HS doesn't respond to anything else while the wav is playing.

        Not to make such a silly thing too complicated... ;-)

        Oh, BTW, there is no noticble delay in the script, event though it's going through over 8,000 waves! Cool!

        --------------
        -=A.J. Griglak

        Comment


          #5
          Just a couple ideas for you. Dont have time to be too elaborate.

          You traverse subdirectories using GetFolder & SubFolders. You can made it recursive and it will traverse folders within folders within folders etc.

          Set folder = objFSO.GetFolder(strPathx)
          for each subfldr in folder.SubFolders
          ...process/count all the files in this subfolder
          next

          Homeseer is a single thread process. There are some media methods in the scripting language that may provide the capability to play a wav then later check its status. Just dont know.

          The approach I would likely use is a different player that runs in a separate process. For example if the file was called up by a browser such as IE then it would play in the backgound and not slow down homeseer at all. For example homeseer would host a web page where the web page contains the random wav file select logic. It would feed the wav file to the client and determine how long it will take for the wav file to play and do a meta refresh so the client will ask for the next file when the curent one finishes playing. This just becomes another link on your homeseer web page. As long as you are sending sounds you might as well send random pictures to the browser in a slideshow format. Some audio / video associations may provide interesting results.

          Similiar things could be done with winamp, cdj, musicmatch, mediaPlayer etc. acting as the sound player rather than IE or other browser client.

          Comment


            #6
            Try this file. I switched to using hs.MEDIAPlay and this will allow HS to do other things while the media is playing.
            <pre class="ip-ubbcode-code-pre">
            sub main()


            dim r, strPathX


            ' Set r to zero
            r=0

            ' Set the path to the wav files
            strPathX = "c:\program files\homeseer\html\wavs"

            ' Create our FSO
            Set objFSO = CreateObject("Scripting.FileSystemObject")

            ' Get a handle on our folder
            Set objFolder = objFSO.GetFolder(strPathX)


            ' Turn on the randomize function
            Randomize

            ' Set the upper limit of the random function to the number of files in the directory.
            upperlimit = objFolder.Files.count

            ' Set the lower limit to 1
            lowerlimit = 1

            ' Assign the random number to the wavfilenum variable
            wavfilenum = Int((upperlimit - lowerlimit + 1)*Rnd() + lowerlimit)


            ' Loop through the files until you get to the one the random function choose to play.
            For Each objItem In objFolder.Files
            r = r + 1
            if r = wavfilenum then
            wavfilename = objItem.name
            end if
            next


            ' Set the path to the wav file
            'wavfile = "c:\program files\homeseer\html\wavs\" & wavfilename

            ' Play the wavfile
            'hs.PlayWavFile wavfile

            hs.MEDIAFilename = "c:\program files\homeseer\html\wavs\" & wavfilename
            hs.MEDIAPlay
            Do While hs.MEDIAIsPlaying
            hs.WaitEvents
            Loop
            end sub
            </pre>


            As far as traversing directories, it could be done but its a major pain and frankly I'm too lazy to do it. I have VB code that does it but my code requires global variables and vbscript doesn't support them. I could use createvar, getvar, delvar, etc but like I said I'm just to lazy to write the code.
            -Rupp
            💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

            Comment


              #7
              Michael:

              Interesting ideas! Right now, it's too advanced for me. I'll keep it in the back of my mind - especially when I fire up the dusty Audrey I've got sitting around!

              Rupp: Again, works out of the box! Just what I'm looking for.

              Now, when I leave the house, a goofy cartoon sound or a movie quote will be played. I like variety in my life, so there ya go!

              I'm going to try to use the same logic to have HS use random phrases when leaving - See ya, Take care, Drive safely, etc. But, I want to tackle that one myself!

              --------------
              -=A.J. Griglak

              Comment


                #8
                This script rocks - thanks so much!

                Comment

                Working...
                X