class Assistant(object): def __init__(self, use_speech): self.tts = TTS() self.use_speech = use_speech if self.use_speech: self.stt = STT() self.chatbot = ChatBot( 'JARVIS', storage_adapter='chatterbot.storage.JsonFileStorageAdapter', filters=['chatterbot.filters.RepetitiveResponseFilter'], logic_adapters=[{ 'import_path': 'chatterbot.logic.BestMatch' }]) self.chatbot.set_trainer(ChatterBotCorpusTrainer) self.chatbot.train("chatterbot.corpus.english.greetings") def search_wolfram(self, input): try: search_result = wolfram_client.query(input) self.say(next(search_result.results).text) return True except: return False def say(self, message): self.tts.say(message) def respond(self, message): self.say(self.chatbot.get_response(message)) def get_input(self): if (self.use_speech): input = self.stt.listen() print 'User: {}'.format(input) else: input = raw_input('User: ') return input
class Text(object): def __init__(self): self.stt_engine = STT() self.tts_engine = TTS() self.mic = Mic(self.tts_engine, self.stt_engine, self.stt_engine) self.selection = Selection(self.tts_engine) def handle(self): while True: threshold, translate = self.mic.passiveListen("JARVIS") if not translate or not threshold: continue input = self.mic.activeListen(threshold) print input if input: string = self.selection.select(input) else: self.tts_engine.say("Pardon?")
from tts import TTS from recipe_parser import RecipeParser if __name__ == '__main__': tts = TTS() rp = RecipeParser('icecreamcone.json') text = raw_input('Say:') while text: if text == 'ingredients': ingredients = rp.get_ingredients() for ingredient in ingredients: tts.say(ingredient) elif text == 'instructions': instructions = rp.get_instruction() for instruction in instructions: tts.say(instruction[0:100]) elif rp.find_ingredient(text): ingredient = rp.find_ingredient(text)[0] tts.say(ingredient['amount'] + ' ' + ingredient['ingredient']) text = raw_input('Say:')