使用python把文本转化为声音
作者:枯藤天涯 转自:http://bbs.bccn.net/thread-258434-1-1.html
目的:
建立一个人机声音交互的可编程的环境
前提:
1.操作系统:winxp,4元一张
2.python解释器:python25,python-2.5.2.msi
3.python的windows扩展:pywin32-212.win32-py2.5.exe
4.微软声音识别引擎:
SAPI5VoiceInstaller.msi(WIN XP本身已安装好)
SAPI5SpeechInstaller.msi(WIN XP本身已安装好)
5.对微软声音识别引擎的python包装pyTTS:pyTTS-3.0.win32-py2.5.exe
注意:
在网上搜索的时候,注意版本的区别。上面是我使用的版本,是可以建立的。
步骤:
1.安装python-2.5.2.msi
2.安装pywin32-212.win32-py2.5.exe
它会找到python安装的目录。
3.安装微软声音识别引擎:
4.安装pyTTS,
会自动的找到python的安装目录.
注意:安装的时候注意安装的顺序。按照这个顺序安装,可以省去手动找目录的麻烦。
检测:
import pyTTS
tts=pyTTS.Create()
tts.Speak("I love China")
这时你就会听到I love China的声音了。
当然还可以做的更多。
作者:枯藤天涯 转自:http://bbs.bccn.net/thread-258434-1-1.html
目的:
建立一个人机声音交互的可编程的环境
前提:
1.操作系统:winxp,4元一张
2.python解释器:python25,python-2.5.2.msi
3.python的windows扩展:pywin32-212.win32-py2.5.exe
4.微软声音识别引擎:
SAPI5VoiceInstaller.msi(WIN XP本身已安装好)
SAPI5SpeechInstaller.msi(WIN XP本身已安装好)
5.对微软声音识别引擎的python包装pyTTS:pyTTS-3.0.win32-py2.5.exe
注意:
在网上搜索的时候,注意版本的区别。上面是我使用的版本,是可以建立的。
步骤:
1.安装python-2.5.2.msi
2.安装pywin32-212.win32-py2.5.exe
它会找到python安装的目录。
3.安装微软声音识别引擎:
4.安装pyTTS,
会自动的找到python的安装目录.
注意:安装的时候注意安装的顺序。按照这个顺序安装,可以省去手动找目录的麻烦。
检测:
import pyTTS
tts=pyTTS.Create()
tts.Speak("I love China")
这时你就会听到I love China的声音了。
当然还可以做的更多。
# to bring text to speech capability to your Windows computer# install SAPI5Speech (XP and Vista should have it already)# http://www.nolad.com/vt/redist/SAPI5SpeechInstaller.msi## Windows XP has Sam, SAPI5Voice adds Mary and Mike# http://www.nolad.com/vt/redist/SAPI5VoiceInstaller.msi## the Python for Windows extensions should be installed# for COM to work eg. pywin32-210.win32-py2.5.exe# from http://sourceforge.net/projects/pywin32/## tested with Python25 on a Windows XP machine by vegaseat import win32com.client voices = {'Sam' : 'Microsoft Sam','Mary' : 'Microsoft Mary','Mike' : 'Microsoft Mike'} # choose voice from the voices dictionaryvoice = 'Sam'# range 0(low) - 100(loud)volume = 100# range -10(slow) - 10(fast)rate = -1 # some text to speaktext = """\It is said, that if you line up all the cars in the world end to end, someone would be stupid enough and try to pass them.""" # initialize COM components of MS Speech API# COM is Microsoft's Component Object Model# (COM is also used by Peter Parente's pyTTS)speak = win32com.client.Dispatch('Sapi.SpVoice')# assign a voicespeak.Voice = speak.GetVoices('Name='+voices[voice]).Item(0)speak.Rate = ratespeak.Volume = volume# now speak out the textspeak.Speak(text)# to bring text to speech capability to your Windows computer
# install SAPI5Speech (XP and Vista should have it already)
# http://www.nolad.com/vt/redist/SAPI5SpeechInstaller.msi
#
# Windows XP has Sam, SAPI5Voice adds Mary and Mike
# http://www.nolad.com/vt/redist/SAPI5VoiceInstaller.msi
#
# the Python for Windows extensions should be installed
# for COM to work eg. pywin32-210.win32-py2.5.exe
# from http://sourceforge.net/projects/pywin32/
#
# tested with Python25 on a Windows XP machine by vegaseat
import win32com.client
voices = {
'Sam' : 'Microsoft Sam',
'Mary' : 'Microsoft Mary',
'Mike' : 'Microsoft Mike'
}
# choose voice from the voices dictionary
voice = 'Sam'
# range 0(low) - 100(loud)
volume = 100
# range -10(slow) - 10(fast)
rate = -1
# some text to speak
text = """\
It is said, that if you line up all the cars in the world end to end,
someone would be stupid enough and try to pass them.
"""
# initialize COM components of MS Speech API
# COM is Microsoft's Component Object Model
# (COM is also used by Peter Parente's pyTTS)
speak = win32com.client.Dispatch('Sapi.SpVoice')
# assign a voice
speak.Voice = speak.GetVoices('Name='+voices[voice]).Item(0)
speak.Rate = rate
speak.Volume = volume
# now speak out the text
speak.Speak(text)