def __init__(self): self._logger = logging.getLogger(__name__) # Read config config_file = os.path.abspath(os.path.join(jasperpath.LIB_PATH, 'profile.yml')) self._logger.debug("Trying to read config file: '%s'", config_file) with open(config_file, "r") as f: self.config = yaml.safe_load(f) try: api_key = self.config['keys']['GOOGLE_SPEECH'] except KeyError: api_key = None try: stt_engine_type = self.config['stt_engine'] except KeyError: stt_engine_type = "sphinx" self._logger.warning("stt_engine not specified in profile, defaulting to '%s'", stt_engine_type) # Compile dictionary sentences, dictionary, languagemodel = [os.path.abspath(os.path.join(jasperpath.LIB_PATH, filename)) for filename in ("sentences.txt", "dictionary.dic", "languagemodel.lm")] vocabcompiler.compile(sentences, dictionary, languagemodel) # Initialize Mic self.mic = Mic(speak.newSpeaker(), stt.PocketSphinxSTT(), stt.newSTTEngine(stt_engine_type, api_key=api_key))
def __init__(self): # Read config config_file = os.path.abspath(os.path.join(client_path, 'profile.yml')) logger.debug("Trying to read config file: '%s'", config_file) with open(config_file, "r") as f: self.config = yaml.safe_load(f) try: api_key = self.config['keys']['GOOGLE_SPEECH'] except KeyError: api_key = None try: stt_engine_type = self.config['stt_engine'] except KeyError: stt_engine_type = "sphinx" logger.warning("stt_engine not specified in profile, defaulting to '%s'", stt_engine_type) # Compile dictionary sentences, dictionary, languagemodel = [os.path.abspath(os.path.join(client_path, filename)) for filename in ("sentences.txt", "dictionary.dic", "languagemodel.lm")] vocabcompiler.compile(sentences, dictionary, languagemodel) # Initialize Mic self.mic = Mic(speak.newSpeaker(), stt.PocketSphinxSTT(), stt.newSTTEngine(stt_engine_type, api_key=api_key))
def __init__(self): self._logger = logging.getLogger(__name__) # Create config dir if it does not exist yet if not os.path.exists(jasperpath.CONFIG_PATH): try: os.makedirs(jasperpath.CONFIG_PATH) except OSError: self._logger.error("Could not create config dir: '%s'", jasperpath.CONFIG_PATH, exc_info=True) raise # Check if config dir is writable if not os.access(jasperpath.CONFIG_PATH, os.W_OK): self._logger.critical("Config dir %s is not writable. Jasper won't work correctly.") # FIXME: For backwards compatibility, move old config file to newly created config dir old_configfile = os.path.join(jasperpath.LIB_PATH, 'profile.yml') new_configfile = jasperpath.config('profile.yml') if os.path.exists(old_configfile): if os.path.exists(new_configfile): self._logger.warning("Deprecated profile file found: '%s'. Please remove it.", old_configfile) else: self._logger.warning("Deprecated profile file found: '%s'. Trying to copy it to new location '%s'.", old_configfile, new_configfile) try: shutil.copy2(old_configfile, new_configfile) except shutil.Error: self._logger.error("Unable to copy config file. Please copy it manually.", exc_info=True) raise # Read config self._logger.debug("Trying to read config file: '%s'", new_configfile) try: with open(new_configfile, "r") as f: self.config = yaml.safe_load(f) except OSError: self._logger.error("Can't open config file: '%s'", new_configfile) raise try: api_key = self.config['keys']['GOOGLE_SPEECH'] except KeyError: api_key = None try: stt_engine_type = self.config['stt_engine'] except KeyError: stt_engine_type = "sphinx" self._logger.warning("stt_engine not specified in profile, defaulting to '%s'", stt_engine_type) try: tts_engine_slug = self.config['tts_engine'] except KeyError: tts_engine_slug = tts.get_default_engine_slug() logger.warning("tts_engine not specified in profile, defaulting to '%s'", tts_engine_slug) tts_engine_class = tts.get_engine_by_slug(tts_engine_slug) # Compile dictionary sentences, dictionary, languagemodel = [jasperpath.config(filename) for filename in ("sentences.txt", "dictionary.dic", "languagemodel.lm")] vocabcompiler.compile(sentences, dictionary, languagemodel) # Initialize Mic self.mic = Mic(tts_engine_class(), stt.PocketSphinxSTT(), stt.newSTTEngine(stt_engine_type, api_key=api_key))
def getNewProfile(mic, profile): #This line bug ! mic.say('Who are you?') input = raw_input("Your name : ") if input=='': profile_file='profile.yml' else: profile_file='profile-'+input+'.yml' mic.say('Hello '+input+" . You're the new user now" ) #TODO replace by directly reading the config file and changing the var profile #argument = list() #argument.append(sys.argv[0]) #for arg in sys.argv[1:]: # argument.append(arg) logger = logging.getLogger(__name__) # FIXME: For backwards compatibility, move old config file to newly # created config dir old_configfile = os.path.join(jasperpath.LIB_PATH, profile_file) new_configfile = jasperpath.config(profile_file) if os.path.exists(old_configfile): if os.path.exists(new_configfile): logger.warning("Deprecated profile file found: '%s'. " + "Please remove it.", old_configfile) else: logger.warning("Deprecated profile file found: '%s'. " + "Trying to copy it to new location '%s'.", old_configfile, new_configfile) try: shutil.copy2(old_configfile, new_configfile) except shutil.Error: logger.error("Unable to copy config file. " + "Please copy it manually.", exc_info=True) raise # Read config logger.debug("Trying to read config file: '%s'", new_configfile) try: with open(new_configfile, "r") as f: #Where the magic is. Clear the dict and then update it profile.clear() profile.update(yaml.safe_load(f)) except OSError: logger.error("Can't open config file: '%s'", new_configfile) raise try: api_key = profile['keys']['GOOGLE_SPEECH'] except KeyError: api_key = None try: stt_engine_type = profile['stt_engine'] except KeyError: stt_engine_type = "sphinx" logger.warning("stt_engine not specified in profile, " + "defaulting to '%s'", stt_engine_type) try: tts_engine_slug = profile['tts_engine'] except KeyError: tts_engine_slug = tts.get_default_engine_slug() logger.warning("tts_engine not specified in profile, defaulting " + "to '%s'", tts_engine_slug) tts_engine_class = tts.get_engine_by_slug(tts_engine_slug) #TODO To test ! flag=0 for arg in sys.argv[1:]: if(arg == '--local'): from client.local_mic import Mic flag=1 if flag==0: from client.mic import Mic # Initialize Mic mic = Mic(tts_engine_class(), stt.PocketSphinxSTT(**stt.PocketSphinxSTT.get_config()), stt.newSTTEngine(stt_engine_type, api_key=api_key))
print " Copyright 2013 Shubhro Saha & Charlie Marsh " print "===========================================================" speaker.say("Hello.... I am Jasper... Please wait one moment.") testConnection() configure() profile = yaml.safe_load(open("profile.yml", "r")) try: api_key = profile['keys']['GOOGLE_SPEECH'] except KeyError: api_key = None try: stt_engine_type = profile['stt_engine'] except KeyError: print "stt_engine not specified in profile, defaulting to PocketSphinx" stt_engine_type = "sphinx" mic = Mic(speaker, stt.PocketSphinxSTT(), stt.newSTTEngine(stt_engine_type, api_key=api_key)) addendum = "" if 'first_name' in profile: addendum = ", %s" % profile["first_name"] mic.say("How can I be of service%s?" % addendum) conversation = Conversation("JASPER", mic, profile) conversation.handleForever()
def getNewProfile(mic, profile): #This line bug ! mic.say('Who are you?') input = raw_input("Your name : ") if input == '': profile_file = 'profile.yml' else: profile_file = 'profile-' + input + '.yml' mic.say('Hello ' + input + " . You're the new user now") #TODO replace by directly reading the config file and changing the var profile #argument = list() #argument.append(sys.argv[0]) #for arg in sys.argv[1:]: # argument.append(arg) logger = logging.getLogger(__name__) # FIXME: For backwards compatibility, move old config file to newly # created config dir old_configfile = os.path.join(jasperpath.LIB_PATH, profile_file) new_configfile = jasperpath.config(profile_file) if os.path.exists(old_configfile): if os.path.exists(new_configfile): logger.warning( "Deprecated profile file found: '%s'. " + "Please remove it.", old_configfile) else: logger.warning( "Deprecated profile file found: '%s'. " + "Trying to copy it to new location '%s'.", old_configfile, new_configfile) try: shutil.copy2(old_configfile, new_configfile) except shutil.Error: logger.error("Unable to copy config file. " + "Please copy it manually.", exc_info=True) raise # Read config logger.debug("Trying to read config file: '%s'", new_configfile) try: with open(new_configfile, "r") as f: #Where the magic is. Clear the dict and then update it profile.clear() profile.update(yaml.safe_load(f)) except OSError: logger.error("Can't open config file: '%s'", new_configfile) raise try: api_key = profile['keys']['GOOGLE_SPEECH'] except KeyError: api_key = None try: stt_engine_type = profile['stt_engine'] except KeyError: stt_engine_type = "sphinx" logger.warning( "stt_engine not specified in profile, " + "defaulting to '%s'", stt_engine_type) try: tts_engine_slug = profile['tts_engine'] except KeyError: tts_engine_slug = tts.get_default_engine_slug() logger.warning( "tts_engine not specified in profile, defaulting " + "to '%s'", tts_engine_slug) tts_engine_class = tts.get_engine_by_slug(tts_engine_slug) #TODO To test ! flag = 0 for arg in sys.argv[1:]: if (arg == '--local'): from client.local_mic import Mic flag = 1 if flag == 0: from client.mic import Mic # Initialize Mic mic = Mic(tts_engine_class(), stt.PocketSphinxSTT(**stt.PocketSphinxSTT.get_config()), stt.newSTTEngine(stt_engine_type, api_key=api_key))
def start(self): def testConnection(): if Diagnostics.check_network_connection(): print "CONNECTED TO INTERNET" else: print "COULD NOT CONNECT TO NETWORK" self.speaker.say( "Warning: I was unable to connect to a network. Parts of the system may not work correctly, depending on your setup.") def fail(message): traceback.print_exc() self.speaker.say(message) sys.exit(1) def configure(): try: print "COMPILING DICTIONARY FOR MODULES" vocabcompiler.compile( "sentences.txt", "dictionary.dic", "languagemodel.lm") print "COMPILING DICTIONARY OF LOCATIONS OPTIONS" vocabcompiler.compileLocations( "sentences_locations.txt", "dictionary_locations.dic", "languagemodel_locations.lm"); print "STARTING CLIENT PROGRAM" except OSError: print "BOOT FAILURE: OSERROR" fail( "There was a problem starting EasyNav. You may be missing the language model and associated files. Please read the documentation to configure your Raspberry Pi.") except IOError: print "BOOT FAILURE: IOERROR" fail( "There was a problem starting EasyNav. You may have set permissions incorrectly on some part of the filesystem. Please read the documentation to configure your Raspberry Pi.") except: print "BOOT FAILURE" fail( "There was a problem starting EasyNav.") old_client = os.path.abspath(os.path.join(os.pardir, "old_client")) if os.path.exists(old_client): shutil.rmtree(old_client) print "===========================================================" print " JASPER The Talking Computer " print " Copyright 2013 Shubhro Saha & Charlie Marsh " print "===========================================================" self.speaker.say("Hello.... I am EASYNAV... Please wait one moment while I configure.") configure() profile = yaml.safe_load(open("profile.yml", "r")) try: api_key = profile['keys']['GOOGLE_SPEECH'] except KeyError: api_key = None try: stt_engine_type = profile['stt_engine'] except KeyError: print "stt_engine not specified in profile, defaulting to PocketSphinx" stt_engine_type = "sphinx" mic = Mic(self.speaker, stt.PocketSphinxSTT(), stt.newSTTEngine(stt_engine_type, api_key=api_key)) mic.say("Hi...i'm EasyNav.....your friendly navigation assistant....") mic.say("To invoke me, please say my Name......and i will beep....then proceed with your command") mic.say("To find out about commands...please say help......") self.dispatcherClient.start() #GetLocations.getLoc() conversation = Conversation("EASYNAV", mic, profile, self.dispatcherClient) conversation.handleForever()