Advertisement
Kxffie

Custom ChatGPT "Jarvis" Assistant New

Dec 12th, 2022
1,426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.65 KB | Source Code | 0 0
  1. # ChatGPT Assistant with voice assistance and text.
  2. # kxffie.itch.io/chatgpt-jarvis-assistant
  3. # youtube.com/Kxffie
  4. # https://kxffie.itch.io/chatgpt-jarvis-assistant
  5. #
  6. # Updated code. you can now input your own session ID and everything is now one file.
  7. #
  8.  
  9. from pyChatGPT import ChatGPT
  10. import speech_recognition as sr
  11. import os
  12. import pyttsx3
  13.  
  14. os.system('cls' if os.name == 'nt' else 'clear')
  15. print("Find your session ID at https://chat.openai.com/ and right click the page.\nClick inspect and where it says \"Elements, Console, Sources etc...\" go into Application and find \"__Secure-next-auth.session-token\" and copy the value.\n")
  16. ID = input("Please input your Session Value: ")
  17. function = input(
  18.     "Would you like to use the chatbot or the voice assistant? (chat/voice) ")
  19. os.system('cls' if os.name == 'nt' else 'clear')
  20. print("Loading ChatGPT \"Jarvis\" Assistant...")
  21. api = ChatGPT(ID)
  22. engine = pyttsx3.init()
  23. engine.setProperty('rate', 130)
  24. os.system('cls' if os.name == 'nt' else 'clear')
  25.  
  26. stoppingWords = ["stop", "goodbye", "bye", "exit", "quit"]
  27.  
  28.  
  29. def main():
  30.     if function == "chat":
  31.         print("Type 'stop' to exit the chatbot.")
  32.         inp = input("Type something! > ")
  33.         if inp == "stop":
  34.             print("---------------\nGoodbye!\n---------------")
  35.             input("Press any button to quit...")
  36.             exit()
  37.         else:
  38.             response = api.send_message(inp)
  39.             print(f"---------------\n{response['message']}\n---------------")
  40.  
  41.     else:
  42.         r = sr.Recognizer()
  43.         with sr.Microphone() as source:
  44.             r.adjust_for_ambient_noise(source)
  45.             print("Say something!")
  46.             audio = r.listen(source)
  47.             finalAudio = r.recognize_google(audio).lower()
  48.             print(finalAudio)
  49.  
  50.             try:
  51.                 print(f"You said: {finalAudio}")
  52.  
  53.                 if any(word in finalAudio.split() for word in stoppingWords):
  54.                     print("---------------\nGoodbye!\n---------------")
  55.                     engine.say("Goodbye!")
  56.                     engine.runAndWait()
  57.                     input("Press any button to quit...")
  58.                     exit()
  59.                 else:
  60.                     engine.say("Thinking of a response...")
  61.                     engine.runAndWait()
  62.                     response = api.send_message(finalAudio)
  63.                     print(
  64.                         f"---------------\n{response['message']}\n---------------")
  65.                     engine.say(response["message"])
  66.                     engine.runAndWait()
  67.  
  68.             except Exception as e:
  69.                 print(f"Error: {e}")
  70.  
  71. while True:
  72.     main()
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement