- 安装pyttsx3库
pip
install
pyttsx3
pip install espeak
- pyttsx3库应用
import pyttsx3
engine = pyttsx3.init() #初始化语音引擎
rate = engine.getProperty('rate')
print(f'语速:{rate}')
volume = engine.getProperty('volume')
print (f'音量:{volume}')
engine.setProperty('rate', 100) #设置语速
engine.setProperty('volume',0.6) #设置音量
voices = engine.getProperty('voices')
for voice in voices:
print(voice)
voices = engine.getProperty('voices')
# engine.setProperty('voice',voices[o].id) #设置一个语音合成器()
engine.setProperty('voice','zh') #设置一个语音合成器(树莓派上中文只能这样,不然只能说英文可能是库的bug)
engine.say("hello,你好")
engine.runAndWait() engine.stop()