在WINDOWS平台下,只要你的电脑安装了python和win32com模块就可以让你的电脑说英语了.代码如下:
#如果输入有".", 则输入被看作是文件名,否则为一个英文单词.如:"aa.txt" (读aa.txt文件里的内容)
# "hello world" 则读"helloworld"
import sys
from win32com.client import constants
import win32com.client
speaker=win32com.client.Dispatch('SAPI.SpVoice')
print 'englist word OR a filename with . '
while 1:
try:
s=raw_input()
if '.' in s:
ss=file(s).read()
else:
ss=str(s)
speaker.Speak(ss)
except:
if sys.exc_type is EOFError:
sys.exit()
#如果输入有".", 则输入被看作是文件名,否则为一个英文单词.如:"aa.txt" (读aa.txt文件里的内容)
# "hello world" 则读"helloworld"
import sys
from win32com.client import constants
import win32com.client
speaker=win32com.client.Dispatch('SAPI.SpVoice')
print 'englist word OR a filename with . '
while 1:
try:
s=raw_input()
if '.' in s:
ss=file(s).read()
else:
ss=str(s)
speaker.Speak(ss)
except:
if sys.exc_type is EOFError:
sys.exit()
本文介绍如何使用Python和win32com模块在Windows平台上实现文本转语音的功能。通过简单的代码示例,展示了如何让计算机朗读英文单词或文件中的内容。
4279

被折叠的 条评论
为什么被折叠?



