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 = athenapath.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 = 'athena' tmpdir = tempfile.mkdtemp() lexicon_file = athenapath.data('julius-stt', 'VoxForge.tgz') lexicon_archive_member = 'VoxForge/VoxForgeDict' profile_path = athenapath.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_instance(cls, vocabulary_name, phrases): config = cls.get_config() if cls.VOCABULARY_TYPE: vocabulary = cls.VOCABULARY_TYPE( vocabulary_name, path=athenapath.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 = athenapath.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 = athenapath.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): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = athenapath.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 = {} # Try to get AT&T app_key/app_secret from config profile_path = athenapath.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 = {} # HMM dir # Try to get hmm_dir from config profile_path = athenapath.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 = athenapath.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 = athenapath.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 pull request # athenaproject/athena-client#128 has been merged conf = { 'fst_model': os.path.join(athenapath.APP_PATH, os.pardir, 'phonetisaurus', 'g014b2b.fst') } # Try to get fst_model from config profile_path = athenapath.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 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("\nathena 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://athenaproject.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(athenapath.CONFIG_PATH): os.makedirs(athenapath.CONFIG_PATH) outputFile = open(athenapath.config("profile.yml"), "w") yaml.dump(profile, outputFile, default_flow_style=False) print("Done.")