예제 #1
0
def getSpeech():
    reader = speech_recognizer.Recognizer()
    with speech_recognizer.Microphone() as mic:
        audio = reader.listen(mic)
    try:
        print(
            r.getClarissaSetting("main", "user.name") + ": " +
            reader.recognize_google(audio))
        return reader.recognize_google(audio)
    except speech_recognizer.UnknownValueError:
        if (r.getClarissaSetting("speech", "speak_out") == "true"):
            tts.init("I'm sorry. I could not understand that.", 'en-US', False)
        print("Clarissa: I'm sorry. I could not understand that")
    except speech_recognizer.RequestError as error:
        if ("recognition connection failed" in "{0}".format(error)):
            if (r.getClarissaSetting("speech", "speak_out") == "true"):
                tts.init(
                    "I need an internet connection for speech recognition. I will disable speech recognition. You can later re-enable it by running python bot.py --enable-speech-recognition",
                    'en-US', False)
            print(
                "Clarissa: I need an internet connection for speech recognition. I will disable speech recognition. You can later re-enable it by running python bot.py --enable-speech-recognition"
            )
            w.setClarissaSetting("speech", "hey_clarissa_enabled", "false")

            toBot(messageToBot=input(
                r.getClarissaSetting("main", "user.name") + ": "))
        print("Clarissa: Could not process: {0}".format(error))
        if (r.getClarissaSetting("speech", "speak_out") == "true"):
            tts.init("Could not process {0}".format(error), 'en-US', False)
    except (KeyboardInterrupt, SystemExit):
        shutil.rmtree("Audio/", True)
        bot.getResponse("kill-bot")
예제 #2
0
파일: bot.py 프로젝트: Clarissa-Bot/Setup
def toBot():
    reload(bot)
    reload(learner)
    if (os.path.isfile(".bot_engage")):
        print("You can only run one instance of Clarissa.")
    else:
        swearNum = 1
        setup_ext = open(".setup_ext", 'r')
        for line in setup_ext.readlines():
            if "install=" in line:
                os.environ['CLARISSA_PATH'] = line.replace("install=", "")
        os.environ['USER_NAME'] = r.getClarissaSetting("user.name").replace(
            "\n", "")
        messageToBot = input(os.environ['USER_NAME'].replace("\n", "") + ": ")
        if (messageToBot == "--add-command"):
            writeCommand(command=input("Command: "),
                         response=input("Responses: "))
            reload(bot)
        elif (messageToBot == "kill-bot"):
            bot.getResponse("kill-bot")
            exit()
        elif (messageToBot == "--clear-commands"):
            #os.remove("commands.bot")
            #os.remove("responses.bot")]
            print("Cleared commands")
            exit()
        elif (messageToBot == "learn"):
            learner.learn(db_support=False)
        elif (messageToBot == "--get-commands"):
            commandsList = open("commands.list", "r")
            print(commandsList.read())
        elif (messageToBot == "--get-logs"):
            logs = open('chat.log', 'r')
            print(logs.read())
        elif (messageToBot == "--update-clarissa"):
            urllib.urlopen("https://softy.xyz/apps/sites/clarissa/get.php")
            response = urllib.request.urlopen(
                "https://softy.xyz/apps/sites/clarissa/clarissa.json")
            import json
            file = json.loads(response.read())
            print(file['command'])
        elif ("Call me " in messageToBot):
            w.setClarissaSetting("user.name",
                                 messageToBot.replace("Call me ", ""))
        elif ("call me " in messageToBot):
            w.setClarissaSetting("user.name",
                                 messageToBot.replace("call me ", ""))
        log.log("chat.log", messageToBot)
        if (r.getClarissaSetting("ro.Clarissa.FROM_SERVER") is "true"):
            print("Get the response from a server")
        else:
            bot.getResponse(messageToBot)
        toBot()
예제 #3
0
def setupClarissa(install_path):
    useWebServices()
    os.remove("setup.ini")
    if (os.path.isfile("setup.ini")):
        out = open('setup.ini', 'a')
        del_settings = input(
            "This will delete your current settings. Do you wish to continue? (Y/N)"
        )
        if "y" in del_settings.lower():
            os.remove("rm -R Settings")
            os.mkdir("Settings")
        else:
            exit()

    else:
        if not os.path.exists(install_path + "/Settings"):
            os.mkdir(install_path + "/Settings")
        out = open('setup.ini', 'w')
    print("Setting up Clarissa. This should not take long.")
    setup = open(os.environ['USERPROFILE'] + "/._clarissa.py", 'w')
    setup.write("import os\n")
    setup.write("os.environ['CLARISSA_PATH']=r\"" + install_path + "\"")
    setup.flush()
    setup.close()
    os.environ['CLARISSA_PATH'] = install_path
    w.setClarissaSettingWithPath("setup.ini", "main", "install", install_path)
    w.setClarissaSetting("main", "auto_update", "true")
    w.setClarissaSetting("speech", "hey_clarissa_enabled", "false")
    w.setClarissaSetting("speech", "speak_out", "false")
    w.setClarissaSetting("main", "user.name", input("Your username: "******"chatterbot.corpus.english")
    os.system("pip install -r TO_INSTALL.txt")
예제 #4
0
파일: bot.py 프로젝트: Clarissa-Bot/Setup
     #os.remove("responses.bot")
     os.remove("bot_response.py")
     writeCommand("Hello", "Hi")
     print("Cleared commands")
 elif ("learn" in sys.argv):
     learner.learn(db_support=False)
 elif ("--get-commands" in sys.argv):
     commandsList = open("commands.list", "r")
     print(commandsList.read())
 elif ("--update-clarissa" in sys.argv):
     os.system("python update.py")
 elif ("--get-logs" in sys.argv):
     logs = open('chat.log', 'r')
     print(logs.read())
 elif (sys.argv[1] == "set.name"):
     w.setClarissaSetting("user.name", sys.argv[2])
 elif (sys.argv[1] == "--get-setting"):
     print(getClarissaSetting(sys.argv[2]))
 elif (sys.argv[1] == "--update-from-url"):
     os.system("python update.py --from-url " + sys.argv[2])
 elif ("--enable-auto-update" in sys.argv):
     w.setClarissaSettingWithPath("Settings/update.settings",
                                  "Clarissa.AUTO_UPDATE", "true")
 elif ("--update-bot" in sys.argv):
     os.system("python update.py")
 elif ("--help" in sys.argv or "--h" in sys.argv):
     print("Commands:")
     print("\t--add-command : Adds command to Clarissa")
     print("\t--clear-commands : Clears all added custom commands")
     print("\t--get-commands : Prints a list of Clarissa commands")
     print("\t--update-clarissa : Adds messages")
예제 #5
0
def init(to_speak, language, is_slow):
	print("We are working on improving tts")
	import writer
	writer.setClarissaSetting("main","speak_out", "false")
예제 #6
0
def toBot(messageToBot):
    try:
        reload(bot)
        reload(learner)
        if (messageToBot == None):
            messageToBot = getSpeech()
        if (os.path.isfile(".bot_engage")):
            print("You can only run one instance of Clarissa.")
        else:
            swearNum = 1
            os.environ['CLARISSA_PATH'] = r.getClarissaSettingWithPath(
                "setup.ini", "main", "install")
            os.environ['USER_NAME'] = r.getClarissaSetting("main", "user.name")
            if (messageToBot == "--add-command"):
                writeCommand(command=input("Command: "),
                             response=input("Responses: "))
                reload(bot)
            elif (messageToBot == "kill-bot"):
                exit()
            elif (messageToBot == "--clear-commands"):
                #os.remove("commands.bot")
                #os.remove("responses.bot")]
                print("Cleared commands")
                exit()
            elif (messageToBot == "learn"):
                learner.learn(db_support=False)
            elif (messageToBot == "--get-commands"):
                commandsList = open("commands.list", "r")
                print(commandsList.read())
            elif (messageToBot == "--get-logs"):
                logs = open('chat.log', 'r')
                print(logs.read())
            elif (messageToBot == "--update-clarissa"):
                urllib.urlopen("https://softy.xyz/apps/sites/clarissa/get.php")
                response = urllib.request.urlopen(
                    "https://softy.xyz/apps/sites/clarissa/clarissa.json")
                import json
                file = json.loads(response.read())
                print(file['command'])
            elif (messageToBot == "list the commands"):
                file = open("commands.list", 'r')
                for line in file.readlines():
                    print("Clarissa: " + line)
            elif ("Call me " in messageToBot):
                w.setClarissaSetting("main", "user.name",
                                     messageToBot.replace("Call me ", ""))
            elif ("call me " in messageToBot):
                w.setClarissaSetting("main", "user.name",
                                     messageToBot.replace("call me ", ""))
            elif ("Run " in messageToBot):
                apps = Apps()
                if (apps.does_app_exist(messageToBot.replace("Run ",
                                                             "")) == True):
                    apps.run(messageToBot.replace("Run ", ""))
                    return None
                else:
                    print(messageToBot.replace("Run ", "") + " was not found")
                    if (clarissa_voice_recognition_enabled == True):
                        toBot(messageToBot=getSpeech())
                    else:
                        toBot(messageToBot=input(
                            r.getClarissaSetting("main", "user.name") + ": "))
            elif ("run " in messageToBot):
                apps = Apps()
                if (apps.does_app_exist(messageToBot.replace("run ",
                                                             "")) == True):
                    apps.run(messageToBot.replace("run ", ""))
                    return None
                else:
                    print(messageToBot.replace("run ", "") + " was not found")
                    if (clarissa_voice_recognition_enabled == True):
                        toBot(messageToBot=getSpeech())
                    else:
                        toBot(messageToBot=input(
                            r.getClarissaSetting("main", "user.name") + ": "))
            elif ("Make app" in messageToBot):
                apps = Apps()
                apps.make_app(input("App name:"))
            elif ("make app" in messageToBot):
                apps = Apps()
                apps.make_app(input("App name:"))

            log.log("chat.log", messageToBot)
            cpu_def = CPU()
            cpu_def.run_code(code=bot.getResponse(messageToBot))
            if (clarissa_voice_recognition_enabled == True):
                toBot(messageToBot=getSpeech())
            else:
                toBot(messageToBot=input(
                    r.getClarissaSetting("main", "user.name") + ": "))
    except TypeError:
        if (clarissa_voice_recognition_enabled is True):
            toBot(getSpeech())
        else:
            toBot(messageToBot=input(
                r.getClarissaSetting("main", "user.name") + ": "))
    except (KeyboardInterrupt, SystemExit):
        bot.getResponse("kill-bot")
예제 #7
0
     os.remove("bot_response.py")
     writeCommand("Hello", "Hi")
     print("Cleared commands")
 elif ("learn" in sys.argv):
     learner.learn(db_support=False)
 elif ("--get-commands" in sys.argv):
     commandsList = open("commands.list", "r")
     print(commandsList.read())
 elif ("--update-clarissa" in sys.argv):
     os.system("python update.py")
     print("Clarissa: Updating won't work just yet.")
 elif ("--get-logs" in sys.argv):
     logs = open('chat.log', 'r')
     print(logs.read())
 elif (sys.argv[1] == "set.name"):
     w.setClarissaSetting("main", "user.name", sys.argv[2])
 elif (sys.argv[1] == "--get-setting"):
     print(getClarissaSetting("main", sys.argv[2]))
 elif (sys.argv[1] == "--update-from-url"):
     os.system("python update.py --from-url " + sys.argv[2])
 elif ("--enable-auto-update" in sys.argv):
     w.setClarissaSettingWithPath("Settings/Clarissa.ini", "update",
                                  "Clarissa.AUTO_UPDATE", "true")
 elif ("--update-bot" in sys.argv):
     os.system("python update.py")
 elif (sys.argv[1] == "--set-setting"):
     w.setClarissaSetting(sys.argv[2], sys.argv[3], sys.argv[4])
 elif ("--enable-speech-recognition" in sys.argv):
     w.setClarissaSetting("speech", "hey_clarissa_enabled", "true")
 elif ("--disable-speech-recognition" in sys.argv):
     w.setClarissaSetting("speech", "hey_clarissa_enabled", "false")