使用pyttsx3包,先安装。
核心代码:engine = pyttsx3.init() # 初始化
uname = "周吴郑王"
engine.say("奥利给给给" + str(uname) + "的" + str(uname) + ",感谢!!!") engine.runAndWait() # 没有这句不行哦
engine.stop()
-
源代码:
import pyttsx3
if __name__ == '__main__':
# for speak audio
engine = pyttsx3.init() # object creation
""" RATE"""
rate = engine.getProperty('rate') # getting details of current speaking rate
# print(rate) #printing current voice rate
engine.setProperty('rate', 100) # setting up new voice rate
"""VOLUME"""
volume = engine.getProperty('volume') # getting to know current volume level (min=0 and max=1)
print(volume) # printing current volume level
engine.setProperty('volume', 0.7) # setting up volume level between 0 and 1
"""VOICE"""
voices = engine.getProperty('voices') # getting details of current voice
engine.setProperty('voice', voices[0].id) #changing index, changes voices. o for male. and this can speak chinese
# engine.setProperty('voice', voices[1].id) # changing index, changes voices. 1 for female. can't speak chinese
uname = "周吴郑王"
engine.say("奥利给给给" + str(uname) + "的" + str(uname) + ",感谢!!!")
engine.runAndWait()
engine.stop()