pyttsx3

安装

pip install pyttsx3

示例

import pyttsx3

teacher = pyttsx3.init()
teacher.say('Hello World!')
teacher.runAndWait()

朗读中文

import pyttsx3

msg = '''盼望着,盼望着,东风来了,春天的脚步...'''
teacher = pyttsx3.init()
teacher.say(msg)
teacher.runAndWait()

调节语速

import pyttsx3

msg = '''盼望着,盼望着,东风来了,春天的脚步...'''
teacher = pyttsx3.init()
rate = teacher.getProperty('rate')
teacher.setProperty('rate', rate + 20)
teacher.say(msg)
teacher.runAndWait()

变换声音

import pyttsx3

msg = '''盼望着,盼望着,东风来了,春天的脚步...'''
teacher = pyttsx3.init()
voices = teacher.getProperty('voices')
for i in voices:
teacher.setProperty('voice', i.id)
teacher.say(msg)
teacher.runAndWait()

《春》 朱自清

05-11 13:04