Trigger Aryan

Once AI device is powered on, Aryan gets started in Sleeping mode and waits for Human to Trigger it. A Infinite while loop runs awaiting Human to trigger the Aryan to wake up from Sleep in the AryanStartStopCommand flow.
RawSpeechRecognizationTrigger flow is used to recognize the Human speech and output is stored in ListenSpeech for every 3 sec in loop.
Below code snippet demonstrates this flow and as soon as ListenSpeech matches Aryan or Arya respective flows are triggered by startAI flow.
It is from here that aifriend is identified as Aryan or Arya, they remain with you until Aryan or Arya goes back to sleep.

If the Human say "Terminate" then Aryan Master process are shutdown and have to be started again to bring them back to sleep.
while True:
PrintText("Aryan/Arya", "Sleeping...Say Aryan or Arya to Wake me up")
ListenSpeech = RawSpeechRecognizationTrigger().lower().lstrip().rstrip()
if ListenSpeech != "NA":
if subStrCheck(ListenSpeech,"aryan"):
if not (subStrCheck(ListenSpeech,"exit") or subStrCheck(ListenSpeech,"stop")):
aifriend = "Aryan"
elif subStrCheck(ListenSpeech,"arya"):
if not (subStrCheck(ListenSpeech,"exit") or subStrCheck(ListenSpeech,"stop")):
aifriend = "Arya"
elif subStrCheck(ListenSpeech,"terminate"):
PrintText("Internal", "Shutting down Aryan and Arya..")
DisplayText("Shutting down..")

Below snippet is RawSpeechRecognizationTrigger which keeps listening for Human phrase for time limit of 3 sec in loop.
Google Speech Recognition is used to recognize the speech, In case no speech or input then exception is raised but no action is taken and control fall backs to listen again as we want to listen to Human in loop awaiting trigger.
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source, phrase_time_limit=3)
speech = r.recognize_google(audio)
return speech
# Handling Exceptions if speech is not understood.
except sr.UnknownValueError:
speech = "NA"
return speech
except sr.RequestError as e:
speech = "NA"
return speech

Once AI Master get the wakeup command from the Human with AI Friend identified as Aryan or Arya, thereafter AI Worker is triggered which starts the worker script to Start Aryan or Arya using startAI flow
It is accomplished by starting a operating system sub process to start the script and pass the AI Friend (Aryan or Arya) as parameter.
Variable proc is used to capture the sub process and further monitoring of the child worker by Master.
workername = os.path.join(os.path.dirname(__file__) or '.','')
proc = subprocess.Popen([sys.executable,workername,"-a",aifriend], stderr=subprocess.PIPE)

For the entire Duration when Aryan is in conversation with Human using AI Worker process, AI Master process keeps

  • Listening to the Human in case Human wants to exit the AI worker explicitly
    • In this case as soon as the stop trigger words such as "stop", "exit", "no thank you" are identified
      • the AI Worker process is killed by AI Master using the PID captured while starting the child instance.
    • and control goes back to starting point i.e. AryanStartStopCommand and AI Master goes back to sleep.

  • Monitoring if AI Worker process exits naturally after completion of the command given by Human.
    • AI Worker PID is being checked using an Infinite while loop and if poll() for the sub process is None,
      • that is either the process is killed (PID is removed when exited from the Process table)
      • or is not functional (Zombie process in Linux)
      • Thereafter AI Master kills the process
    • and control goes back to starting point i.e. AryanStartStopCommand and AI Master goes back to sleep.
while True:
if psutil.pid_exists( and proc.poll() is not "None":
PrintText("Aryan", "Listening...Say " + aifriend + " Stop to Stop me")
ListenSpeech = RawSpeechRecognizationTrigger().lower().lstrip().rstrip()
if (subStrCheck(ListenSpeech,"exit") or subStrCheck(ListenSpeech,"stop") or subStrCheck(ListenSpeech,"no thank you")):
PrintText("Internal","About to Exit")
Phew, Aryan is sleeping again, waiting for Human trigger to wake up again.
Copy link
On this page
Wake up Aryan from Sleep
Terminate Aryan Master
Listening to User Speech in Loop
Trigger AI Worker to Start Aryan
Monitor Aryan Worker
Listening for explicit command to Stop AI Worker
Monitoring for Graceful Exit of AI Worker