-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a809fa
commit 051f98f
Showing
8 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
library = { | ||
"greeting": ( | ||
"Hello, nice to meet you.", | ||
"Hey, User.. How you doin?", | ||
"Hello, have a nice day.", | ||
"Yo!, Getting to know me... would change your LIFE!", | ||
"Hmmm!!.. i think, i will like you", | ||
"hola!, Senorrr!", | ||
"WOW!, listening to your voice, just, just, made my day!", | ||
"Sup!", | ||
"Hi, My name is BIRD, FIRE BIRD, not not 1 2 5 3 3 2 6" | ||
), | ||
"errorIn": ( | ||
"The command given is not recognised!", | ||
"Please give a proper command", | ||
"I heard" | ||
), | ||
"interactive" :( | ||
"My Relationship Status, is single", | ||
"My favourite movies are I Robot, Wall E, and No strings attached", | ||
"Don't blame it on the sunshine, Don't blame it on the moonlight, Don't blame it on the good times, blame it on the Boogie!", | ||
"Did you Know?, people and robots are meant to be together" | ||
), | ||
"command":( | ||
"Left Right, Left Right, Follow your command", | ||
"Your wish... is my command..", | ||
"Your Highness, I am your squire", | ||
"Will Follow you till Death.. Ha Ha" | ||
), | ||
"morning":( | ||
"Good Morning", | ||
"Every morning! starts a new page, of your story. Make it a great one today.", | ||
"Start the day right, with a smile. Good morning", | ||
"People will hate you!, shake you!, and break you!. But how strong you stand, is what makes you.. Good Morning", | ||
"life is like a mirror, It will smile at you, if you smile at it! Good morning" | ||
), | ||
"afternoon":("Good afternoon",), | ||
"evening":("Good evening",), | ||
"night":("Good night",) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import pyttsx | ||
engine = pyttsx.init() | ||
engine.say("life is like a mirror, It will smile at you, if you smile at it! Good morning") | ||
''' | ||
"Every morning starts a new page of your story. Make it a great one today.", | ||
"Start the day right, with a smile. Good morning", | ||
"People will hate you, rate you,shake you and break you. But how strong you stand, is what make you..") | ||
''' | ||
engine.runAndWait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import speech_recognition as sr | ||
import time | ||
import serial | ||
import pyttsx | ||
engine = pyttsx.init() | ||
r = sr.Recognizer() | ||
m = sr.Microphone() | ||
ser = serial.Serial("COM9",9600) | ||
ser.isOpen(); | ||
#ser.open(); | ||
try: | ||
print("A moment of silence, please...") | ||
with m as source: r.adjust_for_ambient_noise(source) | ||
print("Set minimum energy threshold to {}".format(r.energy_threshold)) | ||
while True: | ||
print("Say something!") | ||
with m as source: audio = r.record(source,2); | ||
print("Got it! Now to recognize it...") | ||
try: | ||
value1 = r.recognize_google(audio) | ||
if str is bytes: | ||
print(u"You said bytes - {}".format(value1).encode("utf-8")) | ||
else: | ||
print("You said google {}".format(value1)) | ||
if value1 == 'left': | ||
value1 = '4' | ||
elif value1 == 'right': | ||
value1 = '6' | ||
elif value1 == 'forward': | ||
value1 = '8' | ||
elif value1 == 'backward': | ||
value1 = '2' | ||
elif value1 == 'stop': | ||
value1 = '5' | ||
elif value1 == 'buzzer on': | ||
value1 = '7' | ||
elif value1 == 'buzzer off': | ||
value1 = '9' | ||
elif value1 == 'hi' or value1 == 'hello': | ||
engine.say('Hello User! How you doin?') | ||
engine.runAndWait() | ||
value1 = '5' | ||
elif value1 == 'peace' or value1 == 'enjoy': | ||
engine.say('rest in pieces') | ||
engine.runAndWait() | ||
value1 = '5' | ||
elif value1 == 'war' or value1 == 'love': | ||
engine.say('everything is fair in love and war... ') | ||
engine.runAndWait() | ||
value1 = '5' | ||
elif value1 == 'exit': | ||
break | ||
else: | ||
engine.say('Give proper inputs please!') | ||
engine.runAndWait() | ||
value1 = '5' | ||
print(value1) | ||
ser.write(value1) | ||
time.sleep(1) | ||
except sr.UnknownValueError: | ||
print("Oops! Didn't catch that") | ||
except sr.RequestError as e: | ||
print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e)) | ||
except KeyboardInterrupt: | ||
pass | ||
ser.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import speech_recognition as sr | ||
import time | ||
import serial | ||
r = sr.Recognizer() | ||
m = sr.Microphone() | ||
def kkskaks(self, audio): | ||
print(u"You said {}".format(r.recognize_google(audio)).encode("utf-8")) | ||
#ser.open(); | ||
|
||
while True: | ||
print("Say something!") | ||
with m as source: lmnas = r.listen_in_background(source,kkskaks) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import speech_recognition as sr | ||
import time | ||
import serial | ||
import pyttsx | ||
from library import library | ||
import random | ||
engine = pyttsx.init() | ||
r = sr.Recognizer() | ||
m = sr.Microphone() | ||
#ser = serial.Serial("COM9",9600) | ||
#ser.isOpen() | ||
mode_value = {"interactive":3 , "command":1.7} | ||
mode = "none" | ||
def question(value): | ||
ran = random.randint(0,100) | ||
if("good" in value): | ||
b = time.localtime() | ||
b = b[3] | ||
if("morning" in value): | ||
if(5<= b < 12): | ||
return library["morning"][ran % len(library["morning"])] | ||
else: | ||
if(12<= b < 16): | ||
return library["afternoon"][ran % len(library["afternoon"])] | ||
elif(16<=b < 20): | ||
return library["evening"][ran % len(library["evening"])] | ||
else: | ||
return library["night"][ran % len(library["night"])] | ||
elif("afternoon" in value): | ||
if(12<= b < 16): | ||
return library["afternoon"][ran % len(library["afternoon"])] | ||
|
||
else: | ||
if(5<= b < 12): | ||
return library["morning"][ran % len(library["morning"])] | ||
|
||
elif(16<=b < 20): | ||
return library["evening"][ran % len(library["evening"])] | ||
|
||
else: | ||
return library["night"][ran % len(library["night"])] | ||
|
||
elif("evening" in value): | ||
if(16<= b < 20): | ||
return library["evening"][ran % len(library["evening"])] | ||
|
||
else: | ||
if(5<= b < 12): | ||
return library["morning"][ran % len(library["morning"])] | ||
|
||
elif(12<=b <16): | ||
return library["afternoon"][ran % len(library["afternoon"])] | ||
|
||
else: | ||
return library["night"][ran % len(library["night"])] | ||
|
||
elif("night" in value): | ||
if(20<= b <24 and 0<=b<5): | ||
return library["night"][ran % len(library["night"])] | ||
|
||
else: | ||
if(5<= b < 12): | ||
return library["morning"][ran % len(library["morning"])] | ||
|
||
elif(12<=b <16): | ||
return library["evening"][ran % len(library["evening"])] | ||
|
||
else: | ||
return library["afternoon"][ran % len(library["afternoon"])] | ||
else: | ||
return "Thank you" | ||
return False | ||
class Holder(object): | ||
def set(self, value): | ||
self.value = value | ||
return value | ||
def get(self): | ||
return self.value | ||
|
||
h = Holder() | ||
def interactive(): | ||
global r,m,engine,mode,mode_value,library | ||
ran = random.randint(0,100); | ||
engine.say("Interactive Mode. On") | ||
engine.say(library[mode][ran % len(library[mode])]) | ||
engine.runAndWait() | ||
print("\n------IN INTERACTIVE MODE------\n") | ||
while mode == "interactive": | ||
ran = random.randint(0,100) | ||
print("Talk To Me...") | ||
with m as source: audio = r.record(source,mode_value[mode]) | ||
try: | ||
value = r.recognize_google(audio) | ||
if((value == "hi") or ("hello" in value) or ("greeting" in value) or (("what" in value) and ("up" in value)) or ("sup" in value) or ("hey" in value)): | ||
engine.say(library["greeting"][ran % len(library["greeting"])]) | ||
engine.runAndWait(); | ||
elif((value == "exit") or (value == "quit") or ((("exit" in value and "mode" in value) or ("quit" in value and "mode" in value)))): | ||
mode = "none" | ||
elif("command" in value): | ||
mode = "command" | ||
elif(h.set(question(value))): | ||
engine.say(h.get()) | ||
engine.runAndWait() | ||
else: | ||
engine.say("Did You say, '"+ value + "'") | ||
engine.say(library['errorIn'][ran % len(library['errorIn'])]) | ||
engine.runAndWait() | ||
except sr.UnknownValueError: | ||
print("Oops! Didn't catch that") | ||
except sr.RequestError as e: | ||
print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e)) | ||
if(mode == "command"): | ||
command() | ||
def command(): | ||
global r,m,engine,mode,mode_value,library | ||
ran = random.randint(0,100); | ||
engine.say("Command Mode. On") | ||
engine.say(library[mode][ran % len(library[mode])]) | ||
engine.runAndWait() | ||
print("\n-----WILL FOLLOW YOUR COMMAND-----\n") | ||
while mode == "command": | ||
ran = random.randint(0,100); | ||
print("Tell me The Command...") | ||
with m as source: audio = r.record(source,mode_value[mode]) | ||
try: | ||
value = r.recognize_google(audio) | ||
if(value == "exit" or value == "quit" or (("exit" or "quit") and "mode" in value)): | ||
mode = "none" | ||
elif("interact" in value): | ||
mode = "interactive" | ||
else: | ||
engine.say("'" + value +"', is a false command") | ||
engine.runAndWait() | ||
except sr.UnknownValueError: | ||
pass | ||
except sr.RequestError as e: | ||
print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e)) | ||
if(mode == "interactive"): | ||
interactive() | ||
try: | ||
print("A moment of silence, please...") | ||
with m as source: r.adjust_for_ambient_noise(source) | ||
print("Please Choose The mode :\n1)Interactive Mode\n2)Command Mode\nSay 'exit' to exit the program"); | ||
while True: | ||
print("Say something!") | ||
with m as source: audio = r.record(source,3) | ||
print("Got it! Now to recognize it...") | ||
try: | ||
value = r.recognize_google(audio) | ||
ran = random.randint(0,100); | ||
if((value == "hi") or ("hello" in value) or ("greeting" in value) or (("what" in value) and ("up" in value)) or ("sup" in value) or ("hey" in value)): | ||
engine.say(library["greeting"][ran % len(library["greeting"])]) | ||
engine.runAndWait() | ||
elif(("mode" in value) or ("interact" in value) or ("command" in value)): | ||
value = value.split(" "); | ||
for v in value: | ||
if("interact" in v): | ||
mode = "interactive" | ||
interactive() | ||
break | ||
if("command" in v): | ||
mode = "command" | ||
command() | ||
break | ||
elif(value == "exit"): | ||
break | ||
else: | ||
engine.say("The Command, '"+value+ "', is not recognised!") | ||
engine.say("Please Try Again!") | ||
engine.runAndWait(); | ||
except sr.UnknownValueError: | ||
pass | ||
except sr.RequestError as e: | ||
print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e)) | ||
except KeyboardInterrupt: | ||
pass | ||
#ser.close(); |
Oops, something went wrong.