llm-asr-tts/5_pyttsx3_test.py
LIRUI ad1fee9c4b
Some checks failed
Lint / quick-checks (push) Has been cancelled
Lint / flake8-py3 (push) Has been cancelled
Close inactive issues / close-issues (push) Failing after 2s
first commit
2025-03-17 00:41:41 +08:00

22 lines
608 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pyttsx3
# 初始化 TTS 引擎
engine = pyttsx3.init()
voices = engine.getProperty('voices')
# 打印出所有的音色信息
for voice in voices:
print(f'id = {voice.id}----name = {voice.name}')
# 设置语音属性
engine.setProperty('rate', 150) # 语速engine.setProperty('volume', 0.9) # 音量0.0 到 1.0
# 选择语音
voices = engine.getProperty('voices')
print(voices)
engine.setProperty('voice', voices[0].id) # 使用第一个语音
# 输入文本
text = "你好,今天天气很好,适合爬山"
# 朗读文本
engine.say(text)
# 等待朗读完成
engine.runAndWait()