text-to-speech - 有什么我应该添加到我的代码中来改进我的代码的吗
问题描述
这是我刚刚完成的代码,我想知道是否应该添加更多如果您想尝试我的代码,请确保安装“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()
解决方案
推荐阅读
- c# - 如何使用 Neo4jClient 添加多个标签
- sql - 在 SQL 中滚动 12 个月筛选条件
- javascript - 如何为驱动器文件 url 创建正则表达式?
- python - 实时算法交易专家的逻辑
- javascript - 将 prevState 数据数组与 nextState 进行比较
- c++ - 在 C++ 中获取嵌套的 JSON 数组和矩阵
- vue.js - 如何在 Vuejs 中的 keyup.enter 事件后取消对输入的关注?
- mysql - mysql-Docker 具有单独的基于文件的日志文件和日志轮换
- android - 等待数据库插入,Kotlin 协程
- javascript - 使用ajax将json从python返回到javascript时出现问题