import pyttsx3
import webbrowser
import smtplib
import random
import speech_recognition as sr
import wikipedia
import datetime
import wolframalpha
import os
import sys
from PIL import ImageGrab
import numpy as np
import cv2
import pyscreenshot as pys
engine = pyttsx3.init('sapi5')
client = wolframalpha.Client('7U52GP-Q9QKLQJJQL')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[len(voices)-1].id)
def speak(audio):
print('Computer: ' + audio)
engine.say(audio)
engine.runAndWait()
def greetMe():
currentH = int(datetime.datetime.now().hour)
if currentH >= 0 and currentH < 12:
speak('Good Morning!')
if currentH >= 12 and currentH < 18:
speak('Good Afternoon!')
if currentH >= 18 and currentH !=0:
speak('Good Evening!')
greetMe()
speak('Hello Sir, I am your digital assistant LARVIS the Lady Jarvis!')
speak('How may I help you?')
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-in')
print('User: ' + query + '\n')
except sr.UnknownValueError:
speak('Sorry sir! I didn\'t get that! Try typing the command!')
query = str(input('Command: '))
return query
if __name__ == '__main__':
while True:
query = myCommand();
query = query.lower()
if 'open youtube' in query:
speak('okay')
webbrowser.open('www.youtube.com')
elif 'open google' in query:
speak('okay')
webbrowser.open('www.google.co.in')
elif 'open gmail' in query:
speak('okay')
webbrowser.open('www.gmail.com')
elif "what\'s up" in query or 'how are you' in query:
stMsgs = ['Just doing my thing!', 'I am fine!', 'Nice!', 'I am nice and full of energy']
speak(random.choice(stMsgs))
elif 'ı love you' or 'love you' or 'ı like you' in query:
speak('ı love you to ')
recipient = myCommand()
elif 'do you like me' or "like me" or "are you like me" in query:
speak('yes ı lıke so much ')
recipient = myCommand()
elif 'take picture' or "take photo" or "my photo" or "photo please" or "picture please" in query:
speak('cheese ')
import cv2
video_capture = cv2.VideoCapture(0)
if not video_capture.isOpened():
speak("Could not open video device")
print("Could not open video device")
ret, frame = video_capture.read()
cv2.imshow("Capturing", frame)
video_capture.release()
recipient = myCommand()
elif 'screenshot' or 'take screenshot' or 'screen picture' in query:
speak('okey ')
def ekranGrountusuAl(sDosyaAdi):
try:
s
resim = ImageGrab.grab()
adi=sDosyaAdi+".jpg"
resim.save(adi,'JPEG')
except:
print ("Hata olustu")
ekranGrountusuAl("ekranresmi")
recipient = myCommand()
elif 'am ı good' or 'am ı healty' or 'ı am healty' in query:
speak('please fill in the information ')
boy = int(input("what is your size(cm):"))
kilo = float(input("what is you weight(kg):"))
endeks = kilo / ((boy/100) * (boy/100))
if endeks < 18:
speak("you are weak")
print("you are weak")
elif endeks < 25:
speak("you are healty")
print("you are healty")
elif endeks < 30:
speak("you are overweight")
print("you are overweight")
elif endeks < 35:
speak("you are first degree obese")
print("you are first degree obese")
elif endeks < 40:
speak("you are second degree obese")
print("you are second degree obese")
elif endeks > 40:
speak("you are third degree obese")
print("you are third degree obese")
else:
speak("error")
print("error")
recipient = myCommand()
elif 'take screen video' or 'screen video' in query:
speak('okay ı am rect the vıdeo.press q to stop recording')
forcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', forcc, 8, (1920,1080))
while True:
img= pys.grab()
img_np=np.array(img)
cv2.imshow('Screen', img_np)
out.write(img_np)
if cv2.waitKey(20) & 0xFF==ord('q'):
break
out.release()
cv2.destroyAllWindows()
recipient = myCommand()
elif 'email' in query:
speak('Who is the recipient? ')
recipient = myCommand()
if 'me' in recipient:
try:
speak('What should I say? ')
content = myCommand()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login("Your_Username", 'Your_Password')
server.sendmail('Your_Username', "Recipient_Username", content)
server.close()
speak('Email sent!')
except:
speak('Sorry Sir! I am unable to send your message at this moment!')
elif 'nothing' in query or 'abort' in query or 'stop' in query:
speak('okay')
speak('Bye Sir, have a good day.')
sys.exit()
elif 'hello' in query:
speak('Hello Sir')
elif 'bye' or "fuck of" in query:
speak('Bye Sir, have a good day.')
sys.exit()
elif 'play music' in query:
music_folder = Your_music_folder_path
music = [music1, music2, music3, music4, music5]
random_music = music_folder + random.choice(music) + '.mp3'
os.system(random_music)
speak('Okay, here is your music! Enjoy!')
else:
query = query
speak('Searching...')
try:
try:
res = client.query(query)
results = next(res.results).text
speak('WOLFRAM-ALPHA says - ')
speak('Got it.')
speak(results)
except:
results = wikipedia.summary(query, sentences=2)
speak('Got it.')
speak('WIKIPEDIA says - ')
speak(results)
except:
webbrowser.open('www.google.com')
speak('Next Command! Sir!')
Arkadaşlar bu şekilde bir asistan kodlamaya çalıştım(internetten bulduğum bir asistan üzerinde edit yaptım)Fakat bazı komutları doğru söylememe rağmen farklı işlemler yapıyor.Mesela "screenshot" diyorum fakat almıyor ve farklı bir cevap veriyor nedeni nedir?

