Exemplo n.º 1
0
def main():

    SWEARS = {"heck" : 0.01,
              "fudge": 0.10,
              "darn" : 0.05
             }

    print("Welcome to PottyPot!")
    while True:
        print("-"*25)
        print("Start recording?")
        user_response = input("[y]/n> ")
        if user_response.lower() != "y" or not user_response:
            print("Invalid response")
            break
        
        file = record_audio(5)
        words = speech_detect(file)

        user_swears = []

        for i in words:
            print(i)
            indiv = i.split(' ')
            for j in indiv:
                for k in SWEARS:
                    if k == j:
                        user_swears.append(k)

        if user_swears:
            print(f"Uh oh, you said {' '.join(user_swears)}!")

            price = float(0)
            for swear in user_swears:
                price += SWEARS[swear]

            price = str(price)[0:4]
            print(f"That'll be ${price}")
            response = send_money(price)
            print(f"Donated ${price}, thanks for swearing!")
Exemplo n.º 2
0
def defuse_button(button, check):

    color = button[0]
    word = button[1]
    hold = False

    if color == "read":
        color = "red"
    if word == "a":  # sometimes abort heard as a boat
        word = "abort"

    if color == "blue" and word == "abort":
        hold = True
    elif (int(check['batteries']) > 1) and (word == "detonate"):
        speech.speak('press and immediately release')
    elif (color == "white") and (check['car'] == "yes"):
        hold = True
    elif (int(check['batteries']) > 2) and (check['freak'] == "yes"):
        speech.speak('press and immediately release')
    elif color == "yellow":
        hold = True
    elif (color == "red") and (word == "hold"):
        speech.speak("press and immediately release")
    else:
        hold = True
    if hold:
        speech.speak('hold, color?')
        strip = speech.record_audio()

        if strip == "blue":
            speech.speak('countdown 4')
        elif strip == "white":
            speech.speak('countdown 1')
        elif strip == "yellow":
            speech.speak('countdown 5')
        else:
            speech.speak('countdown 1')
Exemplo n.º 3
0
from speech import record_audio
from Command import Command
from Process import Process
#from basic_movement import BasicMovement
from malmo_commands import SpeechToSteve
from speech_recognition import UnknownValueError
from speech_recognition import RequestError
import time

if __name__ == "__main__":
    process = Process(SpeechToSteve({}))
    while True:
        try:
            i = input("Ready for command")
            command = record_audio()
            #command = str(input("Type your command: ")) #keyboard input
            command = Command(command)

            print("raw_text", command.rawText)
            for token in command.doc:
                print(token.text, end=' ')
                print(token.dep_, token.pos_)
            print(
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
            )
        except UnknownValueError:
            print("Cannot recognize audio")
            continue
        except RequestError:
            print("Speech service down")
            print("Exiting")
Exemplo n.º 4
0
def respond(voice_data):
    global check
    voice_data = voice_data.lower()
    if 'check' in voice_data or 'jack' in voice_data:
        speech.speak('ready')
        global check
        voice_data = speech.record_audio()

        voice_data = voice_data.split()
        if 'foul' in voice_data:
            voice_data[voice_data.index('foul')] = 'vowel'
        if 'bowel' in voice_data:
            voice_data[voice_data.index('bowel')] = 'vowel'
        if 'powell' in voice_data:
            voice_data[voice_data.index('powell')] = 'vowel'
        if 'barrel' in voice_data:
            voice_data[voice_data.index('barrel')] = 'vowel'
        try:
            for i in range(0, len(voice_data) - 1):
                if i % 2 == 0:
                    check[voice_data[i]] = voice_data[i + 1]

            print(check)

            incomplete = True

            while incomplete:
                incomplete = False

                if ('digit' not in check.keys()) or (not str(
                        check['digit']).isdigit()):
                    incomplete = True
                    speech.speak('repeat the digit')
                    check['digit'] = speech.record_audio()
                    check['digit'] = stringtoint(check['digit'])
                if ('batteries' not in check.keys()) or (not str(
                        check['batteries']).isdigit()):
                    incomplete = True
                    speech.speak('repeat battery number')
                    check['batteries'] = speech.record_audio()
                    check['batteries'] = stringtoint(check['batteries'])
                if ('parallel' not in check.keys()) or (not str(
                        check['parallel']) in ['yes', 'no']):
                    incomplete = True
                    speech.speak('repeat parallel yes/no')
                    check['parallel'] = speech.record_audio()
                if ('freak' not in check.keys()) or (not str(check['freak'])
                                                     in ['yes', 'no']):
                    incomplete = True
                    speech.speak('repeat freak yes/no')
                    check['freak'] = speech.record_audio()
                if ('car' not in check.keys()) or (not str(check['car'])
                                                   in ['yes', 'no']):
                    incomplete = True
                    speech.speak('repeat car yes/no')
                    check['car'] = speech.record_audio()
                if ('vowel' not in check.keys()) or (not str(check['vowel'])
                                                     in ['yes', 'no']):
                    incomplete = True
                    speech.speak('repeat vowel yes/no')
                    check['vowel'] = speech.record_audio()
            print(check)
            speech.speak('Bomb initialisation complete')
        except:
            speech.speak('sorry try again')
    if 'wires' in voice_data or 'why is' in voice_data:
        print("hello")
        voice_data = voice_data.split()
        if 'bread' in voice_data:
            voice_data[voice_data.index('bread')] = "red"
        if 'why' in voice_data and 'is' in voice_data:
            defuse_wires(voice_data[2:], check)
        else:
            defuse_wires(voice_data[1:], check)
    if 'button' in voice_data or 'butter' in voice_data:
        voice_data = voice_data.split()
        voice_data = voice_data[1:]
        if len(voice_data) > 2:
            if voice_data[2] == "boat":
                voice_data[1] == "abort"
        if voice_data[0] == "read":
            voice_data[0] = "red"
        print(voice_data)
        defuse_button(voice_data, check)
    if 'keypad' in voice_data or 'key pad' in voice_data or 'leappad' in voice_data:
        voice_data = voice_data.split()
        voice_data = voice_data[1:]
        if len(voice_data) == 4:
            if ('i' in voice_data):
                voice_data[voice_data.index('i')] = "eye"
            if ('6' in voice_data):
                voice_data[voice_data.index('6')] = "six"
            if ('ballooned' in voice_data):
                voice_data[voice_data.index('ballooned')] = "balloon"
            if "lampeter" in voice_data:
                voice_data[voice_data.index('lampeter')] = "lambda"
            if "lander" in voice_data:
                voice_data[voice_data.index('lander')] = "lambda"
            if len(voice_data) != len(set(voice_data)):
                speech.speak('sorry, try again')
            else:
                print(voice_data)
                defuse_keypad(voice_data, check)
        else:
            speech.speak('sorry, try again')
    if 'simon' in voice_data:
        voice_data = voice_data.split()
        voice_data = voice_data[1:]
        voice_data[0] = stringtoint(voice_data[0])

        if len(voice_data) == 3 or len(voice_data) == 4:
            if 'strikes' in voice_data:
                voice_data.pop(voice_data.index['strikes'])
            if 'flashing' in voice_data:
                voice_data.pop(voice_data.index['flashing'])

        if len(voice_data) == 2 or set(voice_data[1:]).issubset(
            ['blue', 'red', 'yellow', 'green']):
            if 'read' in voice_data or 'bread' in voice_data:
                voice_data[1] = 'red'
            if '0gn' in voice_data:
                voice_data = ['0', 'green']
            if '1gn' in voice_data:
                voice_data = ['1', 'green']
            if '2gn' in voice_data:
                voice_data = ['2', 'green']
            if 'zerocream' in voice_data:
                voice_data = ['0', 'green']
            print(voice_data)
            defuse_simon(voice_data, check)

        else:
            speech.speak('try again')

    if 'password' in voice_data:
        defuse_password()
    if 'exit' in voice_data or 'except' in voice_data or 'accent' in voice_data:
        exit()
    if 'oh my god' in voice_data:
        speech.speak('Its not my fault')
    if 'hello' in voice_data:
        speech.speak('hello, how are you?')
    if 'test' in voice_data:
        speech.speak('roger')
    if 'thank you' in voice_data:
        speech.speak('im a slave')
    if 'we did it' in voice_data:
        speech.speak('excuse me i did all the hard work')
    if 'skip' in voice_data:
        check = {
            'batteries': '2',
            'digit': '2',
            'parallel': 'no',
            'car': 'no',
            'freak': 'yes',
            'vowel': 'yes'
        }
        print(check)
        speech.speak('bomb initialisation default config')
Exemplo n.º 5
0
    if d == 'zero':
        d = 0
    elif d == 'one' or d == 'wan':
        d = 1
    elif d == 'two' or d == 'to' or d == 'too':
        d = 2
    elif d == 'three':
        d = 3
    elif d == 'four' or d == 'for':
        d = 4
    elif d == 'five':
        d = 5
    elif d == 'six' or d == 'sex':
        d = 6
    elif d == 'seven':
        d = 7
    elif d == 'eight':
        d = 8
    elif d == 'nine':
        d = 9
    return d


speech.speak('How can I help you?')

while True:
    print("READY")
    voice_data = speech.record_audio()
    print(voice_data)
    respond(voice_data)
Exemplo n.º 6
0
def defuse_password():
    alphabet = {
        'alpha': 'a',
        'bravo': 'b',
        'charlie': 'c',
        'delta': 'd',
        'echo': 'e',
        'foxtrot': 'f',
        'golf': 'g',
        "hotel": "h",
        'india': 'i',
        'juliet': 'j',
        'kilo': 'k',
        'lima': 'l',
        'mike': 'm',
        'november': 'n',
        'oscar': 'o',
        'papa': 'p',
        'quebec': 'q',
        'romeo': 'r',
        'sierra': 's',
        'tango': 't',
        'uniform': 'u',
        'victor': 'v',
        'whiskey': 'w',
        'xray': 'x',
        'yankee': 'y',
        'zulu': 'z'
    }

    passwords = [
        "about", "after", "again", "below", "could", "every", "first", "found",
        "great", "house", "large", "learn", "never", "other", "place", "plant",
        "point", "right", "small", "sound", "spell", "still", "study", "their",
        "there", "these", "thing", "think", "three", "water", "where", "which",
        "world", "would", "write"
    ]

    column = 0

    letters = [[], [], []]
    wrong = False
    while column < 3:
        speech.speak('column ' + str(column + 1))
        voice_data = speech.record_audio()
        print(voice_data)
        if 'exit' in voice_data:
            letters = None
            break
        voice_data = voice_data.split()
        for i in voice_data:
            if i == "whisky":
                i = "whiskey"
            if i == "x-ray":
                i = "xray"
            if i == "ecco":
                i = "echo"
            if i in alphabet.keys():
                letters[column].append(alphabet[i])
            else:
                wrong = True
                break
        print(letters)
        if len(letters[column]) != 6:
            wrong = True
        if wrong:
            wrong = False
            letters[column] = []
        else:
            column += 1

    try:
        answers = []
        for i in letters[0]:
            for j in letters[1]:
                for k in letters[2]:
                    for p in passwords:
                        if p.startswith(i + j + k):
                            answers.append(p)
        print(answers)
        if len(answers) == 1:
            speech.speak("The password is " + answers[0])
            spell_password(answers[0])
        elif len(answers) > 1:
            speech.speak("The password is either " + answers[0])
            spell_password(answers[0])
            for i in range(0, len(answers)):
                if i != 0:
                    speech.speak('or ' + answers[i])
                    spell_password(answers[i])
        else:
            speech.speak("Error try again")

        print(letters)
    except:
        pass