-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from shyamcody/master
added quote.py for quote and solved the #7 issue.
- Loading branch information
Showing
3 changed files
with
116 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) |