码迷,mamicode.com
首页 > 其他好文 > 详细

pyttsx3 的使用教程

时间:2020-01-15 23:03:08      阅读:810      评论:0      收藏:0      [点我收藏+]

标签:最大   import   rate   详细信息   你好   tts   stop   wait   __name__   

import pyttsx3


def use_pyttsx3():
    # 创建对象
    engine = pyttsx3.init()
    # 获取当前语音速率
    rate = engine.getProperty(‘rate‘)
    print(f‘语音速率:{rate}‘)
    # 设置新的语音速率
    engine.setProperty(‘rate‘, 200)
    # 获取当前语音音量
    volume = engine.getProperty(‘volume‘)
    print(f‘语音音量:{volume}‘)
    # 设置新的语音音量,音量最小为 0,最大为 1
    engine.setProperty(‘volume‘, 0.5)
    # 获取当前语音声音的详细信息
    voices = engine.getProperty(‘voices‘)
    print(f‘语音声音详细信息:{voices}‘)
    # 设置当前语音声音为女性,当前声音不能读中文
    engine.setProperty(‘voice‘, voices[1].id)
    # 设置当前语音声音为男性,当前声音可以读中文
    engine.setProperty(‘voice‘, voices[0].id)
    # 获取当前语音声音
    voice = engine.getProperty(‘voice‘)
    print(f‘语音声音:{voice}‘)
    # 语音文本
    words = ‘你好,python!‘
    # 将语音文本说出来
    engine.say(words)
    engine.runAndWait()
    engine.stop()


if __name__ == ‘__main__‘:
    use_pyttsx3()

pyttsx3 的使用教程

标签:最大   import   rate   详细信息   你好   tts   stop   wait   __name__   

原文地址:https://www.cnblogs.com/liumengsong/p/12199017.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!