python实现将文本转换成语音的方法详解编程语言
2023-06-13 09:20:23 时间
# Text To Speech using SAPI (Windows) and Python module pyTTS by Peter Parente # download installer file pyTTS-3.0.win32-py2.4.exe # from: http://sourceforge.net/projects/uncassist # also needs: http://www.cs.unc.edu/Research/assist/packages/SAPI5SpeechInstaller.msi # and pywin32-204.win32-py2.4.exe at this date the latest version of win32com # from: http://sourceforge.net/projects/pywin32/ # tested with Python24 on a Windows XP computer vagaseat 15jun2005 import pyTTS import time tts = pyTTS.Create() # set the speech rate, higher value = faster # just for fun try values of -10 to 10 tts.Rate = 1 print "Speech rate =", tts.Rate # set the speech volume percentage (0-100%) tts.Volume = 90 print "Speech volume =", tts.Volume # get a list of all the available voices print "List of voices =", tts.GetVoiceNames() # explicitly set a voice tts.SetVoiceByName(MSMary) print "Voice is set ot MSMary" print # announce the date and time, does a good job timeStr = "The date and time is " + time.asctime() print timeStr tts.Speak(timeStr) print str1 = """ A young executive was leaving the office at 6 pm when he found the CEO standing in front of a shredder with a piece of paper in hand. "Listen," said the CEO, "this is important, and my secretary has left. Can you make this thing work?" "Certainly," said the young executive. He turned the machine on, inserted the paper, and pressed the start button. "Excellent, excellent!" said the CEO as his paper disappeared inside the machine. "I just need one copy." print str1 tts.Speak(str1) tts.Speak(Haah haa haah haa) print str2 = """ Finagles fourth law: Once a job is fouled up, anything done to improve it only makes it worse. print str2 print print "The spoken text above has been written to a wave file (.wav)" tts.SpeakToWave(Finagle4.wav, str2) print "The wave file is loaded back and spoken ..." tts.SpeakFromWave(Finagle4.wav) print print "Substitute a hard to pronounce word like Ctrl key ..." #create an instance of the pronunciation corrector p = pyTTS.Pronounce() # replace words that are hard to pronounce with something that # is spelled out or misspelled, but at least sounds like it p.AddMisspelled(Ctrl, Control) str3 = p.Correct(Please press the Ctrl key!) tts.Speak(str3) print print "2 * 3 = 6" tts.Speak(2 * 3 = 6) print tts.Speak("sounds goofy, lets replace * with times") print "Substitute * with times" # * needs the spaces p.AddMisspelled( * , times) str4 = p.Correct(2 * 3 = 6) tts.Speak(str4) print print "Say that real fast a few times!" str5 = "The sinking steamer sunk!" tts.Rate = 3 for k in range(7): print str5 tts.Speak(str5) time.sleep(0.3) tts.Rate = 0 tts.Speak("Wow, not one mispronounced word!")
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8135.html
cgojavamacpythonwindows相关文章
- python中pygame怎么安_Python中pygame安装方法图文详解
- 多重共线性:python计算VIF以及使用vif做因子独立性检验的方法「建议收藏」
- Python元组_python元组的定义方式
- 【说站】python错误类型捕获的方法
- 【说站】python字符串方法format()如何使用
- 【说站】python访问元组的两种方法
- 【说站】python类方法如何定义
- 【说站】Python随机数中种子的使用
- {Python}关于类属性、类方法和静态方法的综合案例
- python读取图像数据的一些方法[通俗易懂]
- python lambda表达式 if_Python学习-lambda表达式
- python win32api sendmessage_Python win32api.SendMessage方法代码示例[通俗易懂]
- 【7】python_matplotlib 输出(保存)矢量图方法;画图时图例说明(legend)放到图像外侧;Python_matplotlib图例放在外侧保存时显示不完整问题解决
- python多线程有几种实现方法详解编程语言
- Python获取脚本所在目录的正确方法详解编程语言
- python scrapy 网络采集使用代理的方法详解编程语言
- python发送各类邮件的主要方法详解编程语言
- Python类三种方法,函数传参,类与实例变量(一)详解编程语言
- 小白的Python之路 day5 python模块详解及import本质编程语言
- CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法详解编程语言
- MySQL与Python搭配,实现数据库操作。(mysql-python)
- python图片匹配方法详解编程语言
- Python面向对象中的classmethod类方法和__getattr__方法介绍详解编程语言
- Python unittest跳过测试用例(2种方法,附带实例分析)
- python驱动使用pip安装MySQL Python驱动的简单步骤(pip安装mysql)
- 如何在Linux中安装Python?(linux安装python)
- Python中MYSQLdb出现乱码的解决方法
- python字典多条件排序方法实例
- python实现从字符串中找出字符1的位置以及个数的方法