本文实例讲述了python将文本转换成语音的方法。分享给大家供大家参考。具体实现方法如下:
# 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 = """ Finagle's 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, let's 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!")
希望本文所述对大家的Python程序设计有所帮助。
标签:
python,文本,转换,语音
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“python实现将文本转换成语音的方法”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新动态
2024年11月09日
2024年11月09日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]