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 = dingdangpath.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'] else: config['model'] = os.path.join( dingdangpath.LIB_PATH, 'snowboy/dingdang.pmdl') 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'] else: config['hotword'] = 'DINGDANG' return config
def _compile_vocabulary(self, phrases): prefix = 'dingdang' tmpdir = tempfile.mkdtemp() lexicon_file = dingdangpath.data('julius-stt', 'VoxForge.tgz') lexicon_archive_member = 'VoxForge/VoxForgeDict' profile_path = dingdangpath.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=dingdangpath.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 = dingdangpath.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 iflytek_yuyin config from config profile_path = dingdangpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'iflytek_yuyin' in profile: if 'vid' in profile['iflytek_yuyin']: config['vid'] = \ profile['iflytek_yuyin']['vid'] 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 = dingdangpath.config('profile.yml') if os.path.exists(profile_path): with open(profile_path, 'r') as f: profile = yaml.safe_load(f) if 'google_yuyin' in profile \ and 'api_key' in profile['google_yuyin']: config['api_key'] = profile['google_yuyin']['api_key'] return config
def get_config(cls): conf = {'fst_model': os.path.join(dingdangpath.APP_PATH, os.pardir, 'phonetisaurus', 'g014b2b.fst')} # Try to get fst_model from config profile_path = dingdangpath.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): # FIXME: Replace this as soon as we have a config module config = {} # HMM dir # Try to get hmm_dir from config profile_path = dingdangpath.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 = {} # Try to get baidu_yuyin config from config profile_path = dingdangpath.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'] if 'per' in profile['baidu_yuyin']: config['per'] = \ profile['baidu_yuyin']['per'] 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 = dingdangpath.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