亲宝软件园·资讯

展开

Python文字语音转换

Camile8 人气:0

话不多说上代码!源代码

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 )

效果展示

加载全部内容

相关教程
猜你喜欢
用户评论