网络编程
位置:首页>> 网络编程>> Python编程>> 基于Python编写简易文字语音转换器

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

作者:Camile8  发布时间:2023-12-28 19:24:54 

标签: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()

用来打包的文件

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

# -*- 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编写简易文字语音转换器

来源:https://blog.csdn.net/lipeitong333/article/details/123493376

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com