-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfindOnScreen.py
45 lines (37 loc) · 1.14 KB
/
findOnScreen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# python code to take input via voice and take a screenshot and search that spoken element on the screen using pyautogui
# pip install pyautogui
# pip install speechrecognition
# pip install pyttsx3
import pyautogui
import speech_recognition as sr
import pyttsx3
engine = pyttsx3.init()
engine.setProperty('rate', 150)
engine.setProperty('volume', 0.9)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
print(e)
print("Say that again please...")
return "None"
return query
if __name__ == "__main__":
speak("What do you want to search on the screen?")
query = takeCommand().lower()
try:
speak("Searching...")
print(pyautogui.locateCenterOnScreen(query + ".png"))
except:
speak("Sorry, I could not find it on the screen.")
# Path: screenshot.py