Example #1
0
 def execute_mods(self, text):
     """ Executes the modules in prioritized order """
     if len(self.matched_mods) <= 0:
         tts.speak(settings.NO_MODULES)
         return
     
     self.matched_mods.sort(key=lambda mod: mod.priority, reverse=True)
     
     normal_mods = []
     greedy_mods = []
     greedy_flag = False
     priority = 0
     for mod in self.matched_mods:
         if greedy_flag and mod.priority < priority:
             break
         if mod.greedy:
             greedy_mods.append(mod)
             greedy_flag = True
             priority = mod.priority
         else:
             normal_mods.append(mod)
 
     if len(greedy_mods) is 1:
         normal_mods.append(greedy_mods[0])
     elif len(greedy_mods) > 1:
         if 0 < len(normal_mods):
             print('\n~ Matched mods (non-greedy): '+str([mod.name for mod in normal_mods])[1:-1]+'\n')
         m = self.mod_select(greedy_mods)
         if not m:
             return
         normal_mods.append(m)
     for mod in normal_mods:
         self.execute_tasks(mod, text)
Example #2
0
    def run(self):
        """ Listen for input, match the modules and respond """
        while True:
            if self.quit_flag:
                break
            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

                self.match_mods(text)
                self.execute_mods(text)
            except OSError as e:
                if 'Invalid input device' in str(e):
                    tts.speak(settings.NO_MIC)
                    settings.USE_STT = False
                    continue
                else:
                    raise Exception
            except EOFError:
                print('\n\n~ Shutting down...')
                break
            except:
                if self.error():
                    print(traceback.format_exc())
                else:
                    break
        print('\n~ Arrivederci.')
Example #3
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 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 Speech Recognition
        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 Speech Recognition service; {0}".format(e))
    except:                             # speech is unintelligible
        tts.speak(settings.ERROR)
    finally:
        return msg
Example #4
0
 def error(self):
     """ Inform the user that an error occurred """
     tts.speak(settings.ERROR)
     text = eval(input('Continue? (Y/N) '))
     # response = stt.active_listen()
     if 'y' in text.lower():
         log.error(traceback.format_exc())
Example #5
0
    def run(self):
        """ Listen for input, match the modules and respond """
        while True:
            if self.quit_flag:
                break
            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

                self.match_mods(text)
                self.execute_mods(text)
            except OSError as e:
                if 'Invalid input device' in str(e):
                    tts.speak(settings.NO_MIC)
                    settings.USE_STT = False
                    continue
                else:
                    raise Exception
            except EOFError:
                print('\n\n~ Shutting down...')
                break
            except:
                if self.error():
                    print(traceback.format_exc())
                else:
                    break
        print('\n~ Arrivederci.')
Example #6
0
 def error(self):
     """ Inform the user that an error occurred """
     tts.speak(settings.ERROR)
     text = input('Continue? (Y/N) ')
     #response = stt.active_listen()
     
     return 'y' in text.lower()
Example #7
0
 def execute_mods(self, text):
     """ Executes the modules in prioritized order """
     if len(self.matched_mods) <= 0:
         tts.speak(settings.NO_MODULES)
         return
     
     self.matched_mods.sort(key=lambda mod: mod.priority, reverse=True)
     
     normal_mods = []
     greedy_mods = []
     greedy_flag = False
     priority = 0
     for mod in self.matched_mods:
         if greedy_flag and mod.priority < priority:
             break
         if mod.greedy:
             greedy_mods.append(mod)
             greedy_flag = True
             priority = mod.priority
         else:
             normal_mods.append(mod)
 
     if len(greedy_mods) is 1:
         normal_mods.append(greedy_mods[0])
     elif len(greedy_mods) > 1:
         if 0 < len(normal_mods):
             print('\n~ Matched mods (non-greedy): '+str([mod.name for mod in normal_mods])[1:-1]+'\n')
         m = self.mod_select(greedy_mods)
         if not m:
             return
         normal_mods.append(m)
     for mod in normal_mods:
         self.execute_tasks(mod, text)
Example #8
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 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 Speech Recognition
        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 Speech Recognition service; {0}"
            .format(e))
    except:  # speech is unintelligible
        tts.speak(settings.ERROR)
    finally:
        return msg
Example #9
0
 def error(self):
     """ Inform the user that an error occurred """
     tts.speak(settings.ERROR)
     text = input('Continue? (Y/N) ')
     # response = stt.active_listen()
     if 'y' in text.lower():
         print(traceback.format_exc())
Example #10
0
 def try_set_loc(self, zip_iata_city, state_country=None):
     if not self.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')
         tts.speak('Location not found.')
         return False
     return True
Example #11
0
 def try_set_loc(self, zip_iata_city, state_country=None):
     if not self.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'
         )
         tts.speak('Location not found.')
         return False
     return True
Example #12
0
'''
Created on Feb 11, 2016

@author: Connor
'''
from athena import tts
    
print('~ Enter \'q\' at any time to quit')
while True:
    
    fname = input('\n~ Unique Filename: ')
    if len(fname) is 0 or 'q' in fname[0].lower():
        break
    
    phrase = input('~ Phrase: ')
    if len(phrase) is 0 or 'q' in phrase[0].lower(): 
        break
    
    tts.speak(phrase, cache=True, filename=fname)
Example #13
0
 def speak(self, phrase, show_text=True):
     if show_text:
         print('\n~ '+phrase+'\n')
     speak(phrase)
Example #14
0
'''
Created on Feb 11, 2016

@author: Connor
'''
from athena import tts
    
print('~ Enter \'q\' at any time to quit')
while True:
    
    fname = input('\n~ Unique Filename: ')
    if len(fname) is 0 or 'q' in fname[0].lower():
        break
    
    phrase = input('~ Phrase: ')
    if len(phrase) is 0 or 'q' in phrase[0].lower(): 
        break
    
    tts.speak(phrase, cache=True, filename=fname)