国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python實現將文本轉換成語音的方法

2020-02-23 01:27:06
字體:
來源:轉載
供稿:網友

本文實例講述了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  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!")

希望本文所述對大家的Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 精河县| 友谊县| 额尔古纳市| 阳山县| 当阳市| 武义县| 伊川县| 娱乐| 县级市| 修武县| 公主岭市| 枞阳县| 南江县| 华亭县| 陈巴尔虎旗| 双流县| 台中县| 洱源县| 中西区| 普宁市| 洛宁县| 莱西市| 宽城| 郓城县| 平原县| 广南县| 丰宁| 吴堡县| 天镇县| 武宁县| 昌乐县| 濮阳县| 绍兴县| 余姚市| 云霄县| 博野县| 雷波县| 凤台县| 耒阳市| 广德县| 乌鲁木齐市|