Ejemplo n.º 1
0
def listen():
    r = sr.Recognizer()
    with sr.Microphone(sample_rate = 48000) as source:
        say('Calibrating. Silence, please.')
        log.update('calibrating noise level')
        r.adjust_for_ambient_noise(source)
        log.update('energy threshold at ' + str(r.energy_threshold))

        say('Ready.')
        while True:
            # obtain audio from the microphone
            log.update('listening for speech')
            audio = r.listen(source)
            log.update('processing speech')
            with open('/tmp/teleradio.wav', 'wb') as f:
                f.write(audio.get_wav_data())
            audio_bytes = BytesIO(audio.get_wav_data())
            nlp.handle_audio(audio = audio_bytes)
Ejemplo n.º 2
0
def light_set(text, entities):
    state = nlp.top_confidence(entities=entities,
                               entity_name='gpio_state',
                               min_confidence=.75)
    if state == 'on':
        say('Turning light on')
        return
    if state == 'off':
        say('Turning light off')
        return
    if state == 'toggle':
        say('Toggling light')
        return
    log.warning('light_set state unclear')
    say('Clarify what to do with the light.')
    return
Ejemplo n.º 3
0
def shutdown(text, entities):
    say('Shutting down')
    os.system('shutdown -h now')
Ejemplo n.º 4
0
def reboot(text, entities):
    say('Rebooting')
    os.system('reboot')
Ejemplo n.º 5
0
def ip_get(text, entities):
    say('I P functionality not ready yet.')
Ejemplo n.º 6
0
def update(text, entities):
    say('Update functionality not ready yet.')