python實(shí)現(xiàn)將文本轉(zhuǎn)換成語(yǔ)音的方法
本文實(shí)例講述了python將文本轉(zhuǎn)換成語(yǔ)音的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
# 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!")
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
python一行代碼就能實(shí)現(xiàn)數(shù)據(jù)分析的pandas-profiling庫(kù)
這篇文章主要為大家介紹了python一行代碼就能實(shí)現(xiàn)數(shù)據(jù)分析的pandas-profiling庫(kù),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01
使用Pytorch實(shí)現(xiàn)Swish激活函數(shù)的示例詳解
激活函數(shù)是人工神經(jīng)網(wǎng)絡(luò)的基本組成部分,他們將非線性引入模型,使其能夠?qū)W習(xí)數(shù)據(jù)中的復(fù)雜關(guān)系,Swish 激活函數(shù)就是此類激活函數(shù)之一,在本文中,我們將深入研究 Swish 激活函數(shù),提供數(shù)學(xué)公式,探索其相對(duì)于 ReLU 的優(yōu)勢(shì),并使用 PyTorch 演示其實(shí)現(xiàn)2023-11-11
Python鼠標(biāo)事件及坐標(biāo)獲取窗口和屏幕坐標(biāo)
這篇文章主要介紹了Python編程中如何通過(guò)鼠標(biāo)事件及坐標(biāo)獲取窗口坐標(biāo)和屏幕坐標(biāo)的示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-10-10
Python實(shí)現(xiàn)快速多線程ping的方法
這篇文章主要介紹了Python實(shí)現(xiàn)快速多線程ping的方法,實(shí)例分析了Python多線程及ICMP數(shù)據(jù)包的發(fā)送技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07
Python調(diào)用兩個(gè)機(jī)器人聊天的實(shí)戰(zhàn)
本文主要介紹了Python調(diào)用兩個(gè)機(jī)器人聊天,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
Python設(shè)置和解除Word文檔保護(hù)的實(shí)現(xiàn)步驟
在日常工作和學(xué)習(xí)中,我們經(jīng)常需要使用Word文檔來(lái)記錄和分享重要的信息,為了確保文檔內(nèi)容的安全性和完整性,了解如何保護(hù)和取消保護(hù)Word文檔顯得尤為重要,這篇博客將詳細(xì)介紹如何使用Python設(shè)置和解除Word文檔的保護(hù),需要的朋友可以參考下2025-02-02

