赞
踩
- from comtypes.client import CreateObject
-
- engine = CreateObject('SAPI.SpVoice')
- stream = CreateObject('SAPI.SpFileStream')
-
- from comtypes.gen import SpeechLib
-
- infile = 'E:\\语音文档\\易经64卦读音.txt'
- outfile = 'E:\\demo.wav'
-
- stream.Open(outfile, SpeechLib.SSFMCreateForWrite)
- engine.AudioOutputStream = stream
- with open(infile, 'r', encoding='utf-8') as file:
- text = file.read()
- engine.speak(text)
- stream.close()
前一篇博文的代码中导入SpeechLib库的语句放到了最前面,头次运行代码无问题。再运行代码生成语音文件时就出现了此错误,提示意思是这个Typelib不同于模块的问题。SpeechLib改到了现在的位置,这样逻辑顺序才正确!就不再出现运行错误了!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。