예제 #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
예제 #2
0
파일: stt.py 프로젝트: masomel/py-iot-apps
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
예제 #3
0
파일: stt.py 프로젝트: masomel/py-iot-apps
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()
예제 #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()