#文本发音
import pyttsx3 as pyttsx
import win32com
# engine = pyttsx.init()
# engine.say('大家好,我是XXX。 这是我的唐诗机器人。妈妈,我爱你')
# engine.runAndWait()
from win32com.client import Dispatch
# msg = "大家好,我是XXX。 这是我的唐诗机器人。妈妈,我爱你"
# speaker = Dispatch('SAPI.SpVoice')
# speaker.Speak(msg)
# del speaker
from comtypes.client import CreateObject
from comtypes.gen import SpeechLib
engine = CreateObject('SAPI.SpVoice')
stream = CreateObject('SAPI.SpFileStream')
from comtypes.gen import SpeechLib
infile = 'demo.txt'
outfile = 'demo_audio.wav'
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()
利用文本发音
最新推荐文章于 2024-12-26 21:16:48 发布