这是我刚刚完成的代码,我想知道是否应该添加更多如果您想尝试我的代码,请确保安装“pyttsx3”和“pysimplegui”
import PySimpleGUI as sg
import pyttsx3
import pyttsx3.drivers
engine = pyttsx3.init()
engine.startLoop(False)
def speak(sentence):
engine.say(sentence)
sg.theme('TealMono') # Theme Color
# All the stuff inside your window.
layout = [ [sg.Text('Insert text'), sg.InputText(),],
[sg.Button('Speak', bind_return_key=True, button_color=("red", "#04323a")),
sg.Button('Cancel', button_color=("red", "#04323a")),
sg.Text('© Stephan Teig')
]
]
# Create the Window
window = sg.Window('Text to Speech', layout, use_ttk_buttons=True)
# Event Loop to process "events" and get the "values" of the inputs
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
break
engine.iterate()
speak(values[0])
window.close()
engine.endLoop()