pyttsx3
pyttsx3是一个Python库,用于将文本转换为语音输出。它支持多种操作系统,包括Windows和macOS,并且提供了丰富的功能来控制文本到语音的转换过程。
import pyttsx3
msg = "Hello World!"
pyttsx3.speak(msg)
engine = pyttsx3.init()
engine.say(msg)
engine.runAndWait()
""" 把语音存储到文件 """
engine.save_to_file(msg, "~/abc.mp3")
"""更改速率"""
rate = engine.getProperty("rate")
print(rate)
engine.setProperty("rate", 125)
"""更改音量"""
volume = engine.getProperty("volume")
print(volume)
engine.setProperty("volume", 1.0) # 0-1
"""语音"""
voice = engine.getProperty("voice")
print(voice)
voices = engine.getProperty("voices")
for voice in voices:
print(voice)
engine.setProperty("voice", voices[1].id)
engine.say(msg)
engine.runAndWait()
engine.stop()
标签:engine,pyttsx3,voices,语音,msg,voice,python3 From: https://www.cnblogs.com/caroline2016/p/18338119