安装pyttsx3。 pip install pyttsx3
import pyttsx3
engine = pyttsx3.init()
"""更改速率"""
rate = engine.getProperty('rate') # getting details of current speaking rate
engine.setProperty('rate', 80) # setting up new voice rate
"""更改音量"""
volume = engine.getProperty('volume') # getting to know current volume level (min=0 and max=1)
engine.setProperty('volume', 1.0) # setting up volume level between 0 and 1
"""更改声音"""
voices = engine.getProperty('voices') # getting details of current voice
# print(voices)
# for v in voices:
# print(v)
# engine.setProperty('voice', voices[25].id) #changing index, changes voices. o for male tw
# engine.setProperty('voice', voices[36].id) #changing index, changes voices. o for male hk 粤语
engine.setProperty('voice', voices[39].id) #changing index, changes voices. o for male cn
mystr = "建设全国统一大市场是构建新发展格局的基础支撑和内在要求。意见明确,加快建立全国统一的市场制度规则,打破地方保护和市场分割,打通制约经济循环的关键堵点,促进商品要素资源在更大范围内畅通流动,加快建设高效规范、公平竞争、充分开放的全国统一大市场,全面推动我国市场由大到强转变,为建设高标准市场体系、构建高水平社会主义市场经济体制提供坚强支撑。 "
engine.say(mystr)
# engine.runAndWait()
# engine.save_to_file(mystr, './abcd.mp3')
engine.runAndWait()
网友评论