利用Python 的 库文本转语音
结果为:
.wav音频
原文本为:
好好学习
天天向上
代码如下:
# -*- coding: utf-8 -*-
# @Time : 2019/10/20 2:44
# @Author : Administrator
# @File : yuyin1.py
# @Software: PyCharm
from comtypes.client import CreateObject
import comtypes.client # Importing comtypes.client will make the gen subpackage
try:
from comtypes.gen import SpeechLib # comtypes
except ImportError:
# Generate the SpeechLib lib and any associated files
engine = comtypes.client.CreateObject("SAPI.SpVoice")
stream = comtypes.client.CreateObject("SAPI.SpFileStream")
from comtypes.gen import SpeechLib
#from comtypes.gen import SpeechLib
engine=CreateObject('SAPI.SpVoice')
stream=CreateObject('SAPI.SpFileStream')
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()
网友评论