about comtypes:
https://pythonhosted.org/comtypes/
https://wenku.baidu.com/view/522398dece2f0066f5332222.html
http://svn.python.org/projects/ctypes/branches/comtypes-0.4/docs/comtypes.client.html
首先pip install comtypes
from comtypes.client import CreateObject engine = CreateObject("SAPI.SpVoice") stream = CreateObject("SAPI.SpFileStream")
from comtypes.gen import SpeechLib # maybe 上面两行代码需要放在此行前面
outfile = "welcome.wav" stream.Open(outfile, SpeechLib.SSFMCreateForWrite) engine.AudioOutputStream = stream engine.speak(data) stream.Close()
以上代码实现将data(文本)输出为welcome.wav,
import lame
cmd = 'lame --preset insane %s' % outfile
subprocess.call(cmd, shell=True)
以上代码使用进程调用cmd执行命令版lame将welcome.wav转换为welcome.mp3,需要下载lame并将lame.exe文件夹所在地址添加到系统环境变量