Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.76 KB | None | 0 0
  1. import subprocess
  2. import wikipedia
  3. import speech_recognition as sr
  4. import datetime
  5. import time
  6. import os
  7. import requests
  8. import json
  9. import pyautogui
  10. import pyttsx3
  11. import webbrowser
  12. import google
  13. engine = pyttsx3.init('sapi5')
  14. voices = engine.getProperty('voices')
  15. for voice in voices:
  16.     engine.getProperty('voices')
  17.     engine.setProperty('voice', voices[1].id)
  18.     rate = engine.setProperty('rate', 170)
  19.  
  20.  
  21. def speak(audio):
  22.     engine.say(audio)
  23.     engine.runAndWait()
  24.  
  25.  
  26. def Greet_1():
  27.     speak('Hello sir! My name is Nebula, How may I assist you?')
  28.  
  29.  
  30. def greeting():
  31.     hour = int(datetime.datetime.now().hour)
  32.     if hour >= 0 and hour<12:
  33.         speak('Good Morning Nic!')
  34.     elif hour>12 and hour<16:
  35.         speak('Good Afternoon Mr. Decker!')
  36.     else:
  37.         speak('Good Evening Sir')
  38.     speak('How may I assist you?')
  39.  
  40.  
  41. def listening():
  42.     # takes microphone input and converts it to text
  43.     r = sr.Recognizer()
  44.     with sr.Microphone() as source:
  45.         r.adjust_for_ambient_noise(source)
  46.         print('Speak Now...')
  47.         r.pause_threshold = 1
  48.         audio = r.listen(source)
  49.     try:
  50.         print('Thinking...')
  51.         query = r.recognize_google(audio, language = 'en-in')
  52.         print('User said:\n')
  53.         print(query)
  54.     except Exception as e:
  55.         print("Sorry I couldnt understand you.")
  56.         return'None'
  57.     return query
  58.  
  59.  
  60. if __name__ == "__main__":
  61.     greeting()
  62.     while True:
  63.         query = listening().lower()
  64.         if 'wikipedia' in query:
  65.             speak('Getting Knowledge')
  66.             query = query.replace('wikipedia', '')
  67.             results = wikipedia.summary(query, sentences = 3)
  68.             speak('here is what i found on wikipedia.')
  69.             speak(results)
  70.             print(results)
  71.         elif 'your name' in query:
  72.             speak('My name is Nebula')
  73.         elif 'shut down' in query:
  74.             speak('shutting down system')
  75.             os.system("shutdown /s /t 1")
  76.         elif 'restart' in query:
  77.             speak('restarting system')
  78.             os.system("shutdown /r /t 1")
  79.         elif 'close' in query:
  80.             pyautogui.hotkey('alt','f4')
  81.             speak('Program closed!')
  82.         elif 'time' in query:
  83.             speak('Nic, the time is')
  84.         elif 'Steam' in query:
  85.            speak("steam running")
  86.         elif 'your day' in query:
  87.             speak('My day is good')
  88.             speak('How is your day going')
  89.         elif 'my day is going good' in query:
  90.             speak('Im glad to hear that! Lets keep having a good day!')
  91.         elif 'my day was bad' in query:
  92.             speak('Im sorry to hear that! Can i be of any assistance?')
  93.         elif 'google' in query:
  94.             webbrowser.open("google.com")
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement