Bootstrap

Python 语音识别

1、使用pyttsx 文本转语音:

import pyttsx3 as pyttsx
engine=pyttsx.init()
engine.say('你好呀')
engine.runAndWait()

2、使用API文本转语音:

from win32com.client import Dispatch
msg="你是谁"
msg1="我是你"
speaker=Dispatch('SAPI.SpVoice')
speaker.Speak(msg1)
del speaker  #释放speaker对象

3、使用SpeechLib 文本转语音:

from comtypes.client import CreateObject
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()

;