Esempio n. 1
0
def run():
    while True:
        try:
            if settings.USE_STT:
                stt.listen_keyword()
                text = stt.active_listen()
            else:
                text = input('> ')
            if not text:
                print("\n~ No text input received.\n")
                continue
    
            matched_mods = match_mods(text)
                     
            if len(matched_mods) == 0:
                print('\n~ No modules matched.\n')
            else:
                mods = build_mod_order(matched_mods)
                execute_mods(mods, text)
                
        except EOFError:
            print('\n\n~ Shutting down...\n')
            break
        except:
            print(traceback.format_exc())
            tts.speak("Error occurred. Would you still like to continue?")
            print("Error occurred. Would you still like to continue?\n")
            response = input('> ')
            #response = stt.active_listen()
            
            if "yes" not in response.lower():
                break
    print('~ Arrivederci.')
Esempio n. 2
0
 def action(self, text):
     rand = r.random()
     chance = 0
     for k, v in EMOTIONS.items():
         chance += v
         if (rand < chance):
             tts.speak(r.choice(RESPONSES[k]))
             break
Esempio n. 3
0
def set_loc(api, zip_iata_city, state_country=None):
    if not api.update_loc(zip_iata_city, state_country):
        print('\n~ Location not found using:')
        if state_country:
            print('~ City:', zip_iata_city)
            print('~ State/Country:', state_country+'\n')
        else:
            print('~ Zip/Airport Code:', zip_iata_city+'\n')
        print('~ TIP: use underscores for spaces within names (e.g. "new_york_city")\n')
        speak('Location not found.')
        return False
    return True
Esempio n. 4
0
def active_listen():
    r = speech_recognition.Recognizer()

    with speech_recognition.Microphone() as src:    # use the default microphone as the audio source
        r.adjust_for_ambient_noise(src)             # listen for 1 second to calibrate the energy threshold for ambient noise levels
        print("\n~ Active listening... ")
        tts.play_mp3("double-beep.mp3")
        audio = r.listen(src)                       # listen for the first phrase and extract it into audio data
    
    msg = ''
    try:
        msg = r.recognize_google(audio)             # recognize speech using Google Speech Recognition
        print("\n~ \""+msg+"\"")
    except LookupError:                             # speech is unintelligible
        msg = ""
        print("\n~ "+ERROR_MESSAGE+"\n")
        tts.speak(ERROR_MESSAGE)
    finally:
        return msg
Esempio n. 5
0
 def list_weather(self, output, value):
     print('~ '+output+':', value)
     if not self.spoke_once:
         speak('The '+output.lower()+' in '+self.api.location()+' is '+value)
         self.spoke_once = True
Esempio n. 6
0
 def speak(self, phrase, print_phrase=True):
     if print_phrase:
         print("\n~ "+phrase+"\n")
     speak(phrase)