-
Notifications
You must be signed in to change notification settings - Fork 1
/
tts.py
52 lines (40 loc) · 1.21 KB
/
tts.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
46
47
48
49
50
51
52
# class handles keyboard input and reading of the text
# by oran collins
# github.com/wisehackermonkey
# oranbusiness@gmail.com
# 20200419
from pynput import keyboard
import pyttsx3
import pyperclip
# example useage
# tts = TTS()
# while True:
# tts.iterate()
# tts.endloop()
class TTS():
def __init__(self):
self.engine = pyttsx3.init()
self.engine.startLoop(False)
self.listener = keyboard.Listener(
on_press=self.on_press,
on_error=self.onError
)
self.listener.start()
def read_text(self, text):
self.engine.say(text)
def iterate(self):
self.engine.iterate()
def endloop(self):
self.engine.endLoop()
# call when any key is pressed
# goal is to read the clipboard when the insert key is pressed
def on_press(self,key):
try:
if key == key.insert:
print("\nreading clipboard")
self.engine.say(pyperclip.paste())
except AttributeError:
print("." , end="")
# print(f'special key {key} pressed')
def onError(self):
print("error occurred")