Members:
Sunjoong Kim
Objective:
Build an artificial assistant that is capable of doing tasks.
Status:
Complete/Developing
Running the Code:
Remember to download pip sources pyttsx3, pyaudio, and speech_recognition.
#################################################
### SIGNAL 1.0 ### DEVELOPED BY SUNJOONG KIM ###
#################################################
#import
import speech_recognition as sr
import pyttsx3
import time
from random import choice
#preset,default
r = sr.Recognizer()
Signal=pyttsx3.init()
gender = 'sir'
choices = [[f'Yes {gender}?',f'Did you call me {gender}?',f'Right at your service {gender}.']]
history = []
#functions
#for voice in Signal.getProperty('voices'):
# print(voice)
#Signal.setProperty('voice', voice.id)
#def change_voice(Signal, language, gender):
# for voice in Signal.getProperty('voices'):
# if language in voice.languages and gender == voice.gender:
# Signal.setProperty('voice', voice.id)
# return True
#change_voice(Signal, "en_US", "VoiceGenderFemale")
def record_text():
while(1):
try:
with sr.Microphone() as source2:
r.adjust_for_ambient_noise(source2, duration=0.00000000000000001)
audio2 = r.listen(source2)
MyText = r.recognize_google(audio2)
return MyText
except sr. RequestError as e:
print("Could not request results; {0}". format(e))
except sr.UnknownValueError:
#print("unknown error occured")
pass
return
def wake():
if int(time.strftime('%H')) < 12:
history.append(f'Good morning {gender}, Super Intelligent Giga Nearoned Artificial Legacy, Mode Active')
Signal.say(f'Good morning {gender}, Super Intelligent Giga Neuroned Artificial Legacy, Mode Active')
Signal.runAndWait()
else:
history.append(f'Good afternoon {gender}, Super Intelligent Giga Nearoned Artificial Legacy, Mode Active')
Signal.say(f'Good afternoon {gender}, Super Intelligent Giga Neuroned Artificial Legacy, Mode Active')
Signal.runAndWait()
def output_text(text):
if text == None:
run()
text = text.lower()
#print(text)
recognize(text)
return
def search(word):
if word == 'apple':
history.append('Apple, a round, red fruit, that is typically introduced and mentioned in many myths.')
Signal.say('Apple, a round, red fruit, that is typically introduced and mentioned in many myths.')
Signal.runAndWait()
elif word == 'youtube':
history.append('Youtube, a social media app owned by Google.')
Signal.say('Youtube, a social media app owned by Google.')
Signal.runAndWait()
elif word == 'run':
history.append('Run, An action done by animate creatures, that involve the swinging of limbs, to maneuver itself forward')
Signal.say('Run, An action done by animate creatures, that involve the swinging of limbs, to maneuver itself forward')
Signal.runAndWait()
elif word == 'sprint':
history.append('Sprint, A faster form of running')
Signal.say('Sprint, A faster form of running')
Signal.runAndWait()
else:
history.append('Word not defined. Please ask again.')
Signal.say('Word not defined. Please ask again.')
Signal.runAndWait()
def changeGender(gender2):
global gender
if gender2 == 'male':
gender = 'sir'
elif gender2 == 'female':
gender = "ma'am"
else:
history.append(f'No gender {gender2} recognized')
Signal.say(f'No gender {gender2} recognized')
Signal.runAndWait()
def recognize(text):
global gender
if text == 'wake up signal' or text == 'wake signal':
wake()
elif text.split()[0] == 'define':
search(text.split()[1])
elif text == 'time' or text == 'what is the time' or text == 'signal what is the time' or text == 'signal time':
c_time = 'It is currently'+' '+str(time.strftime('%H'))+' '+str(time.strftime('%M'))
history.append(c_time)
Signal.say(c_time)
Signal.runAndWait()
elif text == 'signal':
temp = choice(choices[0])
history.append(temp)
Signal.say(temp)
Signal.runAndWait()
elif (text.split()[0] == 'change' and text.split()[1] == 'gender'):
changeGender(text.split()[2])
elif text.split()[0] == 'transgender':
changeGender(text.split()[1])
elif text.split()[0] == 'repeat':
Signal.say(history[-1])
Signal.runAndWait()
else:
Signal.say('Function or command not listed in code')
Signal.runAndWait()
#running
#change_voice(Signal, "en_US", "VoiceGenderFemale")
def run():
while True:
text = record_text()
output_text(text)
wake()
run()