40 lines
872 B
Python
40 lines
872 B
Python
from gtts import gTTS
|
|
import os
|
|
|
|
import datetime
|
|
|
|
from playsound import playsound
|
|
|
|
|
|
def tts(inputText:str, *args):
|
|
|
|
destPath = os.getcwd() + "\\tts\\"
|
|
time = datetime.datetime.now()
|
|
fileName:str = time.strftime("%m-%d-%Y_%H-%M-%S") + "_tts.mp3"
|
|
|
|
if len(args) == 1:
|
|
fileName = args[0] + "_tts.mp3"
|
|
|
|
tts = gTTS(text=inputText, lang='en')
|
|
tts.save(destPath + fileName)
|
|
|
|
playsound(destPath + fileName)
|
|
|
|
#os.system(filename)
|
|
|
|
def play_speech(fileName):
|
|
destPath = os.getcwd() + "\\tts\\"
|
|
playsound(destPath + fileName)
|
|
|
|
if __name__ == "__main__":
|
|
print("Enter Text: ")
|
|
textInput = str(input())
|
|
print("Custom FileName? y/n: ")
|
|
bool_string = str(input())
|
|
|
|
if bool_string == "y":
|
|
print("Enter FileName: ")
|
|
fileName = str(input())
|
|
tts(textInput, fileName)
|
|
else:
|
|
tts(textInput) |