日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

基于Python編寫簡易文字語音轉換器_python

作者:Camile8 ? 更新時間: 2022-05-17 編程語言

話不多說上代碼!源代碼

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 )

效果展示

原文鏈接:https://blog.csdn.net/lipeitong333/article/details/123493376

欄目分類
最近更新