版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jacke121/article/details/83513723
pip install comtypes
from comtypes.client import CreateObject
engine = CreateObject("SAPI.SpVoice")
stream = CreateObject("SAPI.SpFileStream")
from comtypes.gen import SpeechLib
infile = "d:/text.txt"
outfile = "d:/text5.wav"
stream.Open(outfile, SpeechLib.SSFMCreateForWrite)
engine.AudioOutputStream = stream
f = open(infile, 'r')
theText = f.read()
f.close()
engine.speak(theText)
stream.Close()
import win32com.client text="I love you baby"
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.rate=2
speaker.Speak(text)
pip install speech