赞
踩
- from comtypes.client import CreateObject
- from comtypes.gen import SpeechLib
-
- engine = CreateObject('SAPI.SpVoice')
- stream = CreateObject('SAPI.SpFileStream')
-
- infile = 'E:\\计算机科学速成课\\18. 操作系统-Operating Systems.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()
开始用创建对象的方法CreateObject 分别创建了语音引擎对象与语音文件流对象。调用流对象的Open()方法实现语音流数据写入音频输出文件。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。