python3 pyttsx3 文字转语音库使用
最近再做一个项目,需要文字转语音,决定使用此库了。
1.安装
pip install pyttsx3
# 若未安装pywin32, 需要安装此库的
pip install pywin32
2.官方文档
官方网址https://pyttsx3.readthedocs.io/en/latest/engine.html
3.使用
- 简单使用
import pyttsx3
# 初始化, 必须要有奥
engine = pyttsx3.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
# 注意,没有本句话是没有声音的
engine.runAndWait()
- 播放中文语音,python3下直接写就好了,不需要设置语言blabla的
就不要在意合成语音的僵硬问题了。。。
import pyttsx3
# 初始化, 必须要有奥
engine = pyttsx3.init()
engine.say('语音合成开始')
engine.say('我会说中文了,开森,开森')
# 注意,没有本句话是没有声音的
engine.runAndWait()
- 我在这项目要用的,如果要多次调用say()函数,并不是一次调用就结束了。
每次调用都有加上engine.runAndWait()就可以了
import pyttsx3
# 初始化, 必须要有奥
engine = pyttsx3.init()
engine.say('语音合成开始')
engine.say('我会说中文了,开森,开森')
# 注意,没有本句话是