文本转语音
使用pyttsx :pip install pyttsx
import pyttsx3 as px3
speaker = px3.init()
speaker.say('你好呀')
speaker.runAndWait()
使用SAPI
from win32com.client import Dispatch
speaker = Dispatch('SAPI.SpVoice')
speaker.Speak('我又回来了')
del speaker
使用SpeechLib
"""使用SpeechLib实现文本转语音"""
from comtypes.client import CreateObject
speak = CreateObject('SAPI.SpVoice')
stream = CreateObject('SAPI.SpFileStream')
from comtypes.gen import SpeechLib
infile = 'demo.txt' //需要转换的文件
outfile = 'demo_audio.wav' //输出文件名
stream.open(outfile, SpeechLib.SSFMCreateForWrite)
speak.AudioOutputStream = stream
f = open(infile, 'r', encoding='utf-8')
theText = f.read()
f.close()
speak.speak(theText)
stream.close()
语音转文本
使用PocketSphinx