Asked — Edited

Creating A Simple Robot Brain

Building on Justin's thread on creating a brain. There are many ways to create artificial intelligence and this is just what I have come up with using the tools ARC has currently available.

I have designed my project to be Service/Agent based. When the Robot is powered up the connection script launches the init script.


ControlCommand("Script Manager", ScriptStart, "Init")

This initializes all variables and launches the Voice Service and the Auditory Service and unpauses the Speech Recognition plugin. The only Speech Recognition phrase I have entered here is the robot's name and the is UNAS (meaning First One) Stargate SG1 fans will have known that. And that script looks like this:


ControlCommand("Speech Recognition", PauseOn)
ControlCommand("Bing Speech Recognition", StartListening)

As you can see when the Robot hears his name "UNAS", it pauses the speech recognition module and starts Bing Speech listening.

Here is the Bing Speech Script


ControlCommand("Bing Speech Recognition", StopListening)
WaitFor($IsListening = 1)
ControlCommand("Speech Recognition", PauseOff)

As again you can see after the speech has been captured the script stops Bing speech listening and unPauses Speech Recognition.

The WaitFor($IsListening = 1) we will see later in other scripts for now we can just ignore that line.

Now to the fun part:

The Auditory Service's first line is waiting for the $BingSpeech variable to change and when it does that is when the magic happens.


:AuditoryService
#The Auditory service monitors the $BingSpeech variable for speech and then routes this speech to
#the proper Agent for processing.
#
#***************************************
WaitforChange($BingSpeech)
$HumanSaid = $BingSpeech
$BingSpeech = ""
$IsListening = 0
#***************************************
#Convert the first letter of the captured speech to lower case
$Trash = $HumanSaid
ControlCommand("Agents",ScriptStartWait,"ConvertToLowercase")
$HumanSaid = $Trash
#***************************************

When the $BingSpeech variable changes, its contents are saved in the $HumanSaid variable and the $BingSpeech variable is cleared. Here is where we see the $IsListening variable set to 0 letting the other scripts know that the robot is currently processing and not listening.

The next few lines converts the first letter of the spoken speech to lowercase, you will see why later.

Next the script goes thru a bunch of if statements.


#BlankCanBlank
if(Contains($HumanSaid," can ") & !Contains($HumanSaid,"What can "))
  ControlCommand("Agents",ScriptStartWait,"BlankCanBlank")
#CanBlankBlank
elseif(Contains($HumanSaid,"can ") & !Contains($HumanSaid,"What can ") & !Contains($HumanSaid," can "))
  ControlCommand("Agents",ScriptStartWait,"CanBlankBlank")
#BlankHaveBlank
elseif(Contains($HumanSaid,"have") & !Contains($HumanSaid,"Do "))
  ControlCommand("Agents",ScriptStartWait,"BlankHaveBlank")
#BlankIsInBlank
elseif(Contains($HumanSaid,"is in"))  
  ControlCommand("Agents",ScriptStartWait,"BlankIsInBlank")
#BlankIsThePluralOfBlank
elseif(Contains($HumanSaid,"is the plural of") & !Contains($HumanSaid,"what ")) 
  ControlCommand("Agents",ScriptStartWait,"BlankIsThePluralOfBlank")

I did not include the entire script just enough for a good example So the if statements look at the speech phrase for specific words in specific orders and calls the corresponding Agent. For example we will use the following speech phrase "dogs can run" The if statements will match this and call the CanBlankBlank Agent


:BlankCanBlank
  $IsListening = 0
  $Junction = "can"
  $SpeechLength = Length($HumanSaid)
  $JuncIndex = IndexOf($HumanSaid,$Junction)
  $FirstPart = SubString($HumanSaid,0,$JuncIndex-1)
  $LastPart = SubString($HumanSaid, $JuncIndex + Length($Junction) + 1,$SpeechLength - ($JuncIndex + Length($Junction))-1)
  $SearchPhrase = $FirstPart + "_:::_" + $LastPart
  $MemoryType = "BlankCanBlank"
  ControlCommand("Agents",ScriptStartWait,"WriteMemory")
  if($WriteMemoryCheck = 0)
    $SayWhat = "I knew that!"
  else 
    $SayWhat = "I now know that " + $FirstPart + " " + $Junction + " " + $LastPart
  endif
$IsListening = 1

The Agent Parses the captured speech takes what is before the word can and stores that in $FirstPart and what comes after the word can and stores that in the variable $LastPart Then loads the variable $SearchPhrase and $MemoryType then calls the Write Memory Agent.

This Agent opens the file and searches the file for the SearchPhrase. I will go into detail of the read and write memory Agents in the next exciting episode of Creating a Simple Brain.


ARC Pro

Upgrade to ARC Pro

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.

#17   — Edited

I'm trying to set this up and am having some problems. I think the ReadMemory script is mislabeled as there are two WriteMemory scripts. I believe the first one is the read one.  When I try the can cats purr example I get an error in line 74 of ReadMemory - variable not defined $RMFirstPart Also when I try cats can purr I get   12: if($WriteMemoryCheck = 0)> Error on line 12: Variable not defined: $WriteMemoryCheckI appreciate any help.

PRO
USA
#18  

How ironic, I lost most of my scripts when I upgraded to ARC, I am now coming back to this thread to get my code so I can start converting it to JavaScript. And my tutorial is a real good memory refresher Thank you DJ for saving all the old posts when you went to the new site. Never thought I would be using it as a backup. Wish I would have posted a lot more of my code or posted the entire project.

RichardZ