首页 > 解决方案 > 有什么我应该添加到我的代码中来改进我的代码的吗

问题描述

这是我刚刚完成的代码,我想知道是否应该添加更多如果您想尝试我的代码,请确保安装“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()

查看此图像以了解程序的运行情况

标签: text-to-speechpysimpleguipyttsx3

解决方案


推荐阅读