-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtts_engine.py
49 lines (39 loc) · 1.33 KB
/
tts_engine.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
import pyttsx3
from bot_utils import find_url
class TTSEngine:
def __init__(self, template=''):
self.tts_engine = pyttsx3.init()
voices = self.tts_engine.getProperty('voices')
self.tts_engine.setProperty('voice', voices[1].id)
self.is_active = True
self.template = template
self.blacklist_words = set(
['gay', 'homosexual', 'nazi', 'porno', 'feminazi']
)
def read(self, message):
try:
if not self.is_active:
return
is_valid = self.validate_message(message.content.lower())
if is_valid:
self.tts_engine.say(self.template.format(
message.author.name, message.content))
self.tts_engine.runAndWait()
except Exception as ex:
print(ex)
def validate_message(self, message):
try:
words = set(message.split(' '))
words_count = len(words.intersection(self.blacklist_words))
if words_count > 0:
return False
has_url = find_url(message)
if has_url:
return False
return True
except Exception as ex:
print(ex)
def activate(self):
self.is_active = True
def deactivate(self):
self.is_active = False