-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (54 loc) · 1.72 KB
/
main.py
File metadata and controls
71 lines (54 loc) · 1.72 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from pynput import keyboard
import pyttsx3
import pyperclip
engine = pyttsx3.init()
def read_text(text):
engine.say(text)
# call when any key is pressed
# goal is to read the clipboard when the insert key is pressed
def on_press(key):
try:
if key == key.insert:
print("reading clipboard")
engine.say(pyperclip.paste())
if key == keyboard.Key.esc:
print("Pressed escape")
engine.stop()
except AttributeError:
print(".")
# print('special key {0} pressed'.format(key))
# when kill key is pressed the event handler is killed.
# this is done by returning "False"
def on_release(key):
# if key == keyboard.Key.esc:
# # Stop listener
print("stoped the listener")
# engine.stop()
# return False
def onWord(name, location, length):
print('word', name, location, length)
# print ('word', name, location, length)
# if keyboard.is_pressed("esc"):
# print("Stop")
# engine.stop()
# keyboard.Listener.stop
return False
def onError():
print("error occured")
if __name__ == "__main__":
print("Ultimate tts reader:")
print("press escape to quit program <ESC>")
# start of main program
# engine = pyttsx3.init()
engine.connect('started-word', onWord)
engine.startLoop(False)
listener = keyboard.Listener(
on_press=on_press,
on_release=on_release,
on_error=onError
)
listener.start()
read_text("Starting.")# To quit press the fn plus the insert key.")
while True:
engine.iterate()
engine.endLoop()