def __init__(self, lmd=jasperpath.config("languagemodel.lm"), dictd=jasperpath.config("dictionary.dic"), lmd_persona=jasperpath.data("languagemodel_persona.lm"), dictd_persona=jasperpath.data("dictionary_persona.dic"), lmd_music=None, dictd_music=None, hmm_dir="/usr/local/share/pocketsphinx/model/hmm/en_US/" + "hub4wsj_sc_8k"): """ Initiates the pocketsphinx instance. Arguments: speaker -- handles platform-independent audio output lmd -- filename of the full language model dictd -- filename of the full dictionary (.dic) lmd_persona -- filename of the 'Persona' language model (containing, e.g., 'Jasper') dictd_persona -- filename of the 'Persona' dictionary (.dic) """ self._logger = logging.getLogger(__name__) # quirky bug where first import doesn't work try: import pocketsphinx as ps except: import pocketsphinx as ps self._logfiles = {} with tempfile.NamedTemporaryFile(prefix='psdecoder_music_', suffix='.log', delete=False) as f: self._logfiles[TranscriptionMode.MUSIC] = f.name with tempfile.NamedTemporaryFile(prefix='psdecoder_keyword_', suffix='.log', delete=False) as f: self._logfiles[TranscriptionMode.KEYWORD] = f.name with tempfile.NamedTemporaryFile(prefix='psdecoder_normal_', suffix='.log', delete=False) as f: self._logfiles[TranscriptionMode.NORMAL] = f.name self._decoders = {} if lmd_music and dictd_music: self._decoders[TranscriptionMode.MUSIC] = \ ps.Decoder(hmm=hmm_dir, lm=lmd_music, dict=dictd_music, logfn=self._logfiles[TranscriptionMode.MUSIC]) self._decoders[TranscriptionMode.KEYWORD] = \ ps.Decoder(hmm=hmm_dir, lm=lmd_persona, dict=dictd_persona, logfn=self._logfiles[TranscriptionMode.KEYWORD]) self._decoders[TranscriptionMode.NORMAL] = \ ps.Decoder(hmm=hmm_dir, lm=lmd, dict=dictd, logfn=self._logfiles[TranscriptionMode.NORMAL])
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", jasperpath.CONFIG_PATH) configFileName = 'profile.%s.yml' % l10n.macsen_language configfile = jasperpath.config(configFileName) # Read config self._logger.debug("Trying to read config file: '%s'", configfile) try: with open(configfile, "r") as f: self.config = yaml.safe_load(f) except OSError: self._logger.error("Can't open config file: '%s'", configfile) raise
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'ivona-tts' in profile: if 'access_key' in profile['ivona-tts']: config['access_key'] = \ profile['ivona-tts']['access_key'] if 'secret_key' in profile['ivona-tts']: config['secret_key'] = \ profile['ivona-tts']['secret_key'] if 'region' in profile['ivona-tts']: config['region'] = profile['ivona-tts']['region'] if 'voice' in profile['ivona-tts']: config['voice'] = profile['ivona-tts']['voice'] if 'speech_rate' in profile['ivona-tts']: config['speech_rate'] = \ profile['ivona-tts']['speech_rate'] if 'sentence_break' in profile['ivona-tts']: config['sentence_break'] = \ profile['ivona-tts']['sentence_break'] return config
def _compile_vocabulary(self, phrases): prefix = 'jasper' tmpdir = tempfile.mkdtemp() lexicon_file = jasperpath.data('julius-stt', 'VoxForge.tgz') lexicon_archive_member = 'VoxForge/VoxForgeDict' profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'julius' in profile: if 'lexicon' in profile['julius']: lexicon_file = profile['julius']['lexicon'] if 'lexicon_archive_member' in profile['julius']: lexicon_archive_member = \ profile['julius']['lexicon_archive_member'] lexicon = JuliusVocabulary.VoxForgeLexicon(lexicon_file, lexicon_archive_member) # Create grammar file tmp_grammar_file = os.path.join(tmpdir, os.extsep.join([prefix, 'grammar'])) with open(tmp_grammar_file, 'w') as f: grammar = self._get_grammar(phrases) for definition in grammar.pop('S'): f.write("%s: %s\n" % ('S', ' '.join(definition))) for name, definitions in grammar.items(): for definition in definitions: f.write("%s: %s\n" % (name, ' '.join(definition))) # Create voca file tmp_voca_file = os.path.join(tmpdir, os.extsep.join([prefix, 'voca'])) with open(tmp_voca_file, 'w') as f: for category, words in self._get_word_defs(lexicon, phrases).items(): f.write("%% %s\n" % category) for word, phoneme in words: f.write("%s\t\t\t%s\n" % (word, phoneme)) # mkdfa.pl olddir = os.getcwd() os.chdir(tmpdir) cmd = ['mkdfa.pl', str(prefix)] with tempfile.SpooledTemporaryFile() as out_f: subprocess.call(cmd, stdout=out_f, stderr=out_f) out_f.seek(0) for line in out_f.read().splitlines(): line = line.strip() if line: self._logger.debug(line) os.chdir(olddir) tmp_dfa_file = os.path.join(tmpdir, os.extsep.join([prefix, 'dfa'])) tmp_dict_file = os.path.join(tmpdir, os.extsep.join([prefix, 'dict'])) shutil.move(tmp_dfa_file, self.dfa_file) shutil.move(tmp_dict_file, self.dict_file) shutil.rmtree(tmpdir)
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') name_default = 'default' path_default = jasperpath.config('vocabularies') name_keyword = 'keyword' path_keyword = jasperpath.config('vocabularies') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'pocketsphinx' in profile: if 'hmm_dir' in profile['pocketsphinx']: config['hmm_dir'] = profile['pocketsphinx']['hmm_dir'] if 'vocabulary_default_name' in profile['pocketsphinx']: name_default = \ profile['pocketsphinx']['vocabulary_default_name'] if 'vocabulary_default_path' in profile['pocketsphinx']: path_default = \ profile['pocketsphinx']['vocabulary_default_path'] if 'vocabulary_keyword_name' in profile['pocketsphinx']: name_keyword = \ profile['pocketsphinx']['vocabulary_keyword_name'] if 'vocabulary_keyword_path' in profile['pocketsphinx']: path_keyword = \ profile['pocketsphinx']['vocabulary_keyword_path'] config['vocabulary'] = vocabcompiler.PocketsphinxVocabulary( name_default, path=path_default) config['vocabulary_keyword'] = vocabcompiler.PocketsphinxVocabulary( name_keyword, path=path_keyword) config['vocabulary'].compile(vocabcompiler.get_all_phrases()) config['vocabulary_keyword'].compile( vocabcompiler.get_keyword_phrases()) return config
def get_instance(cls, vocabulary_name, phrases): config = cls.get_config() if cls.VOCABULARY_TYPE: vocabulary = cls.VOCABULARY_TYPE(vocabulary_name, path=jasperpath.config("vocabularies")) if not vocabulary.matches_phrases(phrases): vocabulary.compile(phrases) config["vocabulary"] = vocabulary instance = cls(**config) return instance
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'keys' in profile and 'GOOGLE_SPEECH' in profile['keys']: config['api_key'] = profile['keys']['GOOGLE_SPEECH'] return config
def __init__(self, profile=None): self._switches = {} self._dial_stack = [] self._logger = logging.getLogger(__name__) self._last_dial_time = time.time() if profile is None: profile = jasperpath.config('phone.yml') self.load_profile(profile) self._monitor_thread = threading.Thread(target=self._monitor) self._monitor_thread.setDaemon(True) self._monitor_thread.setName('phone dial monitor') self._monitor_thread.start()
def get_config(cls): config = super(FliteTTS, cls).get_config() # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'flite-tts' in profile: if 'voice' in profile['flite-tts']: config['voice'] = profile['flite-tts']['voice'] return config
def get_config(cls): config = {} profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'watson-stt' in profile: if 'username' in profile['watson-stt']: config['app_username'] = profile['watson-stt']['username'] if 'password' in profile['watson-stt']: config['app_password'] = profile['watson-stt']['password'] return config
def get_config(cls): config = super(PicoTTS, cls).get_config() # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'pico-tts' in profile and 'language' in profile['pico-tts']: config['language'] = profile['pico-tts']['language'] return config
def getService(profile): print ("TESTTEST") client_id = '499382342201-i7r3moo57fv2e495vsgapcq62bka3cbq.apps.googleusercontent.com' client_secret = 'K8wrAMNHQNQv_PA_meGiUhnY' print ("TEST") # Create a flow object. This object holds the client_id, client_secret, and # scope. It assists with OAuth 2.0 steps to get user authorization and # credentials. flow = OAuth2WebServerFlow(client_id, client_secret, scope) # Create a Storage object. This object holds the credentials that your # application needs to authorize access to the user's data. The name of the # credentials file is provided. If the file does not exist, it is # created. This object can only hold credentials for a single user, so # as-written, this script can only handle a single user. print( jasperpath.config('calendar/credentials.dat') ) # storage = Storage(jasperpath.config('calendar/credentials.dat')) storage = Storage('credentials.dat') # The get() function returns the credentials for the Storage object. If no # credentials were found, None is returned. credentials = storage.get() # If no credentials are found or the credentials are invalid due to # expiration, new credentials need to be obtained from the authorization # server. The oauth2client.tools.run_flow() function attempts to open an # authorization server page in your default web browser. The server # asks the user to grant your application access to the user's data. # If the user grants access, the run_flow() function returns new credentials. # The new credentials are also stored in the supplied Storage object, # which updates the credentials.dat file. if credentials is None or credentials.invalid: parser = argparse.ArgumentParser(parents=[tools.argparser]) flags = parser.parse_args() credentials = tools.run_flow(flow, storage, flags) # Create an httplib2.Http object to handle our HTTP requests, and authorize it # using the credentials.authorize() function. http = httplib2.Http() http = credentials.authorize(http) # The apiclient.discovery.build() function returns an instance of an API service # object can be used to make API calls. The object is constructed with # methods specific to the calendar API. The arguments provided are: # name of the API ('calendar') # version of the API you are using ('v3') # authorized httplib2.Http() object that can be used for API calls return build('calendar', 'v3', http=http)
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config("profile.yml") if os.path.exists(profile_path): with open(profile_path, "r") as f: profile = yaml.safe_load(f) if "keys" in profile and "GOOGLE_SPEECH" in profile["keys"]: config["api_key"] = profile["keys"]["GOOGLE_SPEECH"] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # Try to get wit.ai Auth token from config profile_path = jasperpath.config("profile.yml") if os.path.exists(profile_path): with open(profile_path, "r") as f: profile = yaml.safe_load(f) if "witai-stt" in profile: if "access_token" in profile["witai-stt"]: config["access_token"] = profile["witai-stt"]["access_token"] return config
def get_config(cls): config = {} profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'xfyun' in profile: if 'app_id' in profile['xfyun']: config['app_id'] = profile['xfyun']['app_id'] if 'api_key' in profile['xfyun']: config['api_key'] = profile['xfyun']['api_key'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # Try to get wit.ai Auth token from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'witai-stt' in profile: if 'access_token' in profile['witai-stt']: config['access_token'] = \ profile['witai-stt']['access_token'] return config
def dictionary_file(self): """ Returns: The path of the pocketsphinx dictionary file as string """ profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'pocketsphinx' in profile: if 'dictionary' in profile['pocketsphinx']: return profile['pocketsphinx']['dictionary'] return os.path.join(self.path, 'dictionary')
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'pico-tts' in profile and 'language' in profile['pico-tts']: config['language'] = profile['pico-tts']['language'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config("profile.yml") if os.path.exists(profile_path): with open(profile_path, "r") as f: profile = yaml.safe_load(f) if "google-tts" in profile and "language" in profile["google-tts"]: config["language"] = profile["google-tts"]["language"] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'keys' in profile and 'PROJECT_OXFORD_PRIMARY' in profile['keys'] and 'PROJECT_OXFORD_SECONDARY' in \ profile['keys']: config['primary_key'] = profile['keys']['PROJECT_OXFORD_PRIMARY'] config['secondary_key'] = profile['keys']['PROJECT_OXFORD_SECONDARY'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # Try to get AT&T app_key/app_secret from config profile_path = jasperpath.config("profile.yml") if os.path.exists(profile_path): with open(profile_path, "r") as f: profile = yaml.safe_load(f) if "att-stt" in profile: if "app_key" in profile["att-stt"]: config["app_key"] = profile["att-stt"]["app_key"] if "app_secret" in profile["att-stt"]: config["app_secret"] = profile["att-stt"]["app_secret"] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # Try to get AT&T app_key/app_secret from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'att-stt' in profile: if 'app_key' in profile['att-stt']: config['app_key'] = profile['att-stt']['app_key'] if 'app_secret' in profile['att-stt']: config['app_secret'] = profile['att-stt']['app_secret'] return config
def get_config(cls): config = {} profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'watson-stt' in profile: if 'username' in profile['watson-stt']: config['app_username'] = profile['watson-stt'][ 'username'] if 'password' in profile['watson-stt']: config['app_password'] = profile['watson-stt'][ 'password'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'watson-stt' in profile: if 'user_name' in profile['watson-stt']: config['user_name'] = profile['watson-stt'][ 'user_name'] if 'password' in profile['watson-stt']: config['password'] = profile['watson-stt']['password'] return config
def get_instance(cls, vocabulary_name, phrases): print "AbstractSTTEngine with %s %s " % (vocabulary_name,phrases) config = cls.get_config() if cls.VOCABULARY_TYPE: vocabulary = cls.VOCABULARY_TYPE(vocabulary_name, path=jasperpath.config('vocabularies')) if not vocabulary.matches_phrases(phrases): vocabulary.compile(phrases) config['vocabulary'] = vocabulary instance = cls(**config) return instance
def get_instance(cls, vocabulary_name, phrases): print "AbstractSTTEngine with %s %s " % (vocabulary_name, phrases) config = cls.get_config() if cls.VOCABULARY_TYPE: vocabulary = cls.VOCABULARY_TYPE( vocabulary_name, path=jasperpath.config('vocabularies')) if not vocabulary.matches_phrases(phrases): vocabulary.compile(phrases) config['vocabulary'] = vocabulary instance = cls(**config) return instance
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'julius' in profile: if 'hmmdefs' in profile['julius']: config['hmmdefs'] = profile['julius']['hmmdefs'] if 'tiedlist' in profile['julius']: config['tiedlist'] = profile['julius']['tiedlist'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) try: config['hmm_dir'] = profile['pocketsphinx']['hmm_dir'] except KeyError: pass return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config("profile.yml") if os.path.exists(profile_path): with open(profile_path, "r") as f: profile = yaml.safe_load(f) if "julius" in profile: if "hmmdefs" in profile["julius"]: config["hmmdefs"] = profile["julius"]["hmmdefs"] if "tiedlist" in profile["julius"]: config["tiedlist"] = profile["julius"]["tiedlist"] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # Try to get baidu_yuyin config from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'baidu_yuyin' in profile: if 'api_key' in profile['baidu_yuyin']: config['api_key'] = \ profile['baidu_yuyin']['api_key'] if 'secret_key' in profile['baidu_yuyin']: config['secret_key'] = \ profile['baidu_yuyin']['secret_key'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config("profile.yml") if os.path.exists(profile_path): with open(profile_path, "r") as f: profile = yaml.safe_load(f) if "espeak-tts" in profile: if "voice" in profile["espeak-tts"]: config["voice"] = profile["espeak-tts"]["voice"] if "pitch_adjustment" in profile["espeak-tts"]: config["pitch_adjustment"] = profile["espeak-tts"]["pitch_adjustment"] if "words_per_minute" in profile["espeak-tts"]: config["words_per_minute"] = profile["espeak-tts"]["words_per_minute"] return config
def __init__(self, speaker, passive_stt_engine, active_stt_engine, echo=False): """ Initiates the pocketsphinx instance. Arguments: speaker -- handles platform-independent audio output passive_stt_engine -- performs STT while Jasper is in passive listen mode acive_stt_engine -- performs STT while Jasper is in active listen mode """ self._logger = logging.getLogger(__name__) self.setSpeaker(speaker) self.passive_stt_engine = passive_stt_engine self.active_stt_engine = active_stt_engine self.phone = phone.get_phone() self._logger.info("Initializing PyAudio. ALSA/Jack error messages " + "that pop up during this process are normal and " + "can usually be safely ignored.") self._audio = pyaudio.PyAudio() self._logger.info("Initialization of PyAudio completed.") self._echo = echo # whether to play back what it heard self._audio_dev = None profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'audio_dev' in profile and 'speaker' in profile['audio_dev']: self._audio_dev = profile['audio_dev']['mic'] if self._audio_dev is None: self._audio_dev = 0 self.keep_files = False self.last_file_recorded = None self.RATE = 44100 self.CHUNK = 32 self.TARGET_RATE = 16000 self.THRESHOLD_MULTIPLIER = 1.8 self.dial_timeout = 2.5 self._dial_stack = [] self.start_background_threshold_thread()
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'bing-stt' in profile: if 'key' in profile['bing-stt']: config['key'] = profile['bing-stt']['key'] if 'language' in profile['bing-stt']: config['language'] = profile['bing-stt']['language'] if 'show_all' in profile['bing-stt']: config['show_all'] = profile['bing-stt']['show_all'] return config
def get_config(cls): # FIXME: Replace this as soon as pull request # jasperproject/jasper-client#128 has been merged conf = {'fst_model': os.path.join(jasperpath.APP_PATH, os.pardir, 'phonetisaurus', 'g014b2b.fst')} # Try to get fst_model from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'pocketsphinx' in profile: if 'fst_model' in profile['pocketsphinx']: conf['fst_model'] = \ profile['pocketsphinx']['fst_model'] if 'nbest' in profile['pocketsphinx']: conf['nbest'] = int(profile['pocketsphinx']['nbest']) return conf
def get_config(cls): config = super(MaryTTS, cls).get_config() # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'mary-tts' in profile: if 'server' in profile['mary-tts']: config['server'] = profile['mary-tts']['server'] if 'port' in profile['mary-tts']: config['port'] = profile['mary-tts']['port'] if 'language' in profile['mary-tts']: config['language'] = profile['mary-tts']['language'] if 'voice' in profile['mary-tts']: config['voice'] = profile['mary-tts']['voice'] return config
def get_config(cls): config = super(EspeakTTS, cls).get_config() # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'espeak-tts' in profile: if 'voice' in profile['espeak-tts']: config['voice'] = profile['espeak-tts']['voice'] if 'pitch_adjustment' in profile['espeak-tts']: config['pitch_adjustment'] = \ profile['espeak-tts']['pitch_adjustment'] if 'words_per_minute' in profile['espeak-tts']: config['words_per_minute'] = \ profile['espeak-tts']['words_per_minute'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'espeak-tts' in profile: if 'voice' in profile['espeak-tts']: config['voice'] = profile['espeak-tts']['voice'] if 'pitch_adjustment' in profile['espeak-tts']: config['pitch_adjustment'] = \ profile['espeak-tts']['pitch_adjustment'] if 'words_per_minute' in profile['espeak-tts']: config['words_per_minute'] = \ profile['espeak-tts']['words_per_minute'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'cognitive_service' in profile: if 'api_key' in profile['cognitive_service']: config['api_key'] = profile['cognitive_service'][ 'api_key'] if 'language' in profile['cognitive_service']: config['language'] = profile['cognitive_service'][ 'language'] if 'locale' in profile['cognitive_service']: config['locale'] = profile['cognitive_service'][ 'locale'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if profile['tts_engine'] == 'cereproc-tts' and \ profile['att-tts']['personnality'] and \ profile['att-tts']['accountid'] and \ profile['att-tts']['password']: config['personnality'] = profile['att-tts']['personnality'] config['accountid'] = profile['att-tts']['accountid'] config['password'] = profile['att-tts']['password'] return config
def get_config(cls, language): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config('profile.%s.yml' % language) if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'mary-tts' in profile: if 'server' in profile['mary-tts']: config['server'] = profile['mary-tts']['server'] if 'port' in profile['mary-tts']: config['port'] = profile['mary-tts']['port'] if 'language' in profile['mary-tts']: config['language'] = profile['mary-tts']['language'] if 'voice' in profile['mary-tts']: config['voice'] = profile['mary-tts']['voice'] return config
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # Try to get snowboy config from config profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'snowboy' in profile: if 'model' in profile['snowboy']: config['model'] = \ profile['snowboy']['model'] if 'sensitivity' in profile['snowboy']: config['sensitivity'] = \ profile['snowboy']['sensitivity'] else: config['sensitivity'] = "0.5" if 'robot_name' in profile: config['hotword'] = profile['robot_name'] return config
def __init__(self, PERSONA, mic, mpdwrapper): self._logger = logging.getLogger(__name__) self.persona = PERSONA # self.mic - we're actually going to ignore the mic they passed in self.music = mpdwrapper # index spotify playlists into new dictionary and language models phrases = ["STOP", "CLOSE", "PLAY", "PAUSE", "NEXT", "PREVIOUS", "LOUDER", "SOFTER", "LOWER", "HIGHER", "VOLUME", "PLAYLIST"] phrases.extend(self.music.get_soup_playlist()) vocabulary_music = vocabcompiler.PocketsphinxVocabulary( name='music', path=jasperpath.config('vocabularies')) vocabulary_music.compile(phrases) # create a new mic with the new music models config = stt.PocketSphinxSTT.get_config() self.mic = Mic(mic.speaker, mic.passive_stt_engine, stt.PocketSphinxSTT(vocabulary_music=vocabulary_music, **config))
def __init__(self, PERSONA, mic, mpdwrapper): self._logger = logging.getLogger(__name__) self.persona = PERSONA # self.mic - we're actually going to ignore the mic they passed in self.music = mpdwrapper # index spotify playlists into new dictionary and language models phrases = [ "STOP", "CLOSE", "PLAY", "PAUSE", "NEXT", "PREVIOUS", "LOUDER", "SOFTER", "LOWER", "HIGHER", "VOLUME", "PLAYLIST" ] phrases.extend(self.music.get_soup_playlist()) vocabulary_music = vocabcompiler.PocketsphinxVocabulary( name='music', path=jasperpath.config('vocabularies')) vocabulary_music.compile(phrases) # create a new mic with the new music models config = stt.PocketSphinxSTT.get_config() self.mic = Mic( mic.speaker, mic.passive_stt_engine, stt.PocketSphinxSTT(vocabulary_music=vocabulary_music, **config))
def get_config(cls): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = jasperpath.config("profile.yml") if os.path.exists(profile_path): with open(profile_path, "r") as f: profile = yaml.safe_load(f) if "ivona-tts" in profile: if "access_key" in profile["ivona-tts"]: config["access_key"] = profile["ivona-tts"]["access_key"] if "secret_key" in profile["ivona-tts"]: config["secret_key"] = profile["ivona-tts"]["secret_key"] if "region" in profile["ivona-tts"]: config["region"] = profile["ivona-tts"]["region"] if "voice" in profile["ivona-tts"]: config["voice"] = profile["ivona-tts"]["voice"] if "speech_rate" in profile["ivona-tts"]: config["speech_rate"] = profile["ivona-tts"]["speech_rate"] if "sentence_break" in profile["ivona-tts"]: config["sentence_break"] = profile["ivona-tts"]["sentence_break"] return config
def __init__(self, speaker, passive_stt_engine, active_stt_engine): """ Initiates the pocketsphinx instance. Arguments: speaker -- handles platform-independent audio output passive_stt_engine -- performs STT while Jasper is in passive listen mode acive_stt_engine -- performs STT while Jasper is in active listen mode """ self._logger = logging.getLogger(__name__) self.speaker = speaker self.passive_stt_engine = passive_stt_engine self.active_stt_engine = active_stt_engine self._logger.warning("about to connect to pyaudio") self._audio = pyaudio.PyAudio() self.client = crossbarconnect.Client("http://127.0.0.1:8080/publish") self._logger.warning("websocket connected") profile_path = jasperpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'witai-stt' in profile: if 'access_token' in profile['witai-stt']: self.token = profile['witai-stt']['access_token']
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.", jasperpath.CONFIG_PATH) # 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: stt_engine_slug = self.config['stt_engine'] except KeyError: stt_engine_slug = 'sphinx' logger.warning( "stt_engine not specified in profile, defaulting " + "to '%s'", stt_engine_slug) stt_engine_class = stt.get_engine_by_slug(stt_engine_slug) try: slug = self.config['stt_passive_engine'] stt_passive_engine_class = stt.get_engine_by_slug(slug) except KeyError: stt_passive_engine_class = stt_engine_class 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) # Initialize Mic self.mic = Mic(tts_engine_class.get_instance(), stt_passive_engine_class.get_passive_instance(), stt_engine_class.get_active_instance())
import logging import yaml import jasperpath logger = logging.getLogger(__name__) new_configfile = jasperpath.config('profile.yml') try: with open(new_configfile, "r") as f: profile = yaml.safe_load(f) except OSError: logger.error("Can't open config file: '%s'", new_configfile) raise
def run(): profile = {} print("Welcome to the profile populator. If, at any step, you'd prefer " + "not to enter the requested information, just hit 'Enter' with a " + "blank field to continue.") def simple_request(var, cleanVar, cleanInput=None): input = raw_input(cleanVar + ": ") if input: if cleanInput: input = cleanInput(input) profile[var] = input # name simple_request('first_name', 'First name') simple_request('last_name', 'Last name') # gmail print("\nJasper uses your Gmail to send notifications. Alternatively, " + "you can skip this step (or just fill in the email address if you " + "want to receive email notifications) and setup a Mailgun " + "account, as at http://jasperproject.github.io/documentation/" + "software/#mailgun.\n") simple_request('gmail_address', 'Gmail address') profile['gmail_password'] = getpass() # phone number clean_number = lambda s: re.sub(r'[^0-9]', '', s) phone_number = clean_number(raw_input("\nPhone number (no country " + "code). Any dashes or spaces will " + "be removed for you: ")) profile['phone_number'] = phone_number # carrier print("\nPhone carrier (for sending text notifications).") print("If you have a US phone number, you can enter one of the " + "following: 'AT&T', 'Verizon', 'T-Mobile' (without the quotes). " + "If your carrier isn't listed or you have an international " + "number, go to http://www.emailtextmessages.com and enter the " + "email suffix for your carrier (e.g., for Virgin Mobile, enter " + "'vmobl.com'; for T-Mobile Germany, enter 't-d1-sms.de').") carrier = raw_input('Carrier: ') if carrier == 'AT&T': profile['carrier'] = 'txt.att.net' elif carrier == 'Verizon': profile['carrier'] = 'vtext.com' elif carrier == 'T-Mobile': profile['carrier'] = 'tmomail.net' else: profile['carrier'] = carrier # location def verifyLocation(place): feed = feedparser.parse('http://rss.wunderground.com/auto/rss_full/' + place) numEntries = len(feed['entries']) if numEntries == 0: return False else: print("Location saved as " + feed['feed']['description'][33:]) return True print("\nLocation should be a 5-digit US zipcode (e.g., 08544). If you " + "are outside the US, insert the name of your nearest big " + "town/city. For weather requests.") location = raw_input("Location: ") while location and not verifyLocation(location): print("Weather not found. Please try another location.") location = raw_input("Location: ") if location: profile['location'] = location # timezone print("\nPlease enter a timezone from the list located in the TZ* " + "column at http://en.wikipedia.org/wiki/" + "List_of_tz_database_time_zones, or none at all.") tz = raw_input("Timezone: ") while tz: try: timezone(tz) profile['timezone'] = tz break except: print("Not a valid timezone. Try again.") tz = raw_input("Timezone: ") response = raw_input("\nWould you prefer to have notifications sent by " + "email (E) or text message (T)? ") while not response or (response != 'E' and response != 'T'): response = raw_input("Please choose email (E) or text message (T): ") profile['prefers_email'] = (response == 'E') stt_engines = { "sphinx": None, "google": "GOOGLE_SPEECH" } response = raw_input("\nIf you would like to choose a specific STT " + "engine, please specify which.\nAvailable " + "implementations: %s. (Press Enter to default " + "to PocketSphinx): " % stt_engines.keys()) if (response in stt_engines): profile["stt_engine"] = response api_key_name = stt_engines[response] if api_key_name: key = raw_input("\nPlease enter your API key: ") profile["keys"] = {api_key_name: key} else: print("Unrecognized STT engine. Available implementations: %s" % stt_engines.keys()) profile["stt_engine"] = "sphinx" # write to profile print("Writing to profile...") if not os.path.exists(jasperpath.CONFIG_PATH): os.makedirs(jasperpath.CONFIG_PATH) outputFile = open(jasperpath.config("profile.yml"), "w") yaml.dump(profile, outputFile, default_flow_style=False) print("Done.")
def run(): profile = {} print("Welcome to the profile populator. If, at any step, you'd prefer " + "not to enter the requested information, just hit 'Enter' with a " + "blank field to continue.") def simple_request(var, cleanVar, cleanInput=None): input = raw_input(cleanVar + ": ") if input: if cleanInput: input = cleanInput(input) profile[var] = input # name simple_request('first_name', 'First name') simple_request('last_name', 'Last name') simple_request('keyword', 'Key Word Command: [RETURN] for JASPER') # gmail print("\nJasper uses your Gmail to send notifications. Alternatively, " + "you can skip this step (or just fill in the email address if you " + "want to receive email notifications) and setup a Mailgun " + "account, as at http://jasperproject.github.io/documentation/" + "software/#mailgun.\n") simple_request('gmail_address', 'Gmail address') profile['gmail_password'] = getpass() # phone number def clean_number(s): return re.sub(r'[^0-9]', '', s) phone_number = clean_number( raw_input("\nPhone number (no country " + "code). Any dashes or spaces will " + "be removed for you: ")) profile['phone_number'] = phone_number # carrier print("\nPhone carrier (for sending text notifications).") print("If you have a US phone number, you can enter one of the " + "following: 'AT&T', 'Verizon', 'T-Mobile' (without the quotes). " + "If your carrier isn't listed or you have an international " + "number, go to http://www.emailtextmessages.com and enter the " + "email suffix for your carrier (e.g., for Virgin Mobile, enter " + "'vmobl.com'; for T-Mobile Germany, enter 't-d1-sms.de').") carrier = raw_input('Carrier: ') if carrier == 'AT&T': profile['carrier'] = 'txt.att.net' elif carrier == 'Verizon': profile['carrier'] = 'vtext.com' elif carrier == 'T-Mobile': profile['carrier'] = 'tmomail.net' else: profile['carrier'] = carrier # location def verifyLocation(place): feed = feedparser.parse('http://rss.wunderground.com/auto/rss_full/' + place) numEntries = len(feed['entries']) if numEntries == 0: return False else: print("Location saved as " + feed['feed']['description'][33:]) return True print("\nLocation should be a 5-digit US zipcode (e.g., 08544). If you " + "are outside the US, insert the name of your nearest big " + "town/city. For weather requests.") location = raw_input("Location: ") while location and not verifyLocation(location): print("Weather not found. Please try another location.") location = raw_input("Location: ") if location: profile['location'] = location # timezone print("\nPlease enter a timezone from the list located in the TZ* " + "column at http://en.wikipedia.org/wiki/" + "List_of_tz_database_time_zones, or none at all.") tz = raw_input("Timezone: ") while tz: try: timezone(tz) profile['timezone'] = tz break except: print("Not a valid timezone. Try again.") tz = raw_input("Timezone: ") response = raw_input("\nWould you prefer to have notifications sent by " + "email (E) or text message (T)? ") while not response or (response != 'E' and response != 'T'): response = raw_input("Please choose email (E) or text message (T): ") profile['prefers_email'] = (response == 'E') stt_engines = {"sphinx": None, "google": "GOOGLE_SPEECH"} response = raw_input("\nIf you would like to choose a specific STT " + "engine, please specify which.\nAvailable " + "implementations: %s. (Press Enter to default " + "to PocketSphinx): " % stt_engines.keys()) if (response in stt_engines): profile["stt_engine"] = response api_key_name = stt_engines[response] if api_key_name: key = raw_input("\nPlease enter your API key: ") profile["keys"] = {api_key_name: key} else: print("Unrecognized STT engine. Available implementations: %s" % stt_engines.keys()) profile["stt_engine"] = "sphinx" if response == "google": response = raw_input("\nChoosing Google means every sound " + "makes a request online. " + "\nWould you like to process the wake up word " + "locally with PocketSphinx? (Y) or (N)?") while not response or (response != 'Y' and response != 'N'): response = raw_input("Please choose PocketSphinx (Y) " + "or keep just Google (N): ") if response == 'Y': profile['stt_passive_engine'] = "sphinx" # write to profile print("Writing to profile...") if not os.path.exists(jasperpath.CONFIG_PATH): os.makedirs(jasperpath.CONFIG_PATH) outputFile = open(jasperpath.config("profile.yml"), "w") yaml.dump(profile, outputFile, default_flow_style=False) print("Done.")