python 文字转声音_使用python把文本转化为声音

# 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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值