1、使用pyttsx
先安装pyttsx3 : pip3 install pyttsx3
包的使用参考: 在 https://pypi.org/ 搜索pyttsx3
import pyttsx3 as pyttsx
engine = pyttsx.init()
engine.setProperty('rate', 115) # 设置语音播报速度,一般115比较合适。
engine.setProperty('volume', 1.0) # 设置音量,level between 0 and 1,默认是1。
# getting details of current voice
voices = engine.getProperty('voices')
# changing index, changes voices. o for male。中度的女音,播报中、英文。
engine.setProperty('voice', voices[0].id)
# changing index, changes voices. 1 for female。高亮的女音,只播报英文,中文未播报。
# engine.setProperty('voice', voices[1].id)
engine.say('测试结束')
engine.say('End of Test')
# Saving Voice to a file,On linux make sure that 'espeak' and 'ffmpeg' are installed
engine.save_to_file('测试结束', 'test.mp3&