DDR爱好者之家 Design By 杰米
本文实例讲述了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程序设计有所帮助。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月25日
2024年11月25日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]