Beispiel #1
0
def stt():
    at.transcode(OGG_FILE,WAV_FILE)
    r = sr.Recognizer()
    with sr.WavFile(WAV_FILE) as source:
        audio = r.record(source) # read the entire WAV file
        # recognize speech using Google Speech Recognition
        try:
            # for testing purposes, we're just using the default API key
            # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
            # instead of `r.recognize_google(audio)`
            msg = r.recognize_google(audio,language='it')
        except sr.UnknownValueError:
            msg="Google Speech Recognition could not understand audio"
        except sr.RequestError as e:
            msg="Could not request results from Google Speech Recognition service; {0}".format(e)
        print(msg)
        return msg
    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 #3
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")