Windows Scripting Forums

Full Version: Mr. Chatbot
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A fun code for the kids. I have been playing with this for awhile. I am an amateur at writing scripts. This works pretty good if you have the correct sapi voices. Run the description code first to see what's on your PC. Probably only works for Microsoft OS though.

Description Code:
    VBS Programming
  1. Set VObj = CreateObject("SAPI.SpVoice")
  2. For Each Voice In VObj.getvoices
  3. I = I + 1
  4. msgbox "" & (I - 1) & " - " & Voice.GetDescription
  5. Next



Mr. Chatbot Code:
    VBSCRIPT Programming
  1. Set Vobj = CreateObject("SAPI.SpVoice")
  2. With Vobj
  3.  
  4. strName = InputBox("Please choose a voice:" & vbCr & vbCr & "Sam" & vbCr & "Mike" & vbCr & "Mary", "Question:")
  5.  
  6. Select Case LCase(strName)
  7. Case "sam"
  8. Set .voice = .getvoices.item(0)
  9. .Volume = 100
  10. .Rate = -3
  11. Case "mike"
  12. Set .voice = .getvoices.item(1)
  13. .Volume = 100
  14. .Rate = -3
  15. Case "mary"
  16. Set .voice = .getvoices.item(2)
  17. .Volume = 100
  18. .Rate = -3
  19. 'Case "Sample TTS"
  20. ' Set .voice = .getvoices.item(3)
  21. ' .Volume = 100
  22. ' .Rate = -3
  23. Case ""
  24. WScript.echo "please type a name:"
  25. End Select
  26.  
  27. strText = "Hello, my name is " & strName & ". I am a chatbot. Jim created me. What's your name?"'"O.K. See you later then, " & fname & "."
  28. Vobj.speak strText
  29.  
  30. fname=InputBox("What's your name?" , "Mr. Chatbot")
  31. strText = "How are you feeling, " & fname & "?" '"O.K. See you later then, " & fname & "."
  32. Vobj.speak strText
  33. ffeeling=InputBox("How are you feeling?" , "Mr. Chatbot")
  34. strText = "Why are you feeling " & ffeeling & "?"
  35. Vobj.speak strText
  36. fanswer=InputBox("Why are you feeling " & ffeeling & "?" , "Mr. Chatbot")
  37. strText = "Sometimes I feel like that too. What's your favorite color, " & fname & "?"
  38. Vobj.speak strText
  39. fcolor=InputBox("What's your favorite color?" , "Mr. Chatbot")
  40. strText = "I like " & fcolor & ", too. What's your favorite number " & fname & "?"
  41. Vobj.speak strText
  42. fnumber=InputBox("What's your favorite number?" , "Mr. Chatbot")
  43. strText = (fnumber & " is my favorite number too, " & fname & "That is so Cool. We have a lot in common. What else do you like?")
  44. Vobj.speak strText
  45. felse=InputBox("What else do you like?" , "Mr. Chatbot")
  46. strText = "I like " & felse & "too. What is your favorite food, " & fname & "?"
  47. Vobj.speak strText
  48. ffood=InputBox("What is your favorite food?" , "Mr. Chatbot")
  49. strText = "I don't like " & ffood & ". I am a computer. I can't eat food. What is your favorite movie?"
  50. Vobj.speak strText
  51. fmovie=InputBox("What's your favorite movie?" , "Mr. Chatbot")
  52. strText = "Sometimes I have movies on me. I don't think I have ever seen " & fmovie & ". What is your favorite sport " & fname
  53. Vobj.speak strText
  54. fsport=InputBox("What is your favorite sport?" , "Mr. chatbot")
  55. strText = "I can't play " & fsport & "I am a computer. I would rather surf the internet. When you play " & fsport & "you must get thirsty. What is your favorite drink?"
  56. Vobj.speak strText
  57. fdrink=InputBox("What is your favorite drink?" , "Mr. Chatbot")
  58. strText = "Is " & fdrink & "good? Because I can't have fluids. Or I Would Blow Up. What's your favorite game to play?"
  59. Vobj.speak strText
  60. fgame=InputBox("What's your favorite game to play?" , "Mr. Chatbot")
  61. strText = "I have games on me that you could play some day. I don't know if I have " & fgame & "on me but you could look sometime. " & fname & "Did you like talking to me?"
  62. Vobj.speak strText
  63. flike=InputBox("Did you like talking to me?" , "Mr. Chatbot")
  64. strText = "O.K. See you later then, " & fname & ". I will always be here if you need some one to talk to."
  65. Vobj.speak strText
  66. MsgBox("GoodBye, " & fname & "!!!") , , "Mr. Chatbot"
  67. End With

Reference URL's