Esempio n. 1
0
def active_listen():
    """
    Actively listens for speech to translate into text
    :return: speech input as a text string
    """
    global r
    # use the default microphone as the audio source
    with tts.ignore_stderr():
        with speech_recognition.Microphone() as src:
            # listen for 1 second to adjust energy threshold for ambient noise
            # r.adjust_for_ambient_noise(src)
            print("\n~ Active listening... ")
            tts.play_mp3('double-beep.mp3')

            # listen for the first phrase and extract it into audio data
            audio = r.listen(src)

    msg = ''
    try:
        msg = r.recognize_google(audio)  # recognize speech using Google STT
        print('\n~ "'+msg+'"')
    except speech_recognition.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except speech_recognition.RequestError as e:
        print("Could not request results from Google STT; {0}".format(e))
    except:                              # speech is unintelligible
        brain.inst.error()
    finally:
        return msg
Esempio n. 2
0
def active_listen():
    """
    Actively listens for speech to translate into text
    :return: speech input as a text string
    """
    global r
    # use the default microphone as the audio source
    with tts.ignore_stderr():
        with speech_recognition.Microphone() as src:
            # listen for 1 second to adjust energy threshold for ambient noise
            # r.adjust_for_ambient_noise(src)
            log.info("Active listening... ")
            tts.play_mp3('double-beep.mp3')

            # listen for the first phrase and extract it into audio data
            audio = r.listen(src)

    msg = ''
    try:
        msg = r.recognize_google(audio)  # recognize speech using Google STT
    except speech_recognition.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except speech_recognition.RequestError as e:
        print(("Could not request results from Google STT; {0}".format(e)))
    except:
        print("Unknown exception occurred!")
    finally:
        return msg
Esempio n. 3
0
def listen_keyword():
    """ Passively listens for the WAKE_UP_WORD string """
    with tts.ignore_stderr():
        global decoder, p
        stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000,
                        input=True, frames_per_buffer=1024)
        stream.start_stream()
        p.get_default_input_device_info()

    log.info("Waiting to be woken up... ")
    decoder.start_utt()
    while True:
        buf = stream.read(1024)
        decoder.process_raw(buf, False, False)
        if decoder.hyp() and decoder.hyp().hypstr == settings.WAKE_UP_WORD:
            decoder.end_utt()
            return
    decoder.end_utt()
Esempio n. 4
0
def listen_keyword():
    """
    Passively listens for the WAKE_UP_WORD string
    """
    with tts.ignore_stderr():
        global decoder, p
        stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000,
                        input=True, frames_per_buffer=1024)
        stream.start_stream()
        p.get_default_input_device_info()

    print("~ Waiting to be woken up... ")
    decoder.start_utt()
    while True:
        buf = stream.read(1024)
        decoder.process_raw(buf, False, False)
        if decoder.hyp() and decoder.hyp().hypstr == settings.WAKE_UP_WORD:
            decoder.end_utt()
            return
    decoder.end_utt()