话不多说上代码!源代码

from tkinter import *
import pyttsx3
 
class application(frame):
    def __init__(self,master=none):
        super().__init__(master)
        self.master = master
        self.pack()
        self.creatwidget()
 
    # bing input
    def creatwidget(self):
        self.w1 = text(self, width=80, heigh=40, bg='lightcyan') # 宽度为80个字母(40个汉字),高度为1个行高
        self.w1.pack()
        button(self, text="转语音", command=self.returntext).pack(side="left")
 
    # 返回信息
    def returntext(self):
        # indexes(索引):用来指向text组件中文本的位置,text的组件索引也是对应实际字符之间的位置
        # 行号以1开始,列号以0开始
        result=self.w1.get(1.0, end)
        # print("所有文本内容:\n", result)
        # messagebox.showinfo("所有的文本", self.w1.get(1.0, end))
        engine = pyttsx3.init()
        engine.say(result)
        engine.runandwait()
 
 
if __name__ == '__main__':
    root = tk()
    root.geometry("800x600+10+10")
    root.title("测试")
    app = application(root)
    root.mainloop()

用来打包的文件

# -*- mode: python ; coding: utf-8 -*-
 
 
block_cipher = none
 
 
a = analysis(['test.py'],
             pathex=[],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             hooksconfig={},
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=false,
             win_private_assemblies=false,
             cipher=block_cipher,
             noarchive=false)
pyz = pyz(a.pure, a.zipped_data,
             cipher=block_cipher)
 
exe = exe(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,  
          [],
          name='test',
          debug=false,
          bootloader_ignore_signals=false,
          strip=false,
          upx=true,
          upx_exclude=[],
          runtime_tmpdir=none,
          console=true,
          disable_windowed_traceback=false,
          target_arch=none,
          codesign_identity=none,
          entitlements_file=none )

效果展示

到此这篇关于基于python编写简易文字语音转换器的文章就介绍到这了,更多相关python文字语音转换内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!