def takeCommand():
        #It takes microphone input from the user and returns string output

        r = sr.Recognizer()
        with sr.Microphone() as source:
            print("Listening...")
            r.pause_threshold = 1
            audio = r.listen(source)

        try:
            print("Recognizing...")    
            query = r.recognize_google(audio, language='en-in')
            print(f"User said: {query}\n")

        except Exception as e:
            # print(e)    
            print("Say that again please...")  
            return "None"
        return query
Beispiel #2
0
def bot_start(chatbot):
    c = 0
    while (True):
        if c == 1:
            spawn_program_and_die(['python', 'error_page.py'])
        try:
            with sr.Microphone() as source2:
                r.adjust_for_ambient_noise(source2, duration=0.2)
                audio2 = r.listen(source2)
                MyText = r.recognize_google(audio2)
                MyText = MyText.lower()
                print(MyText)
                if ("object recog" in MyText):
                    SpeakText("enabling object detector")
                    from yolo import yolo
                    print("opening object detection")
                elif ("play song" in MyText):
                    SpeakText("opening song player")
                    global n
                    n = (MyText[10:])
                    import play_song
                elif ("read text" in MyText):
                    SpeakText("opening text reader")
                    import tes
                elif ("currency" in MyText):
                    SpeakText("opening Currency Detector")
                    import pred_test
                elif (MyText == "bye"):
                    exit()
                else:
                    response = chatbot.get_response(MyText)
                    print(response)
                    SpeakText(str(response))

        except sr.RequestError as e:
            print("Could not request results; {0}".format(e))

        except sr.UnknownValueError:
            c += 1
            print("unknown error occured")
Beispiel #3
0
                z = s[q:]
                q = 0
                for i in z:
                    q += 1
                    if i == ':':
                        s = z[q:]
        s = ('%s' % data) + ' :  ' + s
        # p = a.ccbox(msg=s, choices=('ok', 'quit'))
        # if p == False:
        #     break
        con.send(s.encode())


s = socket.socket()
s.bind(('0.0.0.0', 8888))
s.listen(10)
while 1:
    try:
        con, addr = s.accept()
        print(addr)
    except:
        continue
    pid = os.fork()
    if pid == 0:
        s.close()
        while 1:
            s = fanyi(con)
            if s != 'None':
                print(s)
                break
    else: