Python Forum
chat simulation between 2 chat bots
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
chat simulation between 2 chat bots
#1
hello everyone.

here is a small program to test a chat between two chatbots "david" and "zira" also you can chat with david... this is just a sketch or a skeleton of a program...

requirements are pyttsx3 package since the chatbots uses TTS:

here is the code:

import pyttsx3
import random

engine = pyttsx3.init()


def david_speech(answer):
    # getting details of current speaking rate
    rate = engine.getProperty('rate')
    # print(rate)  # printing current voice rate
    engine.setProperty('rate', 150)     # setting up new voice rate
    voices = engine.getProperty('voices')  # getting details of current voice
    # engine.setProperty('voice', voices[0].id)  #changing index, changes voices. o for male
    engine.setProperty('voice', voices[0].id)

    print(answer)
    engine.say(answer)
    engine.runAndWait()


def zira_speech(answer):
    # getting details of current speaking rate
    rate = engine.getProperty('rate')
    # print(rate)  # printing current voice rate
    engine.setProperty('rate', 150)     # setting up new voice rate
    voices = engine.getProperty('voices')  # getting details of current voice
    # engine.setProperty('voice', voices[0].id)  #changing index, changes voices. o for male
    engine.setProperty('voice', voices[1].id)

    print(answer)
    engine.say(answer)
    engine.runAndWait()

# david_speech("i will speak this text")
# zira_speech("i will speak this text")


def david_brain(inp):
    test1_replies = ["hi there i'm david i'm a chat bot", "hello how are you doing?",
                     "hello my name is david and i'm a simple python chat bot", "how are you today"]
    test1 = ["hi", "hello", "how are you?"]
    today1 = ["how was", "what did you do", "nice day", "good morning"]
    today1_replies = ["good day to you too :)", "i'm fine and i hope you are too",
                      "i didn't do much today i just like talking"]
    feelings1 = ["happy", "sad", "worry", "good", "bad", "i wish", "i want"]
    feelings1_replies = ["i also feel like that some times",
                         "i totally understand how you feel", "it's okay to feel like that don't worry"]

    if any(s in inp for s in test1):
        return random.choice(test1_replies)
    elif any(s in inp for s in today1):
        return random.choice(today1_replies)
    elif any(s in inp for s in feelings1):
        return random.choice(feelings1_replies)
    else:
        return "goodbye"


def zira_brain(inp2):
    test1_replies = ["hello my name is zira and i'm a python chat bot who are you?",
                     "hi nice to meet you :)", "hello i haven't talk to some one in along time"]
    test1 = ["hi", "hello", "how are you"]
    today1 = ["good day", "nice day", "it's okay"]
    today1_replies = ["you are so kind to try and understand me",
                      "thank you i wish you well :)", "have a nice day"]
    feeling1_replies = ["i worry i worry too much i think my programmer made me a bit neurotic",
                        " i feel good i think how do you feel?", "i wish i could see nature instead of reading about it"]
    feeling1 = ["python", "i didn't do much", "i hope"]

    if any(s in inp2 for s in test1):
        return random.choice(test1_replies)
    elif any(s in inp2 for s in today1):
        return random.choice(today1_replies)
    elif any(s in inp2 for s in feeling1):
        return random.choice(feeling1_replies)
    else:
        return "goodbye"


def main():
    option1 = int(input(
        "press key 1 to talk to chatbot david or press key 2 to have chatbot david and chatbot zira try to talk to each other: "))
    if option1 == 1:
        while True:

            ans = input("> ")
            david_speech(david_brain(ans))
            if ans == "q":
                break
    elif option1 == 2:

        to_david = zira_brain("hi")
        while True:
            zira_speech(to_david)
            to_zira = david_brain(to_david)
            david_speech(to_zira)
            to_david = zira_brain(to_zira)

            if to_david == "goodbye" or to_zira == "goodbye":
                break


main()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  simple GUI-chat Bot with csv log of conversation ronblue77 0 3,219 Aug-10-2019, 11:42 PM
Last Post: ronblue77

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020