python人工智能作业:Windows使用SAPI和tkinter用不到40行实现文本转语音工具

直接上代码:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 技术支持:https://www.jianshu.com/u/69f40328d4f0 
# 技术支持 https://china-testing.github.io/
# https://github.com/china-testing/python-api-tesing/blob/master/practices/TTS.py
# 讨论钉钉免费群21745728 qq群144081101 567351477
# CreateDate: 2018-11-22

import win32com.client as wincl
from tkinter import *


def text2Speech():
 text = e.get()
 speak = wincl.Dispatch("SAPI.SpVoice")
 speak.Speak(text)


#window configs
tts = Tk()
tts.wm_title("Text to Speech")
tts.geometry("225x105")
tts.config(background="#708090")


f=Frame(tts,height=280,width=500,bg="#bebebe")
f.grid(row=0,column=0,padx=10,pady=5)
lbl=Label(f,text="Enter your Text here : ")
lbl.grid(row=1,column=0,padx=10,pady=2)
e=Entry(f,width=30)
e.grid(row=2,column=0,padx=10,pady=2)
btn=Button(f,text="Speak",command=text2Speech)
btn.grid(row=3,column=0,padx=20,pady=10)
tts.mainloop()

参考资料

执行

图片.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。