def __init__(self, profile, hmm=None, dict=None, lm=None, kws_threshold=None, keyphrase=None): self.profile = profile if keyphrase: if not dict: dict = fullpath('config/keyphrase.dic') if not lm: lm = fullpath('config/keyphrase.lm') else: if not dict: dict = fullpath('config/corpus.dic') if not lm: lm = fullpath('config/corpus.lm') if not hmm: hmm = 'share/pocketsphinx/model/en-us/en-us' config = Decoder.default_config() config.set_string('-hmm', os.path.join(SPHINX_ROOT, hmm)) config.set_string('-dict', dict) config.set_string('-lm', lm) config.set_string('-logfn', fullpath('config/sphinx.log')) if keyphrase: config.set_string('-keyphrase', keyphrase) if kws_threshold: config.set_float('-kws_threshold', kws_threshold) self.decoder = Decoder(config) self.transcribe = self.transcribe_darwin self.hyp = None
def main( profile_path=None, old_profile_path=None, phrases_path=None, lm_path=None, dic_path=None ): if not profile_path: profile_path = fullpath('config/profile.json') if not old_profile_path: old_profile_path = profile_path if not lm_path: lm_path = fullpath('config/corpus.lm') if not dic_path: dic_path = fullpath('config/corpus.dic') print "Welcome to the profile populator!" try: with open(old_profile_path) as fp: old_profile = json.load(fp) print "I found a profile at %s." % old_profile_path except: old_profile = None profile = populate_IRIS.init(old_profile) print profile_path with open(profile_path, 'w') as fp: json.dump(profile, fp) print "Your profile is now ready. We need to build the langauge model now" compile_lm.main( phrases_path=phrases_path, lm=lm_path, dic=dic_path, verbose=True )
def say(self, phrase): cmd = ["pico2wave", "--wave", fullpath('libs/tts/response.wav')] cmd += ['-l', self.language] cmd.append(phrase) proc = subprocess.Popen(cmd) proc.wait() audio.play(fullpath('libs/tts/response.wav'))
def activeListen(self, use_local=None): self.stop_itunes() if use_local is None: use_local = self.use_local audio.play(fullpath('static/beep_hi.wav')) if self.prompt: self.userinput = raw_input("YOU: ") else: self.wav, energies = audio.record( verbose=True, threshold=self.threshold, emptyFrames=20 ) with open('test.wav', 'wb') as fp: fp.write(self.wav) if sum(energies) / len(energies) < self.threshold: self.undo_itunes() return "" try: if use_local: self.userinput = self.localSTT.transcribe(self.wav) else: self.userinput = self.cloudSTT.transcribe(self.wav) except: print "Something went wrong" return '' print "YOU:", self.userinput audio.play(fullpath('static/beep_lo.wav')) self.undo_itunes() return self.userinput
def get_modules(attr="SENTENCES", folder='modules', cleanUp=True): if cleanUp: clean_up_all() locations = [fullpath(folder)] modules = [] global all_modules for finder, name, ispkg in pkgutil.walk_packages(locations): try: loader = finder.find_module(name) mod = loader.load_module(name) all_modules.append(mod) except: print "Skipped module '%s' due to an error." % name else: if hasattr(mod, attr): print "Found module '%s'" % name modules.append(mod) else: print "Skipped module '%s' because it misses the constant." \ % name modules.sort( key=lambda mod: mod.PRIORITY if hasattr(mod, 'PRIORITY') else 0, reverse=True ) return modules
def get_apiKeys(old_profile): # We need to find all invocations of profile['keys'] all_keys = [] for dirName, subdirList, fileList in os.walk(fullpath("")): for fname in fileList: filename, file_extension = os.path.splitext(fname) if file_extension == ".py": path = os.path.join(dirName, fname) lparenthesis = "\[['\"]" # matches [' and [" rparenthesis = "['\"]\]" # matches '] and "] with open(path) as fp: all_keys += re.findall( "profile" + lparenthesis + "keys" + rparenthesis + lparenthesis + "(.+)" + rparenthesis, fp.read() ) profile = {} print "I have compiled a list of all API keys you will need to enter." for key in all_keys: if key in old_profile: default = old_profile[key] else: default = "" profile[key] = user_input( "Please enter the API key for " + key, default=default ) return profile
def iCloud(profile): global icloud_api if not icloud_api: appleid = profile['apple']['cred']['id'] password = base64.b64decode(profile['apple']['cred']['password']) icloud_api = PyiCloudService( appleid, password, cookie_directory=fullpath('config/') ) return icloud_api
def say(self, phrase): tts = gtts.gTTS(text=phrase, lang=self.language) tts.save(fullpath("libs/tts/response.mp3")) audio.play(fullpath("libs/tts/response.mp3"))
def ring(self): audio.play(fullpath('static/alarm.wav'))
def dummy(prompt=True): with open(fullpath('config/profile.json')) as fp: profile = json.load(fp) mmic = mic.Mic(profile, prompt=prompt) return mmic, profile
def dummy(prompt=True): with open(fullpath('config/profile.json')) as fp: profile = json.load(fp) mmic = mic.Mic(profile, prompt=prompt) return mmic, profile if __name__ == '__main__': import sys stdin = False if len(sys.argv) == 2: if sys.argv[1] == '-stdin': stdin = True with_notifications = False b = brain(fullpath('config/profile.json'), stdin=stdin) if not stdin and with_notifications: notifier = notifier_class(b) notifier.start() try: while True: b.run() finally: clean_up_all() if not stdin and with_notifications: notifier.just_die() notifier.join()