Dim MyAgent, Merlin, InitLoop, WhatToDo, FirstLoop, AnimateIt, WhatToSay, X, Y, VoiceChoices, NewVoice 

Set WshShell = WScript.CreateObject("WScript.Shell")
On Error Resume Next
Set MyAgent = CreateObject("Agent.Control.1")
If IsObject(MyAgent) Then
  MyAgent.Connected = True
  On Error Resume Next
  MyAgent.Characters.Load "Merlin", "C:\WINNT\msagent\chars\Merlin.acs"
  Set Merlin = MyAgent.Characters ("Merlin")
  Merlin.TTSModeID = "{CA141FD0-AC7F-11D1-97A3-006008273000}"  
End If

InitLoop = True

Do
  If InitLoop Then
    Merlin.Show
    Merlin.MoveTo 100, 177
    Merlin.Greet
    Wscript.Sleep 1000
    Merlin.Speak("Hello! My name is Merlin. I'm a Microsoft Agent.")
    Merlin.Speak("I can do plenty of tricks. Would you like to see some of them? ")
    Merlin.Play("GestureLeft")
    Merlin.Speak("If so, simply type a number in the text box below and click OK")
    Wscript.Sleep 6000
  Else
   Merlin.MoveTo 100, 177
   Merlin.Speak("What would you like me to do now?")
   Merlin.Play("GestureLeft")
   Wscript.Sleep 3000
  End If
   WhatToDo = InputBox("1) Demonstrate Animation Skills" & vbCrLf & vbCrLf &_
   "2) Talk to you" & vbCrLf & vbCrLf &_
   "3) Move around" & vbCrLf & vbCrLf &_
   "4) Change my voice"  & vbCrLf & vbCrLf &_
   "5) Quit", "Merlin Demonstration")

  Select Case WhatToDo
    Case "1" Call AnimateMerlin
    Case "2" Call TalkMerlin
    Case "3" Call MoveMerlin
    Case "4" Call VoiceMerlin
    Case "5"
    Case ""
  End Select
  
  InitLoop = False

Loop Until WhatToDo = 5 or WhatToDo = ""

Merlin.Play("Wave")
Merlin.Speak("Goodbye")

Set AnimationComplete = Merlin.Hide
Do Until AnimationComplete.Status = 0
Wscript.Sleep 100
Loop
Set Merlin = Nothing
MyAgent.Characters.Unload "Merlin"
Wscript.Quit
                   
Sub AnimateMerlin

  AnimationSample = "Please type one of these animations in the text box below:" & vbCrLf & vbCrLf &_
  "Alert               Announce       Blink" & vbCrLf &_
  "Confused       Congratulate   Decline" & vbCrLf &_
  "DoMagic1      Explain           GestureDown" & vbCrLf &_
  "GetAttention   Greet              Idle1_1" & vbCrLf &_
  "Pleased          Process         Read" & vbCrLf &_
  "Sad                Search           Suggest" & vbCrLf &_
  "Surprised        Think             Write" & vbCrLf

   FirstLoop = True
   Do
    If FirstLoop Then
      Merlin.Speak("Here is a sample list of my animation skills. What animation would you like me to demonstrate for you?")
    Else
      Merlin.Speak("What animation would you like me to demonstrate for you now?")
    End If
    Merlin.Play("GestureLeft")
    Wscript.Sleep 3000
    AnimateIt = InputBox(AnimationSample, "Merlin's Animation Skills")
    If AnimateIt = "" Then Exit Do
    Merlin.Speak("This is how I do " & AnimateIt & ".")
    Merlin.Play(AnimateIt)
    Wscript.Sleep 7000
    FirstLoop = False
  Loop Until AnimateIt = ""

End Sub

Sub TalkMerlin

   FirstLoop = True
   Do
    If FirstLoop Then
      Merlin.Speak("I can recite anything that you want me to. What would you like me to say?")
    Else
      Merlin.Speak("What would you like me to say now?")
    End If
    Merlin.Play("GestureLeft")
    Wscript.Sleep 3000
    WhatToSay = InputBox("Please type a phrase in the text box:"  & vbCrLf & vbCrLf &_
    "Or click Cancel to exit", "Merlin's Speaking Skills")
    If WhatToSay = "" Then Exit Do
    Merlin.Speak(WhatToSay )
    Wscript.Sleep 4000
    FirstLoop = False
  Loop Until WhatToSay = ""

End Sub

Sub MoveMerlin

FirstLoop = True

Do
  Merlin.Play("Uncertain")
  If FirstLoop Then
          Merlin.Speak("I can move to any location on the screen. Where would you like me to go?")
    Else
          Merlin.Speak("Where would you like me to go now?")
  End If
  Wscript.Sleep 3000
  X = InputBox("Please type the X coordinate here: ", "Merlin's Moving Skills")
  If X = "" Then Exit Do
  Y = InputBox("Please type  the Y coordinate here: ", "Merlin's Moving Skills") 
  Merlin.MoveTo X, Y
  Merlin.Speak("Here I am at position " & X &", " &Y)
  Wscript.Sleep 7000
  FirstLoop = False
Loop Until X = "" 

End Sub


Sub VoiceMerlin

VoiceChoices = "Please select a voice" & vbCrLf & vbCrLf &_
"1) Adult Male #1" & vbCrLf &_
"2) Adult Male #2" & vbCrLf &_
"3) Adult Male #3" & vbCrLf &_
"4) Adult Male #4" & vbCrLf &_
"5) Adult Male #5" & vbCrLf &_
"6) Adult Male #6" & vbCrLf &_
"7) Adult Male #7" & vbCrLf &_
"8) Adult Male #8"& vbCrLf &_
"9) Adult Female #1" & vbCrLf &_
"10) Adult Female #2"

Merlin.Speak("I have ten voices that I can use." )

FirstLoop = True

Do
    If FirstLoop Then
       Merlin.Speak("Which voice would you like to hear me speak with?" )
    Else
      Merlin.Speak("Which Voice would you like to hear me speak with now?" )
    End If
  Wscript.Sleep 3000
  Merlin.Play("GestureLeft")
  SelectVoice = InputBox(VoiceChoices, "Merlin's Voice Skills")

  Select Case SelectVoice
    Case "1" NewVoice = "{CA141FD0-AC7F-11D1-97A3-006008273000}"
                  Voice = "Adult Male #1"
    Case "2" NewVoice =  "{CA141FD0-AC7F-11D1-97A3-006008273001}"
                  Voice = "Adult Male #2"
    Case "3" NewVoice =  "{CA141FD0-AC7F-11D1-97A3-006008273002}"
                  Voice = "Adult Male #3"
    Case "4" NewVoice =  "{CA141FD0-AC7F-11D1-97A3-006008273003}"
                  Voice = "Adult Male #4"
    Case "5" NewVoice =  "{CA141FD0-AC7F-11D1-97A3-006008273004}"
                  Voice = "Adult Male #5"
    Case "6" NewVoice =  "{CA141FD0-AC7F-11D1-97A3-006008273005}"
                  Voice = "Adult Male #6"
    Case "7" NewVoice =  "{CA141FD0-AC7F-11D1-97A3-006008273006}"
                  Voice = "Adult Male #7"
    Case "8" NewVoice =  "{CA141FD0-AC7F-11D1-97A3-006008273007}"
                  Voice = "Adult Male #8"
    Case "9" NewVoice =  "{CA141FD0-AC7F-11D1-97A3-006008273008}"
                  Voice = "Adult Female #1"
    Case "10" NewVoice = "{CA141FD0-AC7F-11D1-97A3-006008273009}"
                    Voice = "Adult Female #2"
    Case Else Exit Do
  End Select


Merlin.TTSModeID = NewVoice
Merlin.Speak("I am now using the voice " &Voice)
Merlin.Speak("Let me demonstrate by telling you a joke.")
Merlin.Play("Explain")
Merlin.Speak("Did you know that independent studies have discovered that the internet is an addictive agent which, they say, is just as powerful as drugs or alcohol?")
Merlin.Speak("It's true!")
Merlin.Speak("However, researchers go on to say that the internet is actually much more dangerous than those addictive substances because it's a...")
Merlin.Speak("...terminal addiction.")
Merlin.Play("Pleased")
Merlin.Speak("Ha Ha Ha!")


FirstLoop = False

Loop Until SelectVoice = "" 

End Sub



