python实现将文本转换成语音的方法

python实现将文本转换成语音的方法,第1张

概述python实现将文本转换成语音方法

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

# 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  15jun2005import pyTTSimport timetts = pyTTS.Create()# set the speech rate,higher value = faster# just for fun try values of -10 to 10tts.Rate = 1print "Speech rate =",tts.Rate# set the speech volume percentage (0-100%)tts.Volume = 90print "Speech volume =",tts.Volume# get a List of all the available voicesprint "List of voices =",tts.GetVoicenames()# explicitly set a voicetts.SetVoiceByname('MSMary')print "Voice is set ot MSMary"print# announce the date and time,does a good jobtimeStr = "The date and time is " + time.asctime()print timeStrtts.Speak(timeStr)printstr1 = """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 str1tts.Speak(str1)tts.Speak('Haah haa haah haa')printstr2 = """Finagle's fourth law: Once a job is fouled up,anything done to improve it only makes it worse."""print str2printprint "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')printprint "Substitute a hard to pronounce word like Ctrl key ..."#create an instance of the pronunciation correctorp = pyTTS.Pronounce()# replace words that are hard to pronounce with something that # is spelled out or misspelled,but at least sounds like itp.AddMisspelled('Ctrl','Control')str3 = p.Correct('Please press the Ctrl key!')tts.Speak(str3)printprint "2 * 3 = 6"tts.Speak('2 * 3 = 6')printtts.Speak("sounds goofy,let's replace * with times")print "Substitute * with times"# ' * ' needs the spacesp.AddMisspelled(' * ','times')str4 = p.Correct('2 * 3 = 6')tts.Speak(str4)printprint "Say that real fast a few times!"str5 = "The sinking steamer sunk!"tts.Rate = 3for k in range(7):  print str5  tts.Speak(str5)  time.sleep(0.3)tts.Rate = 0tts.Speak("Wow,not one mispronounced word!")

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的python实现将文本转换成语音的方法全部内容,希望文章能够帮你解决python实现将文本转换成语音的方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1199281.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存