python--pyttsx3模块

文字转语音

import pyttsx3

# 初始化一个朗读引擎
engine = pyttsx3.init()
# 阅读
engine.say("study Python!")
# 运行并且等到播放完毕

#修改音量 0-1.0
volume = engine.setProperty("volume",1)

#修改语速
engine.setProperty("rate",200)

#获取默认合成器
voices = engine.getProperty("voices")
print(voices)

# 修改合成器
engine.setProperty("voives",voices[1].id)

将文字保存到MP3中
engine.save_to_file("把文字,写到,MP3,中,测试内容",'output.mp3')
# 运行并且等到播放完毕
engine.runAndWait()
posted @ 2022-05-30 15:12  梁永旺  阅读(314)  评论(0编辑  收藏  举报