Advertisement
SMASIF

Live Chat With Voice

Aug 30th, 2020
3,387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. import pyttsx3
  2. import webbrowser
  3. import smtplib
  4. import random
  5. import speech_recognition as sr
  6. import wikipedia
  7. import datetime
  8. import wolframalpha
  9. import os
  10. import sys
  11. import googlesearch
  12. import pyautogui
  13. import time
  14.  
  15. engine = pyttsx3.init('sapi5')
  16.  
  17. client = wolframalpha.Client('Your_App_ID')
  18.  
  19. voices = engine.getProperty('voices')
  20. engine.setProperty('voice', voices[len(voices) - 1].id)
  21.  
  22.  
  23. def speak(audio):
  24.     print('Computer: ' + audio)
  25.     engine.say(audio)
  26.     engine.runAndWait()
  27.  
  28.  
  29. def greetMe():
  30.     currentH = int(datetime.datetime.now().hour)
  31.     if currentH >= 0 and currentH < 12:
  32.         speak('Good Morning!')
  33.  
  34.     if currentH >= 12 and currentH < 18:
  35.         speak('Good Afternoon!')
  36.  
  37.     if currentH >= 18 and currentH != 0:
  38.         speak('Good Evening!')
  39.  
  40.  
  41. greetMe()
  42.  
  43. speak('Hello Sir, I am your digital assistant LARVIS the Lady Jarvis!')
  44. speak('How may I help you?')
  45.  
  46.  
  47. def myCommand():
  48.     r = sr.Recognizer()
  49.     with sr.Microphone() as source:
  50.         print("Listening...")
  51.         r.pause_threshold = 1
  52.         audio = r.listen(source)
  53.     try:
  54.         query = r.recognize_google(audio, language='en-in')
  55.         print('User: ' + query + '\n')
  56.  
  57.     except sr.UnknownValueError:
  58.         speak('Sorry sir! I didn\'t get that! Try typing the command!')
  59.         query = str(input('Command: '))
  60.  
  61.     return query
  62.  
  63.  
  64. if __name__ == '__main__':
  65.  
  66.     while True:
  67.  
  68.         query = myCommand();
  69.         query = query.lower()
  70.         time.sleep(2)
  71.         pyautogui.typewrite(query)
  72.         pyautogui.press('enter')
  73.         speak('Next Command! Sir!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement