pyttsx3 的使用教程

Posted liumengsong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyttsx3 的使用教程相关的知识,希望对你有一定的参考价值。

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 的使用教程的主要内容,如果未能解决你的问题,请参考以下文章