python文字转语音
依赖pyttsx3库
pip install pyttsx3
yuyin_test1.py
import pyttsx3 engine = pyttsx3.init() engine.say("Fourth letters of transit in the spring breeze as you south ten.") engine.runAndWait()
如需要支持中文,需要执行:yuyin_test2.py
import pyttsx3 engine = pyttsx3.init() voices = engine.getProperty("voices") for item in voices: print(item.id,item.languages)
执行输出:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ZH-CN_HUIHUI_11.0 []
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0 []
支持中文的yuyin_test3.py:
import pyttsx3 engine = pyttsx3.init() engine.setProperty("voice","HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ZH-CN_HUIHUI_11.0") engine.say("南风在过境,十里春风,不如你。") engine.runAndWait()
感谢:https://www.cnblogs.com/socoo-/p/17063626.html
本文来自博客园,作者:河北大学-徐小波,转载请注明原文链接:https://www.cnblogs.com/xuxiaobo/p/17074913.html

浙公网安备 33010602011771号