コード例 #1
0
ファイル: password.py プロジェクト: jwong28/KTNE_VoiceBot
def getColumn(num):
    ans = []
    # if(num == 1):
    #     ans = ["x","z","a","i","j","r"]
    # if(num == 2):
    #     ans = ["b","f","r","g","c","j"]
    # if(num == 3):
    #     ans = ["o","t","a","g","c","j"]
    # if(num == 4):
    #     ans = ["b","f","r","u","c","j"]
    while (True):
        engine.say("Letters for column " + str(num))
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            # if(1==1):
            try:
                col = []
                ans = res["text"].strip().lower().split()
                if (len(ans) == 6):
                    for word in ans:
                        char = word[0]
                        col.append(char)
                    engine.say(col)
                    engine.say("confirm")
                    engine.runAndWait()
                    confirm = helper.checkConfirm()
                    if (confirm):
                        columns.append(col)
                        return
                    # columns.append(col)
                    # return
            except ValueError:
                print("Password error")
コード例 #2
0
ファイル: buttonPress.py プロジェクト: jwong28/KTNE_VoiceBot
def holdButton():
    engine.say("Hold the button, what's the color strip")
    engine.runAndWait()
    while (True):
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            try:
                ans = res["text"].strip().lower().split()
                if ("blue" in ans):
                    engine.say("Release when 4 in any position")
                    engine.runAndWait()
                    return
                elif ("white" in ans):
                    engine.say("Release when 1 in any position")
                    engine.runAndWait()
                    return
                elif ("yellow" in ans):
                    engine.say("Release when 5 in any position")
                    engine.runAndWait()
                    return
                elif ("red" in ans or "orange" in ans or "black" in ans):
                    engine.say("Release when 1 in any position")
                    engine.runAndWait()
                    return
                else:
                    engine.say("Whats the color?")
                    engine.runAndWait()
            except:
                continue
コード例 #3
0
def complicatedWires():
    while (True):
        engine.say("Name wires")
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            try:
                ans = res["text"].strip().lower().split()
                wire = ""
                for word in ans:
                    if (word in helper.done):
                        appendWire(wire)
                        wire = ""
                    elif (ans.index(word) == len(ans) - 1):
                        wire = wire + word + " "
                        appendWire(wire)
                        wire = ""
                    else:
                        wire = wire + word + " "
                sayOutput()
                return
            except ValueError:
                print("Complicated wires error")
                continue
コード例 #4
0
def getSymbols():
    global symbol1, symbol2, symbol3, symbol4
    num = 1
    # x = "llamda"
    while (True):
        engine.say("Symbol " + str(num))
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            # if(1 == 1):
            try:
                # ans = x.strip().lower().split()
                ans = res["text"].strip().lower().split()
                case = findSymbolNum(ans)
                if not (case == 0):
                    if (symbol1 == 0):
                        symbol1 = case
                        num = num + 1
                        # x = "circle with line on the bottom"
                    elif (symbol2 == 0):
                        symbol2 = case
                        num = num + 1
                        # x = "backwards c with a dot"
                    elif (symbol3 == 0):
                        symbol3 = case
                        num = num + 1
                        # x = "a cursive h"
                    elif (symbol4 == 0):
                        symbol4 = case
                        num = num + 1
                        return
            except ValueError:
                print("Greek letter error")
コード例 #5
0
def getSecondPart(question):
    while (True):
        engine.say(question)
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        phrase = ""
        if (helper.checkResponse(res)):
            phrase = res["text"]
            # if(1 == 1):
            phrase = "ready set go"
            if ("ready" in phrase):
                read(ready)
            elif ("first" in phrase):
                read(first)
            elif ("no" in phrase):
                read(no)
            elif ("yes" in phrase):
                read(yes)
            elif ("left" in phrase):
                read(left)
            elif ("right" in phrase):
                read(right)
            elif ("middle" in phrase):
                read(middle)
            elif ("okay" in phrase):
                read(okay)
            elif ("wait" in phrase):
                read(wait)
            elif ("press" in phrase):
                read(press)
            elif ("done" in phrase):
                read(done)
            elif ("next" in phrase):
                read(wordNext)
            elif ("hold" in phrase):
                read(hold)
            elif ("sure" in phrase):
                read(sure)
            elif ("like" in phrase):
                read(like)
            elif ("blank" in phrase):
                read(blank)
            elif ("nothing" in phrase):
                read(nothing)
            elif ("letter" in phrase):
                if ("you" in phrase or "u" in phrase):
                    read(u)
            elif ("triple" in phrase or "three" in phrase):
                read(uhhh)
            elif ("what" in phrase):
                checkWord("what")
            elif ("uh" in phrase):
                checkWord("uh")
            elif ("you" in phrase):
                checkWord("you")
コード例 #6
0
def getBatteries():
    res = speechToText(recognizer, microphone)
    if(helper.checkResponse(res)):
        #Split text by space and get the number
        arr = res["text"].strip().lower().split()
        for word in arr:
            num = helper.getNumber(word.strip())
            print(word, "  ", num)
            print(isinstance(num, int))
            if(isinstance(num, int)):
                # engine.say("Got " + str(num))
                return num
    return 100    
コード例 #7
0
def getDigit():
    res = speechToText(recognizer, microphone)
    if(helper.checkResponse(res)):
        #Split text by space and take letters
        print(res["text"])
        arr = res["text"].strip().lower().split()
        for word in arr:
            num = helper.getNumber(word.strip())
            if(isinstance(num, int)):
                # engine.say(num)
                # engine.runAndWait()
                return num
            
    return ""
コード例 #8
0
def simpleWires():
    while(True):
        engine.say("What are the colors")
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if(helper.checkResponse(res)):
            try:
                ans = res["text"].strip().lower().split()
                ans = getWire(ans)
                if(not len(ans) == 0):
                    print(ans)
                    engine.say(ans)
                    engine.runAndWait()
                    return
            except ValueError:
                print("Simple wires error")
                continue
コード例 #9
0
def wordDisplay():
    # getSecondPart("ready")
    engine.say("Say done when module is finished")
    while (True):
        engine.say("What is the display word")
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            if ("done" in res["text"]):
                engine.say("Ok, done")
                return
            questionTwo = "What is the word in the"
            # questionTwo += checkWord(res["text"].lower())
            position = checkWord(res["text"].lower())
            if not (position == ""):
                questionTwo += position
                getSecondPart(questionTwo)
コード例 #10
0
ファイル: buttonPress.py プロジェクト: jwong28/KTNE_VoiceBot
def buttonPress():
    while (True):
        engine.say("Button color and text")
        engine.runAndWait()
        color = ""
        text = ""
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            try:
                ans = res["text"].strip().lower().split()
                # Get color
                if ("blue" in ans):
                    color = "blue"
                    engine.say("blue")
                elif ("red" in ans):
                    color = "red"
                    engine.say("red")
                elif ("white" in ans):
                    color = "white"
                    engine.say("white")
                elif ("yellow" in ans):
                    color = "yellow"
                    engine.say("yellow")
                # Get text
                if ("hold" in ans):
                    text = "hold"
                    engine.say("hold")
                elif ("detonate" in ans):
                    text = "detonate"
                    engine.say("detonate")
                elif ("abort" in ans):
                    text = "abort"
                    engine.say("abort")
                elif ("press" in ans):
                    text = "press"
                    engine.say("press")
                getResult(color, text)
                if (not ans == ""):
                    return
            except ValueError:
                print("Button press error")
                continue
コード例 #11
0
def simonSays():
    strikes = checkStrikes()
    phase = 1
    while(True):
        engine.say("Color "+ str(phase))
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if(helper.checkResponse(res)):
            try:
                ans = res["text"].strip().lower().split()
                done = getColors(strikes, ans)
                if(done == "done"):
                    return
                elif(done == "next"):
                    phase = phase + 1
            except ValueError:
                print("Simon says error")
    return
コード例 #12
0
def morseCode():
    engine.say("Say and in betweeen dash and dot")
    while (True):
        print("Start while")
        codeWord = ""
        engine.say("Ready for code")
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            # if(1 == 1):
            try:
                # ans = x.strip().lower().split()
                ans = res["text"].strip().lower().split()
                letter = ""
                for word in ans:
                    if ("dot" in word):
                        letter += "dot "
                    elif ("dash" in word):
                        letter += "dash "
                    if ("." in word):
                        letter += "dot "
                    elif ("-" in word):
                        letter += "dash "
                    if ("space" in word):
                        exist = findLetter(letter.strip())
                        letter = ""
                        if not (exist == ""):
                            codeWord += exist
                        #    engine.say(exist)
                        #    return
                exist = findLetter(letter.strip())
                if not (exist == ""):
                    codeWord += exist
                code = findWord(codeWord)
                if not (code == ""):
                    engine.say(code)
                    engine.runAndWait()
                    return code
                engine.say("No word found, try again")
            except:
                continue
コード例 #13
0
ファイル: wireSequence.py プロジェクト: jwong28/KTNE_VoiceBot
def wireSequence():
    engine.say("Say done when module is finished")
    while (True):
        engine.say("Name wires")
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            try:
                ans = res["text"].strip().lower().split()
                print("x is now ")
                print(ans)
                wire = ""
                for word in ans:
                    if (word == "done"):
                        getOutput(wire)
                        if (ran):
                            sayOutput()
                        return
                    if (word in aWord):
                        wire += " a"
                        print("The word is " + wire)
                        ran = getOutput(wire)
                        wire = ""
                    elif (word in bWord):
                        wire += " b"
                        print("The word is " + wire)
                        ran = getOutput(wire)
                        wire = ""
                    elif (word in cWord):
                        wire += " c"
                        print("The word is " + wire)
                        ran = getOutput(wire)
                        wire = ""
                    elif (word == "red" or word == "blue" or word == "black"):
                        wire += word + " "
                if (ran):
                    sayOutput()
            except ValueError:
                print("Wire sequence error")
                continue
コード例 #14
0
ファイル: mazes.py プロジェクト: jwong28/KTNE_VoiceBot
def getStartEnd():
    global end
    start = [100, 100]
    end = [100, 100]
    while (start[0] == 100 or start[1] == 100 or end[0] == 100
           or end[1] == 100):
        if (start[0] == 100 and start[1] == 100):
            engine.say("Start position")
        elif (end[0] == 100 and end[1] == 100):
            engine.say("End position")
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            try:
                # ans = res["text"].strip().lower().split()
                if (start[0] == 100 and start[1] == 100):
                    # engine.say("Start position")
                    s = determinePos(res["text"])
                    start = [s[1] - 1, s[0] - 1]
                    print("New start")
                    print(start)
                elif (end[0] == 100 and end[1] == 100):
                    e = determinePos(res["text"])
                    end = [s[1] - 1, e[0] - 1]
                    print("end")
                    print(end)
            except ValueError:
                print("Start end error")
                continue
        if (end[0] == 100 and end[1] == 100):
            print("Not completed yet")
        if (not (start[0] == 100 or start[1] == 100 or end[0] == 100
                 or end[1] == 100)):
            print("Both is all full")
            print(start)
            print(end)
            return start
コード例 #15
0
def getWrongItems():
    items = []
    res = speechToText(recognizer, microphone)
    if(helper.checkResponse(res)):
        #Split text by space and take letters
        print("Wrong items " + res["text"])
        arr = res["text"].strip().lower().split()
        for word in arr:
            if(word == "digit"):
                items.append("digit")
            elif(word == "vowel" or word == "vowels"):
                items.append("vowel")
            elif(word == "battery" or word == "batteries"):
                items.append("batteries")
            elif(word == "frk"):
                items.append("FRK")
            elif(word == "car"):
                items.append("CAR")
            elif(word == "indicator" or word == "indicators"):
                items.append("indicators")
            elif(word == "port" or word == "parallel"):
                items.append("port")
    return items
コード例 #16
0
ファイル: mazes.py プロジェクト: jwong28/KTNE_VoiceBot
def getMazeNum():
    global mazeNum
    while (True):
        engine.say("Where are the circles in column then row order")
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            # if(1 == 1):
            try:
                # ans = res["text"].strip().lower().split()
                # ans = "1 2"
                c = determinePos(res["text"])
                # return when both circle positions are obtained and in the map
                if not (c[0] == 100 and c[1] == 100):
                    if (c in circles):
                        mazeNum = math.ceil((circles.index(c) + 1) / 2)
                        print("solution")
                        print(mazeNum)
                        return
                # return
            except ValueError:
                print("Maze circles error")
                continue
コード例 #17
0

if __name__ == "__main__":
    start = datetime.now()
    recognizer = sr.Recognizer()
    microphone = sr.Microphone()
    engine = pyttsx3.init()
    
    engine.say("Please wait 1 to 2 seconds after I talk to adjust for noise")
    initial.getInitial()
    engine.say("Initialized")
    engine.runAndWait()
    
    while(True):
        engine.say("Module name")
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        if (helper.checkResponse(res)):
            print("Module " + res["text"])
            checkModule(res["text"])

    #For mic testing
    # while True:
    #     res = speechToText(recognizer, microphone)
    #     if(helper.checkResponse(res)):
    #         print(res["text"])

        
  

コード例 #18
0
def ambiguity(word, phase):
    choices = []
    if (phase == 1):
        if (word == "blank"):
            question = "Say 1 if it is empty, 2 if word is nothing, 3 if word is blank"
            choices = ["empty", "nothing", "blank"]
        elif (word == "lead"):
            question = "Say 1 if word is l e d, 2 if l e a d, 3 if l e e d"
            choices = ["led", "lead", "leed"]
        elif (word == "read"):
            question = "Say 1 if word is r e a d, 2 if r e d, 3 if r e e d"
            choices = ["read", "red", "reed"]
        elif (word == "you"):
            question = "Say 1 if word is y o u, 2 if y o u space a r e, 3 if y o u r "
            question += "4 if y o u apostrophe r e, 5 if letters u r"
            choices = ["you", "you are", "your", "youre", "ur"]
        elif (word == "they"):
            question = "Say 1 if word is t h e r e, 2 if t h e i r, 3 if t h e y space a r e "
            question += "4 if t h e y apostrophe r e"
            choices = ["there", "their", "they are", "theyre"]
        elif (word == "c"):
            question = "Say 1 if word is s e e, 2 if c e e, 3 if letter c"
            choices = ["see", "c", "cee"]
        else:
            return ""
    else:
        if (word == "what"):
            question = "Say 1 if there is a question mark, two for just what"
            choices = ["whatt", "what"]
        elif (word == "uh"):
            question = "Say 1 if word is u h h h, 2 if u h h u h, 3 if u h u h"
            choices = ["uhhh", "uhhuh", "uhuh"]
        elif (word == "you"):
            question = "Say 1 if word is y o u, 2 if y o u r, 3 if y o u  space a r e, "
            question += "4 if y o u apostrophe r e, 5 if u r, 6 if letter u"
            choices = ["you", "your", "you are", "you're", "ur", "u"]
    while (True):
        engine.say(question)
        engine.runAndWait()
        res = speechToText(recognizer, microphone)
        print(res["text"])
        if (helper.checkResponse(res)):
            #Split text by space and get the number
            arr = res["text"].strip().lower().split()
            for a in arr:
                num = helper.getNumber(a.strip())
                if (num > len(choices)):
                    word = choices[num - 1]
                    if (phase == 1):
                        if (word == "empty"):
                            return "bottom left"
                        elif (word == "nothing"):
                            return "middle left"
                        elif (word == "blank"):
                            return "middle right"
                        elif (word == "led"):
                            return "middle left"
                        elif (word == "lead"):
                            return "bottom right"
                        elif (word == "leed"):
                            return "bottom left"
                        elif (word == "red"):
                            return "middle right"
                        elif (word == "read"):
                            return "middle right"
                        elif (word == "reed"):
                            return "bottom left"
                        elif (word == "you"):
                            return "middle right"
                        elif (word == "you are"):
                            return "bottom right"
                        elif (word == "your"):
                            return "middle right"
                        elif (word == "youre"):
                            return "middle right"
                        elif (word == "ur"):
                            return "top left"
                        elif (word == "there"):
                            return "bottom right"
                        elif (word == "their"):
                            return "middle right"
                        elif (word == "they are"):
                            return "middle left"
                        elif (word == "theyre"):
                            return "bottom left"
                        elif (word == "see"):
                            return "bottom right"
                        elif (word == "c"):
                            return "top right"
                        elif (word == "cee"):
                            return "bottom right"
                    else:
                        if (word == "whatt"):
                            read(whatt)
                        elif (word == "what"):
                            read(what)
                        elif (word == "uhhh"):
                            read(uhhh)
                        elif (word == "uhhuh"):
                            read(uhHuh)
                        elif (word == "uhuh"):
                            read(uhUh)
                        elif (word == "you"):
                            read(you)
                        elif (word == "your"):
                            read(your)
                        elif (word == "you are"):
                            read(youAre)
                        elif (word == "you're"):
                            read(youre)
                        elif (word == "ur"):
                            read(ur)
                        elif (word == "u"):
                            read(u)
                        return ""
コード例 #19
0
def getInitial():
    engine = pyttsx3.init()
    complete = False
    batteries = 100
    FRK = ""
    CAR = ""
    parallelPort = ""
    serialDigit = "" 
    serialVowel = ""
    while(not complete):
        if(serialDigit == ""):
            engine.say("Serial last digit")
            engine.runAndWait()
            serialDigit = getDigit()
        # elif(serialVowel == ""):
        #     engine.say("Serial vowel, yes or no")
        #     engine.runAndWait()
        #     serialVowel = getTruthValue()
        elif(batteries == 100):
            engine.say("How many batteries?")
            engine.runAndWait()
            batteries = getBatteries()
        # elif(FRK == ""):
        #     engine.say("Is F R K lit?") 
        #     engine.runAndWait()
        #     FRK = getTruthValue()
        # elif(CAR == ""):
        #     engine.say("Is C A R lit") 
        #     engine.runAndWait()
        #     CAR = getTruthValue()
        # elif(parallelPort == ""):
        #     engine.say("Is there a parallel port?")
        #     engine.runAndWait()
        #     parallelPort = getTruthValue()
        elif(serialVowel == "" or FRK == "" or CAR == "" or parallelPort == ""):
            question = "Answer the following with a series of yes or no. Does the bomb serial have a vowel, is there a lit FRK "
            question += "Is there a lit C A R and is there a parallel port"
            engine.setProperty("rate", 150)
            engine.say(question)
            engine.runAndWait()
            engine.setProperty("rate", 200)
            restart = True
            while(restart):
                engine.runAndWait()
                res = speechToText(recognizer, microphone)
                print(res["text"])
                if(helper.checkResponse(res)):
                    try:
                        ans = res["text"].strip().lower().split()
                        for word in ans:
                            value = ""
                            if(word in helper.confirmMessage):
                                value = True
                            elif(word in helper.denyMessage):
                                value = False
                            if(value == True or value == False):
                                if(serialVowel == ""):
                                    serialVowel = value
                                elif(FRK == ""):
                                    FRK = value
                                elif(CAR == ""):
                                    CAR = value
                                elif(parallelPort == ""):
                                    parallelPort = value
                        if not(serialVowel == "" or FRK == "" or CAR == "" or parallelPort == ""):
                            restart = False
                        else:
                            engine.say("Not all questions were answered")
                    except:
                        continue
        else:
            #Get confirmation
            msg = "Last digit " + str(serialDigit)
            msg = " Vowel " + str(serialVowel)
            msg = str(batteries) + " battery"
            msg = " FRK " + str(FRK)
            msg = " C A R" + str(CAR)
            msg = " Parallel port " + str(parallelPort)
            msg = " Is everything correct?"
            engine.say(msg)
            engine.runAndWait()
            correct = getTruthValue()
            if(correct):
                #Save variables
                helper.saveInitial(serialDigit, serialVowel, batteries, FRK, CAR, parallelPort)
                return
            else:
                engine.say("What is wrong?")
                engine.runAndWait()
                wrong = getWrongItems()
                if(len(wrong) == 0):
                    engine.say("You didn't say any of the items")
                elif("digit" in wrong):
                    serialDigit = ""
                elif("vowel" in wrong):
                    serialVowel = ""
                elif("batteries" in wrong):
                    batteries = 100
                elif("FRK" in wrong):
                    FRK = ""
                elif("CAR" in wrong):
                    CAR = ""
                elif("indicators" in wrong):
                    FRK = ""
                    CAR = ""
                elif("port" in wrong):
                    parallelPort = ""