def message(update, context): message_received = update.message.text assistant.validate_session(update.effective_chat.id) response_text = assistant.send_message(SessionManager.getInstance().getSession(update.effective_chat.id), update.message.text) context.bot.send_message(chat_id=update.effective_chat.id, text=response_text)
def receive_voice(update, context): assistant.validate_session(update.effective_chat.id) audio_file = BytesIO(update.message.voice.get_file().download_as_bytearray()) text = voice.convert_voice(audio_file) response_text = assistant.send_message(SessionManager.getInstance().getSession(update.effective_chat.id), text) context.bot.send_voice(chat_id=update.effective_chat.id, voice=voice.convert_text(response_text))
def speak(self): recorder.record_to_file("input.wav") print("recording finished: input.wav") self.user_text = speechtotext.listen("input.wav") print("speech to text: " + self.user_text) response = assistant.send_message(self.user_text) self.assistant_text = str(response[0]) print("assistant responded: " + self.assistant_text) self.respond()
def send(self): print(self.user_text) response = assistant.send_message(self.user_text) self.assistant_text = str(response[0]) self.respond()
def start(update, context): assistant.validate_session(update.effective_chat.id) response_text = assistant.send_message(SessionManager.getInstance().getSession(update.effective_chat.id), '') context.bot.send_message(chat_id=update.effective_chat.id, text=response_text)