基于Python编写简易文字语音转换器

话不多说上代码!源代码

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文字语音转换内容请搜索编程教程以前的文章,希望以后支持编程教程

 1.引言我们之前已经介绍了神经网络的基本知识,神经网络的主要作用就是预测与分类,现在让我们来搭建第一个用于拟合回归的神经网络吧。 2.神经网络搭建2.1 准备工 ...