簡(jiǎn)介
支持:文字轉(zhuǎn)語音庫娃善,支持英文论衍,中文,可以調(diào)節(jié)語速聚磺、語調(diào)等坯台。
快速入門
## 安裝 pip install pyttsx3
import pyttsx3
engine=pyttsx3.init() # 初始化
engine.say('hello word')# 設(shè)置讀取內(nèi)容
engine.say('輕輕的我走了,正如我輕輕的來')
# with open('./ku.txt','r',encoding='utf-8')as rf:
# engine.say(rf.read())
engine.runAndWait() # 執(zhí)行朗誦
調(diào)節(jié)語速
## 安裝 pip install pyttsx3
import pyttsx3
msg = '''大江東去瘫寝,浪淘盡蜒蕾,千古風(fēng)流人物。故壘西邊焕阿,人道是:三國周郎赤壁咪啡。亂石穿空,驚濤拍岸暮屡,卷起千層雪撤摸。江山如畫,一時(shí)多少豪杰褒纲。
遙想公瑾當(dāng)年准夷,小喬初嫁了,雄姿英發(fā)莺掠。羽扇綸巾衫嵌,談笑間,檣櫓灰飛煙滅彻秆。故國神游楔绞,多情應(yīng)笑我,早生華發(fā)掖棉。人生初夢(mèng)墓律,一尊還酹江月'''
teacher = pyttsx3.init()
rate = teacher.getProperty('rate')
teacher.setProperty('rate', rate - 10)
teacher.say(msg)
teacher.runAndWait()
變換聲音
注意只能變換英文,讀取中文是不能變的幔亥;
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
print(voice, voice.id)
engine.setProperty('voice', voice.id)
engine.say("開心")
engine.runAndWait()
engine.stop()
生成文件mp3文件
# Import the required module
import pyttsx3
# Create a string
string = "Lorem Ipsum is simply dummy text " \
+ "of the printing and typesetting industry."
# Initialize the Pyttsx3 engine
engine = pyttsx3.init()
# We can use file extension as mp3 and wav, both will work
engine.save_to_file(string, 'speech.mp3')
# Wait until above command is not finished.
engine.runAndWait()