📜  python chatbot api - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:06.436000             🧑  作者: Mango

代码示例2
import webbrowser
# import os
import datetime
import pyttsx3
#***moduel section***#

time = datetime.datetime.now()

#***variable section***#

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')

engine.setProperty('voice', voices[0].id)


def speak(audio):
    engine.say(audio)
    engine.runAndWait()



print("Welcome to A.I assistant\n")
speak("Welcome to AI assistant")
print("I am A.I Sir. Please tell me how may I help you\n")
speak("I am AI Sir. Please tell me how may I help you")

#***print section***#




user = input("")
if user=='hi':
    print("hello\n")
    speak("hello")
    user = input("How may i help you!\n")

    while True:
 
      if (user=="what is your name"):
        print("My name is A.I assistant\n")
        speak("My name is AI assistant")

        
        user = input("How may i help you!\n")
      elif user=="open youtube":
            print("opening youtube...\n")
            speak("opening youtube")
            print("youtube opened\n")
            webbrowser.open("youtube.com")
            speak("youtube opened")



            user = input("How may i help you!\n")
      elif user=="open google":
            print("opening google...\n")
            speak("opening google")
            print("google opened\n")
            webbrowser.open("google.com")
            speak("google opened")



            user = input("How may i help you!\n")
      elif user=="what is the time":
                print("The time is: ")
                speak("The time is: ")
                print(time.strftime("%H:%M:%S\n"))   
                speak(time.strftime("%H:%M:%S\n"))


                
                user = input("How may i help you!\n")
      elif user=="AI is dangerous":
                    print("yes,AI could end mankind\n")
                    speak("yes,AI could end mankind")
                    


    



                    user = input("How may i help you!\n")
      elif user=="what is my birth date":
                    print("your birth date is: 15 december 2008 \n")
                    speak("your birthdate is: 15 december 2008")



                    user = input("How may i help you!\n")
      elif user=="bye":
                        print("Ok bye,have a nice day!\n")
                        speak("Ok bye,have a nice day!")

                        # while user =="bye":
                        #     (quit)



                    #***user input section***#