iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >基于Python编写简易文字语音转换器
  • 926
分享到

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

2024-04-02 19:04:59 926人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

话不多说上代码!源代码 from tkinter import * import pyttsx3 class Application(Frame): def __init

话不多说上代码!源代码

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文字语音转换内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: 基于Python编写简易文字语音转换器

本文链接: https://www.lsjlt.com/news/142511.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作