-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtts.py
More file actions
24 lines (22 loc) · 801 Bytes
/
tts.py
File metadata and controls
24 lines (22 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pyttsx3
# function to speek the typed text from the users
def speekUserInput():
userInput = input("Please enter text to be spoken.")
if len(userInput) == 0:
print("User input must not be empty.")
else:
tts = pyttsx3.init()
tts.say(userInput)
tts.runAndWait()
# function to speek the text from text file
def speekFromFile():
fileName = input("Please type the file you would like spoken.")
try:
with open(fileName + ".txt", "r") as fileName:
fileContent = fileName.read()
print(fileContent)
tts = pyttsx3.init()
tts.say(fileContent)
tts.runAndWait()
except FileNotFoundError:
print("The file can't be found. You may want to try that again.")