From 2ae60b474169e14358344693edbaaebeb44a2db8 Mon Sep 17 00:00:00 2001 From: kushalkd14 Date: Sun, 3 Sep 2023 15:13:20 +0530 Subject: [PATCH] added feature --- examples/mimic-bot-adv/main.py | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 examples/mimic-bot-adv/main.py diff --git a/examples/mimic-bot-adv/main.py b/examples/mimic-bot-adv/main.py new file mode 100644 index 00000000..af507436 --- /dev/null +++ b/examples/mimic-bot-adv/main.py @@ -0,0 +1,48 @@ +from textbase import bot, Message +from typing import List +import pyttsx3 + + + + +def speak(text): + engine = pyttsx3.init('sapi5') + + try: + pass + engine.say(text) + engine.startLoop(True) + + except: + pass + engine.stop() + + + + + + +@bot() +def on_message(message_history: List[Message], state: dict = None): + + # Mimic user's response + bot_response = [] + bot_response = message_history[-1]["content"] + mylist=[]+message_history[-1]["content"] + response = { + "data": { + "messages": bot_response, + "state": state, + "speak": speak(mylist[0]["value"]) + }, + "errors": [ + { + "message": "" + } + ] + } + + return { + "status_code": 200, + "response": response + } \ No newline at end of file