예제 #1
0
def variableDeclaration(filename):
    currentline = len(filename.splitlines())
    print("You are writing to line#:", currentline)
    print("Please say your variable name: ")
    tempvar = l.listen()
    print("Variable Name: ", tempvar)
    print("Value: ")
    tempVal = l.listen()
    print("Value: ", tempVal)
    return tempvar + " = " + tempVal
예제 #2
0
def editFile(filename):
    print("Editing file...." + '\n')
    print("Say the line number of the file you want to edit: ")

    count = len(open(filename).readlines())
    lineNumber1 = l.listen()
    while (1):
        try:
            anInt = int(change_to_number(lineNumber1))
            print("LOOPING")
            if (anInt > 0 and anInt < 999):
                lineNumber1 = anInt
                break
        except ValueError:
            print("Please enter a valid number:")
            lineNumber1 = l.listen()
            continue

    lineNumber1 = int(lineNumber1)
    while (lineNumber1 > count or lineNumber1 < 1):
        print(
            "Please enter a valid file line in the file you wish to edit. (1-",
            count, ")")
        lineNumber = l.listen()

    my_file1 = open(filename, 'r')
    string_list = my_file1.readlines()
    my_file1.close()
    my_file = open(filename, 'w')
    print(len(string_list))
    print("The line number is: " + str(lineNumber1))
    print(type(lineNumber1))
    print("File Line being edited is: " + string_list[lineNumber1 - 1])

    print("Resay your edited line: ")
    newLine = l.listen()

    #need to replace "equals" with "="
    newLine = find_operator(newLine)

    string_list[lineNumber1 - 1] = newLine
    print("Line has been edited...")

    for i in range(len(string_list)):
        myString = string_list[i]
        print(myString)

        my_file.write(myString + "\n")

    my_file.close()
예제 #3
0
def comment(filename):
    while 1:
        currentline = len(filename.splitlines())
        print("You are commenting to line#:", currentline)
        print("")
        commentstring = l.listen()
        filename.write("# " + commentstring + "\n")
        print(
            "Would you like to make another line of comments? (Say <yes> / <no>)"
        )
        choice = l.listen()
        if choice == "yes":
            comment(filename)
        elif choice == "no":
            break
        else:
            print("Unable to process request. Input heard: ", choice)
            continue
예제 #4
0
def openFile():
    print("Say File Name to open: <inputFileName>")
    fileString = l.listen() + ".py"

    if os.path.exists(fileString):
        returnFile = open(fileString, "w")
        return returnFile.name

    returnFile = open(fileString, "w+")
    os.chmod(fileString, 0o700)
    returnFile.close()
    return returnFile.name
예제 #5
0
def forLoop(filename):
    print("\n ")
    print("Give a variable name to iterate on")
    varName = l.listen()
    print("variable given =", varName)
    print("Give a # of times to run this loop")
    rangeNum = l.listen()
    temp = change_to_number(rangeNum)
    forString = "for " + varName + " in range(" + temp + "):"

    print("Say the option you would like to do")
    options = "Options are: \n Variable \n Print string \n print variable \n Exit For Loop"
    print(options)
    option1 = l.listen()
    printstr = ""
    counter = 0
    while (option1 != "exit for loop"):
        if (counter > 0):
            print(options)
            option1 = l.listen()
        if (option1 == "variable"):
            print("entered variable")
            printstr += "\t" + variableDeclaration(filename) + "\n"
        if (option1 == "print string"):
            print("say what you want printed")
            print1 = l.listen()
            printstr += "\tprint(" + "\"" + print1 + "\"" + ")" + "\n"
        if (option1 == "print variable"):
            print("say which variable you want printed \n")
            print1 = l.listen()
            printstr += "\tprint(" + print1 + ")" + "\n"
        if (option1 == "exit for loop"):
            print("Exiting the For Loop")
        counter += 1
    return forString + "\n" + printstr
예제 #6
0
def helper(filename):
    tempfile = filename
    #filename.close()
    theFile = open('HelpText.txt', "r")
    print(theFile.read())
    #os.startfile('HelpText.txt')
    print("Say exit to return to the main menu")

    BacktoMenu = l.listen()
    if BacktoMenu == "exit help" or "exit hell":
        print("closing help manual and returning to main")
        #os.system('TASKKILL /F /IM notepad.exe')
        theFile.close()
예제 #7
0
def recommandation(url, num, cur):
    video_id = url.split('?v=')[1]
    video = Listen.youtube_search(video_id=video_id, max_results=num+10)
    res = []
    for sentence in video:
        tmp = [sentence[0], sentence[3], sentence[1]]
        if tmp not in cur:
            res.append(tmp)
    if cur == []:
        return res[:num]
    else:
        print cur
        return res[:num] + cur[:20-num]
예제 #8
0
파일: tree.py 프로젝트: Linh-312/DicRin
def tree_speak():
    while True:
        you = Listen.listen()
        # print("Robot: ",you)
        if "hello" in you:
            Think.start(you)
        elif "bye" in you:
            Speak.speak("Goodbye,See you again")
            break
        elif "dictionary" in you:
            Think.dictionary()
        else:
            you = Think.think(you)
            print(you)
            Speak.speak(you)
예제 #9
0
def classifyCommand():
    # Tokenize string of sentences into list of sentences
    commands = sent_tokenize(Listen.typeCommand())
    print(commands)
    #commands = Listen.typeCommand()
    #print(commands)
    questions, answers = processCommands(commands)
    # INSERT NEW QUESTiON in DB
    DB.insert_DB(questions, answers)

    for i in range(len(answers)):
        # print(questions[i]," : " ,answers[i])
        # print("")
        print("BOT:" + str(answers[i]))
        print("")
예제 #10
0
def listen(playerNum):
    return Listen.listen(playerNum)
예제 #11
0
        summed = Calculate(t)
        PlayText(t + " = " + str(summed))

    elif data.startswith("hi"):
        PlayText("Hello")

    elif data.startswith("what are you"):
        PlayText("I am a hard-coded assistant bot.")

    elif data.startswith("clear space"):
        PlayText("Clearing Space.")
        for name in os.listdir("NewSounds"):
            os.remove("NewSounds/" + name)

    else:
        PlayText("Sorry, I didn't understand that.")


while run == True:
    if run == False:
        break
    PlayText("What is your command")
    Command = Listen.RecordSound(4)
    if Command != None:
        Command = Command.lower()
        if Command.startswith("shut down") or Command.startswith("turn off"):
            PlayText("Okay, I am shutting down now. Goodbye James.")
            break
        PlayText("Processing your command")
        Scarl(Command)
            # Uses the known face with the smallest distance to the new face
            face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
            best_match_index = np.argmin(face_distances)
            if matches[best_match_index]:
                name = known_face_names[best_match_index]

            face_names.append(name)
            if not greetCheck[best_match_index]:
                greet.append(name)
                greetCheck[best_match_index] = True

            if name == "Unknown":
                Speak.speak("I see a person that isn't known, would this person like to be known and give their name?")
                time.sleep(1)
                response = Listen.recognize_speech_from_mic(recognizer, microphone)
                print(response)
                response = input("The speech recognition is a work in progress that works half the time, please type what your \"yes\" or \"no\" answer")
                if "yes" in response or "Yes" in response:
                    Speak.speak(
                        "Ok. Please make sure that you are the only one faceing the camera")
                    time.sleep(3)

                    rgb_small_frame = getFrame()
                    face_locations = face_recognition.face_locations(rgb_small_frame)
                    face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)

                    if len(face_encodings) == 1:
                        Speak.speak("Please type in your name?")
                        asdf = input("Please enter your name?")
                        updateFaces(asdf,totalName,startpoint)
예제 #13
0
def search(request):
    return Listen.search(request)
예제 #14
0
def writeFile(filename):

    #   Currently a conditional to make sure we aren't messing with our own files. Destroy this later
    if filename == "main.py" or filename == "functions.py" or filename == "listen.py" or filename == "write.py":
        print(
            "CRITICAL ERROR. ATTEMPTING TO OVERWRITE SOURCE CODE. EXITING...")
        exit(1)

    # Write Loop
    while 1:
        file = open(filename, "a+")

        print("Current file looks like:")
        print(file.read())

        print("What would you like to write?")
        print("Waiting for input...")
        text = l.listen()

        #to break out of infinite loop
        if text == "exit right" or text == "exit write":
            print("Exiting write...")
            file.close()
            break

        #logic for commenting
        if text == "comment" or text == "common" or text == "comments":
            print("Commenting...")
            comment(filename)
        #logic for variable declaration

        if text == "variable":
            print("Entering variable...")
            assignString = variableDeclaration(filename)
            file.write(assignString)
            file.write("\n")

        if text == "string":
            print("Enter the contents of your string")
            text = l.listen()
            file.write("print(" + "\"" + text + "\"" + ")")
            print("String has been written too...")
            file.write("\n")
# Start of for loop logic
        if text == "for loop" or text == "orally":
            print("Entering For Loop...")
            file.write(forLoop(filename))

        # Start of if statement logic

        if text == "if" or text == "elf" or text == "of" or text == "f" or text == "it":
            print("Entering 'if' statement")
            ifString = ifstate(filename)
            file.write(ifString)
            file.write("\n")

# Start of print logic
        if text == "string" or text == "strength":
            print("Enter the contents of your string")
            text = l.listen()

            file.write("print(" + "\"" + text + "\"" + ")")
            print("String has been written...")
            file.write("\n")


# Start of While Loop Logic
        if text == "while loop" or text == "guadalupe":

            print("Enter the conditional of the while loop")
            text = l.listen()
            if (text.find("less than")):
                print("We found it1!!!!!")
            parsedText = find_operator(text)
            print(parsedText)
            file.write("while " + parsedText + ":" + "\n")
            while 1:
                # print, variable, assignment x=7 x= ,
                print(
                    "Entering the body of the while loop, say 'exit while loop' to break out of loop"
                )
                print("1 - variable declaration/assignment")
                print("2 - print within the while loop")

                text = l.listen()

                print(text)

                if text == "exit while loop":
                    print("Exiting while loop....")
                    break

                if (text == "won" or text == "one" or text == "1"):
                    print("State your declaration/assignment")
                    text = l.listen()
                    bodyText = find_operator(text)
                    print("Variable has been written")

                    file.write("\t" + bodyText + "\n")

                if (text == "two" or text == "to" or text == "too"
                        or text == "2"):
                    print("Are you printing a string or a variable?")
                    print("To exit print say 'exit print'")

                    while (1):
                        text = l.listen()
                        print("Audio Heard: " + text)
                        if text == "string":
                            print("Enter the contents of your string")
                            text = l.listen()
                            file.write("\t" + "print(" + "\"" + text + "\"" +
                                       ")" + "\n")
                            print("String has been written...")
                        if text == "variable":
                            print("Enter the contents of your variable")
                            text = l.listen()
                            file.write("\t" + "print(" + text + ")" + "\n")
                            print("Variable has been written...")
                        if text == "exit print":
                            print("Exiting print....")
                            break

        file.close()
        print("Finished parsing text: " + text)
예제 #15
0
def ifstate(filename):
    currentline = len(filename.splitlines())
    print("What kind of 'if' statement would you like to use")
    print("if statement\n" "if-else statement\n")
    print("Say the statement you would like")
    option = ""
    option = l.listen()
    #option = change_to_number(option)
    print(option)
    print("The option selected: ", option)
    if (option == "if statement" or option == "if they payment"):
        print("Entering regular 'if' statement")
        print("Please state the conditional you want in the if statement")
        print("You are writing to line#:", currentline)
        tempIf = l.listen()
        condOp = find_operator(tempIf)  #if (x > 5)
        print("if (" + condOp + ") :")
        first = "if (" + condOp + ") :\n"
        print("What would you like to go in the body of the if statement")
        print(
            "Options are: \n Variable \n Print string \n print variable  \n While Loop \n Exit If Statement"
        )
        option1 = l.listen()
        printstr = ""
        counter = 0
        while (option1 != "exit if statement"):
            if (counter > 0):
                print(
                    "Options are: \n Variable \n Print string \n print variable  \n While Loop \n Exit If Statement"
                )
                option1 = l.listen()
            if (option1 == "variable"):
                print("Entering variable creation")
                printstr += "\t" + variableDeclaration(filename) + "\n"
            if (option1 == "print string"):
                print("Say what string you would like to print")
                print1 = l.listen()
                print("Your string is: ", print1)
                printstr += "\tprint(" + "\"" + print1 + "\"" + ")" + "\n"
            if (option1 == "print variable"):
                print("Say which variable you want printed \n")
                print1 = l.listen()
                if (print1 == "why"):
                    print1 = "y"
                print("Your selected variable is: ", print1)
                printstr += "\tprint(" + print1 + ")" + "\n"
            if (option1 == "exit if statement"):
                print("Exiting the if statement")
            counter += 1
        return first + printstr

    elif (option == "if else statement"):
        print("Entering option 2: if-else statement")
        print("Please state the conditional you want in the if-else statement")
        print("You are writing to line#:", currentline)

        tempIf = l.listen()
        condOp = find_operator(tempIf)  # if (x > 5)
        print("if (" + condOp + ") :")
        print("What would you like to have in the body of the 'if' portion")
        first = "if (" + condOp + ") :\n"
        print(
            "Options are: \n Variable \n Print string \n print variable  \n  Exit If Statement"
        )
        option1 = l.listen()
        printstr = ""
        counter = 0
        while (option1 != "exit if statement"):
            if (counter > 0):
                print(
                    "Options are: \n Variable \n Print string \n print variable \n Exit If Statement"
                )
                option1 = l.listen()
            if (option1 == "variable"):
                print("entered variable")
                printstr += "\t" + variableDeclaration(filename) + "\n"
            if (option1 == "print string"):
                print("Say what string you would like to print")
                print1 = l.listen()
                print("you said: ", print1)
                printstr += "\tprint(" + "\"" + print1 + "\"" + ")" + "\n"
            if (option1 == "print variable"):
                print("Say which variable you want printed \n")
                print1 = l.listen()
                if (print1 == "why"):
                    print1 = "y"
                print("Your selected variable is: ", print1)
                printstr += "\tprint(" + print1 + ")" + "\n"
            if (option1 == "exit if statement"):
                print("Exiting the if statement")
            counter += 1
        print(
            "Entering the else portion\n Select and option for the body of the 'else' portion"
        )
        print(
            "Options are: \n Variable \n Print string \n print variable  \n Exit If Statement"
        )
        elseop = l.listen()
        elsestr = ""
        counter = 0
        while (elseop != "exit if statement"):
            if (counter > 0):
                print(
                    "Options are: \n Variable \n Print string \n print variable  \n Exit If Statement"
                )
                elseop = l.listen()
            if (elseop == "variable"):
                print("entered variable")
                elsestr += "\t" + variableDeclaration(filename) + "\n"
            if (elseop == "print string"):
                print("Say what string you would like to print")
                print1 = l.listen()
                print("you said: ", print1)
                elsestr += "\tprint(" + "\"" + print1 + "\"" + ")" + "\n"
            if (elseop == "print variable"):
                print("Say which variable you want printed \n")
                print1 = l.listen()
                if (print1 == "why"):
                    print1 = "y"
                print("Your selected variable is: ", print1)
                elsestr += "\tprint(" + print1 + ")" + "\n"
            if (elseop == "exit if statement"):
                print("Exiting the if statement")
            counter += 1
        return first + printstr + "else :\n" + elsestr
예제 #16
0
def youtube_search(video_id=0, video_name='', max_results=5):
    return Listen.youtube_search(video_id, video_name, max_results)
예제 #17
0
def adder(request, url):
    return Listen.adder(request, url)
예제 #18
0
def dictation(request, name):
    return Listen.dictation(request, name)
예제 #19
0
    "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
)

# Loop infinitely for user to
# speak
while 1:

    # Current status output
    print(
        "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Main Menu~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    )
    print("Current working file: ", currentfile)
    print("Current working directory: ", o.getcwd())
    print("Waiting for voice input...")
    # use the microphone as source for input.
    MyText = l.listen()

    # Voice command to stop running.
    if MyText == "end speech to code" or MyText == "and speech to code":
        print("Exiting speech2code...")
        break

#   Helper Function
    if MyText == "help" or MyText == "hell":
        print("Launching <help>...")
        f.helper(currentfile)
        continue

#   Open File Function
    if MyText == "open file":
        if currentfile != "start.py":
예제 #20
0
def video_list(request):
    return Listen.video_list(request)
예제 #21
0
def add_video(request):
    return Listen.add_video(request)