-
Notifications
You must be signed in to change notification settings - Fork 20
/
quote.py
39 lines (29 loc) · 1017 Bytes
/
quote.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
import pyttsx3
import wikiquotes
import random
import re
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
#text cleaning function to eliminate parenthesis and backslash.
def text_clean(text):
text = re.sub("\\\\",'',text)
text = re.sub(r'\([^)]*\)', '', text)
return text
#you can always add more speakers
speakers = ["inspiration","tonny robbins", "love","life","les brown",
"eric thomas","jim rohn","brian tracy","mel robbins"]
def tell_quote(how_many =1):
quotes = wikiquotes.get_quotes(random.sample(speakers,how_many)[0],"english")
acceptables = []
for quote in quotes:
length = len(quote.split(" "))
sents = len(quote.split("."))
if length>5 and sents<=10:
acceptables.append(quote)
tell_quote = random.sample(acceptables,1)[0]
tell_quote = text_clean(tell_quote)
speak(tell_quote)