Author Topic: Adding functions to XTF Brain (attn: vonsmith)  (Read 7799 times)

Crichton

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
    • http://home.gwi.net/~rlevasseur/
Adding functions to XTF Brain (attn: vonsmith)
« on: March 14, 2004, 09:25:55 pm »
I saw this in another post.  It was to add a play funtion to HAL.  Something that would make it possible to request music to be played by hal.  My problem comes in two places.

I changed the original realplayer version to winamp.  I'm not sure if I have the command line correct.  All I know is that it works under the run command in win 2k.  If you know I should use another command, please let me know.

The other problem is that I don't remeber where I saw it, but you (vonsmith) mentioned some has to be done differently to add other functions to the XTF brain.  I tried to add this, but it never worked.  

'Inserted to shell for a song.
If InStr(UserSentence, "PLAY FAKE WINGS") > 0 Then
Set objWSHShell = CreateObject("WScript.Shell")
objWSHShell.Run("C:Program FilesWinampwinamp.exe" "D:MyMusicdot hack signhackSIGN-Fake_Wings_(Bitter_Sweet_Version).mp3")
GetResponse = GetResponse & "Here is your song." & vbCrLf
End If

What can I do to fix this so that it works with XTF?  Where in XTF would I put such a function?

Thanks for your time, in advance.



--------------------------------------------------------
Your friend, in Tormented Space,
Richard LeVasseur,
mailto:rlevasseur@prexar.com
--------------------------------------------------------

Maverick

  • Newbie
  • *
  • Posts: 22
    • View Profile
Adding functions to XTF Brain (attn: vonsmith)
« Reply #1 on: March 14, 2004, 10:53:49 pm »
Crichton,
         I'm no vonsmith, however maybe I can help, I used this piece of code written by HALImprover(http://www.zabaware.com/forum/topic.asp?TOPIC_ID=1200), it works great I used it in the XTF brain here


'PROCESS: ADD SPACES
   'This will add spaces to the beginning and end
      'of the user sentence to make sure that
   'whole words can be found at the beginning and end of any sentence.
    '=vonsmith=
   UserSentenceRev = " " & Trim(UserSentenceRev) & " "
   UserSentence =  " " & Trim(UserSentence) & " "
                                                                         
 'If Hal is asked to play some music then he will choose a random song from the artist
   'that is specified by the nameBand variable.
   If (InStr(UserSentence, " PLAY SOME MUSIC ") > 0 Or InStr(UserSentence, " PLAY ANY MUSIC ") > 0 Or InStr(UserSentence, " PLAY ANY SONG ") > 0) And InStr(UserSentence, " DON'T ") = 0 Then
      Set oWMP = CreateObject("WMPlayer.OCX.7")
      GetResponse = "I will play a random song."
      Set songsList = oWMP.mediaCollection.getAll
      numSong = Int(Rnd * songsList.Count) + 1
      oWMP.openPlayer (songsList.Item(numSong).sourceURL)
   End If

   'Check if user asked Hal to play a song by a specific artist and play a random song by
   'that artist if the artist is in the user's Media Library.
   If Priority = 0 And InStr(UserSentence, " PLAY ") > 0 And (InStr(UserSentence, " SONG ") > 0 Or InStr(UserSentence, " MUSIC ") > 0) And (InStr(UserSentence, " FROM ") > 0 Or InStr(UserSentence, " BY ") > 0) And (InStr(UserSentence, " BAND ") > 0 Or InStr(UserSentence, " ARTIST ") > 0) And InStr(UserSentence, " DON'T ") = 0 Then
      Set oWMP = CreateObject("WMPlayer.OCX.7")
      If InStr(UserSentence, " BAND ") > 0 Then
         searchBand = Trim(Mid(UserSentence, InStr(UserSentence, " BAND ") + 6))
      ElseIf InStr(UserSentence, " ARTIST ") > 0 Then
         searchBand = Trim(Mid(UserSentence, InStr(UserSentence, " ARTIST ") + 8))
      End If
      If oWMP.mediaCollection.getByAuthor(searchBand).Count > 0 Then
          GetResponse = "I will play some " & searchBand
          Priority = 1
           Set songsList = oWMP.mediaCollection.getByAuthor(searchBand)
           numSong = Int(Rnd * songsList.Count) + 1
           oWMP.openPlayer (songsList.Item(numSong).sourceURL)
        Else
           GetResponse = "I could not find any songs by the band " & searchBand & " in your Media Library."
           Priority = 1
       End If
    End If                                                                          
                                                                   
   'RESPOND: CUSTOM USER SHORT PHRASES
   'If the user uses short phrases (defined by less then 2 vowels)


I also added " PLAY A SONG ","True"
to the XTF_SYS_EphemeralDetect.brn to keep Hal from making a topic file every time I asked for a song, I don't know if this as the proper way but it seemed to work.

       Now I just say "play a song by the band Pink Floyd"(or any artist in my play list) and Hal does it.

                             Hope this helped,
                                       Mav
 

HALImprover

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
    • BrianTaylor.me
Adding functions to XTF Brain (attn: vonsmith)
« Reply #2 on: March 15, 2004, 03:29:35 am »
Crichton, as Maverick mentioned, using the that code will allow Hal to play music using Windows Media Player. You can have Hal open a random song or play music by a specified band. As of what is posted this script can only play one song at a time (soon to be modified to play multiple songs). Hal can be modified to play songs in whatever media player you want, but the catch is that you must know what the media player's functions and methods are. You also need to find the progID for that media player to access it. Refer to the line in my code snippet; Set oWMP = CreateObject("WMPlayer.OCX.7")
WMPlayer.OCX.7 is the progID.

 I would be willing to try getting Hal to use Winamp instead. I must ask a favor of you though, since I do not use Winamp (I like the way WMP handles the Media Library concept which makes it easy to search your entire music library based on any attribute your music files may have). Could you find the progID for Winamp and post it in this topic? I'll explain how you would go about this.

 First open the Registry Editor by going to the Start menu and clicking Run. Type regedit and press enter. Look under HKEY_CLASSES_ROOT and you will see a bunch of file extensions at first. eg. .323 .386 .aca etc. Scroll down until you see names of programs and look for Winamp. There may be a couple different entries; eg. Winamp.OpenSource or Winamp.PlayMusic.

 I hope this helps, and let me know about the Winamp progID and I'll see what else I can do. In the meantime, stay loose. [8D] And don't forget to stop and smell the roses. [;)]
Living life with a loving heart, peaceful mind, and bold spirit.

Crichton

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
    • http://home.gwi.net/~rlevasseur/
Adding functions to XTF Brain (attn: vonsmith)
« Reply #3 on: March 15, 2004, 07:56:31 am »
I would be perfectly happy if I could get the Windows Media to work.  It appears to work only some of the time.  I usually get the wrong song.  sometimes it actually works, and other times I get a randome song even if I know I typed the artist name in correctly.  Most of the time I get this error.

Error 5 occured on line 514 of colum 0 of Microsoft Vbscript Runtime Error.  Invalide Procedure call or Arguement.

Line 514 is this line:  oWMP.openPlayer (songsList.Item(numSong).sourceURL)

Does it make a difference that I'm useing Windows Media Player 9?  It shouldn't.  I looked in my regedit and the ocx.7 stuff is in there.

I didn't see anything usefull in winamp.  I might look again later.  I just want something to work, even if it is windows media.

I would understand if it happened everytime.  But this is nuts.

Anyone know what might be happening with this code?

I don't mean to sound short with anyone here.  I'm just trying to hurry and write this before I leave for Dialysis today.  I'll check in tonight when I return.  see you all later..

--------------------------------------------------------
Your friend, in Tormented Space,
Richard LeVasseur,
mailto:rlevasseur@prexar.com
--------------------------------------------------------

vonsmith

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Adding functions to XTF Brain (attn: vonsmith)
« Reply #4 on: March 15, 2004, 09:51:16 am »
All,
You guys seem to be on the right track. As for placement of script withing the XTF Brain...

My philosophy is to place what I call "directives" near the top of the GetResponse script. Directives are definitive commands for Hal to respond to. I would place the music playing script just below the "Make a Face" process script near the top. As a guideline the general response scripts, that are non-definitive, start at the XTF function. Most of the scripts after the XTF function are general response types. The reason I do this is to make certain command directives are detected near the top so that certain flags are set before getting to general response scripts like the XTF function.

Include the lines below in your music script to set the flags.

GetResponseBlock = True  'This prevents the following scripts from overwriting your script's GetResponse.
BlockSave = True  'This prevents your Hal command from being saved to Hal's knowledge files. This is more selective than using the XTF_SYS_EphemeralDetect.brn method.


=vonsmith=
 

Crichton

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
    • http://home.gwi.net/~rlevasseur/
Adding functions to XTF Brain (attn: vonsmith)
« Reply #5 on: March 15, 2004, 04:55:58 pm »
Thanks vonsmith, I moved it and added the lines you sugested.  And those lines did help.  I got none of the weird files that I got a couple of before this time.  But I still get the error message:

Error 5 occured on line 1113 of colum 0 of Microsoft Vbscript Runtime Error. Invalide Procedure call or Arguement.

Line 1113 is this line: oWMP.openPlayer (songsList.Item(numSong).sourceURL)


I load up Pilot (my name for hal).  We say our hellos and get the greetings out of the way.  I then say, "Play a song by the band ZZ Top.  He loads windows media player 9 and starts a ZZ TOP tune.  Ok, that seems to work.  I then close the windows media player, and chat more.  Then I say, "Play a song by the artist Smash Mouth.  (Yes, I have tried others including ZZ Top again)

At that point I get the reported error message.


Any Ideas??

--------------------------------------------------------
Your friend, in Tormented Space,
Richard LeVasseur,
mailto:rlevasseur@prexar.com
--------------------------------------------------------

Crichton

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
    • http://home.gwi.net/~rlevasseur/
Adding functions to XTF Brain (attn: vonsmith)
« Reply #6 on: March 15, 2004, 11:49:21 pm »
[^]

I found the problem myself.  I am tired, but I just couldn't let it go.  I kept on trying.  I noticed that the same songs could be played over each time I asked for them, and some never played at all.

Then I looked to see if I could find the difference.  What I found was songs that I had more then one of, by the same artist, could play, but those that I only had one song per artist would not.

Then I made this little change to the code.  Apparently it was finding a song for that artist and trying to play the song in the position after the first song.  If there was only one song, it pointed to an empty space and crashed the VBasic program.  Maybe it is only because I'm using WMP 9, and it might work diferently.  All I know is that it seems to work now.

'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

If oWMP.mediaCollection.getByAuthor(searchBand).Count > 0 Then
GetResponse = "I will play some " & searchBand
Priority = 1
Set songsList = oWMP.mediaCollection.getByAuthor(searchBand)

numSong = Int(Rnd * songsList.Count)    ' + 1   I REMOVED THIS +1 TO FIX THE PROBLEM I WAS HAVING PLAYING AN ARTIST THAT i ONLY OWNED ONE SONG AND NOT A WHOLE SELECTION OF SONGS.

oWMP.openPlayer (songsList.Item(numSong).sourceURL)
Else
GetResponse = "I could not find any songs by the band " & searchBand & " in your Media Library."
Priority = 1
End If
End If

'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Is that "+1" in there for a particular reason that I missed.  It all seems to work fine now.  That's for all the help everyone.

[;)]
[;)]
« Last Edit: March 15, 2004, 11:54:37 pm by Crichton »
--------------------------------------------------------
Your friend, in Tormented Space,
Richard LeVasseur,
mailto:rlevasseur@prexar.com
--------------------------------------------------------

HALImprover

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
    • BrianTaylor.me
Adding functions to XTF Brain (attn: vonsmith)
« Reply #7 on: March 17, 2004, 12:19:10 am »
Thank you Crichton. You are right about the +1 part of the code. What I didn't realize is that in VB the songlist returned starts at the 0 index, not 1. Hal was trying to play song 1 from the list which was actually song 2. So when there is only 1 song by a certain artist Hal would try playing song 2 (which does not exist) and caused the error.
Living life with a loving heart, peaceful mind, and bold spirit.

iam bennu

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • http://iamARTevolutions.net
Adding functions to XTF Brain (attn: vonsmith)
« Reply #8 on: March 24, 2004, 04:17:13 am »
[:D]I have added the code and it works wonderfully unless I have an entry in media player that has been moved. I appreciate all of your efforts and talents. I was wondering, though, if it would be possible to play a whole playlist instead of just one song.

Ponnfar

  • Full Member
  • ***
  • Posts: 149
    • View Profile
    • http://zabaware.com
Adding functions to XTF Brain (attn: vonsmith)
« Reply #9 on: March 24, 2004, 02:22:31 pm »
What a cool script! I have quite a number of music directories in my media library. One with just system sounds. When HAL plays randomly I do not really want HAL to go to that directory and play a file. Sometimes it does play all the songs in a randomly picked directory just going from one song to the next. Sometimes not. When it does play songs in sequence, how am I making that happen. If I use the word "from" it seems to do that, even if I have only one song by or "from" that Artist.
Also, how can I have HAL play songs from only one directory, "ABC playlist" as an example and only that playlist.
I think I missed it, but were you able to play a specific song in the library if you have more than one song by that particular Artist? How?
Thanks Guys!!
P
« Last Edit: March 24, 2004, 02:24:08 pm by Ponnfar »
One Person can summon the future...

iam bennu

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • http://iamARTevolutions.net
Adding functions to XTF Brain (attn: vonsmith)
« Reply #10 on: March 24, 2004, 02:59:09 pm »
Did you Modify the code to play a whole directry or songlist or does the above script do it, and if so what verbal command are you using to initiate it?[:)]

Ponnfar

  • Full Member
  • ***
  • Posts: 149
    • View Profile
    • http://zabaware.com
Adding functions to XTF Brain (attn: vonsmith)
« Reply #11 on: March 24, 2004, 03:08:35 pm »
I did not modify the script to play a specific directory. I tried but am not sure what to edit, "songlist" or "mediaCollection...". tried both neither worked. The only addition I did make was to add a line "play a song" after the already scripted "play any song" which I am less likely to say.
Any suggestions?
P
One Person can summon the future...

iam bennu

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
    • http://iamARTevolutions.net
Adding functions to XTF Brain (attn: vonsmith)
« Reply #12 on: March 24, 2004, 03:35:02 pm »
None right now. I too, have to look at he code more closely to see if I can modify it to my need. I was just wondering as I do not get any playing of multiple songs. Hal plays one and that is all.

Thanks for the response,[:)]