from comtypes.client import CreateObject
from comtypes.gen import SpeechLib
engine = CreateObject("SAPI.SpVoice")
stream = CreateObject("SAPI.SpFileStream")
infile = "SHIVA.txt"
outfile = "三体.mp3"
stream.Open(outfile, SpeechLib.SSFMCreateForWrite)
engine.AudioOutputStream = stream
f = open(infile, 'r',encoding='utf-8')
theText = f.read()
f.close()
engine.speak(theText)
stream.Close()
搜索
复制