# 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)

分享到:

2009-04-16 11:02

浏览 4245

评论

4 楼

wangchao719

2010-01-29

恩,试了一下,很不错

可以发中文,可能和2楼的系统环境不同~~

3 楼

tomqyp

2009-07-25

引用

操作系统:winxp,4元一张

 

2 楼

lampeter123

2009-04-18

lyhapple 写道

很强大.收藏了,也许以后用得上..呵呵.

谢谢你的支持,暂时还只能支持英文发声,如果有中文识别引擎就好了

1 楼

lyhapple

2009-04-17

很强大.收藏了,也许以后用得上..呵呵.

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐