Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 gTTS 模块在 Python 中将文本转换为语音。有没有一种方法可以使用,它不涉及将音频保存到 mp3 文件而是直接播放它?我在网上看了一段时间,但我仍然找不到完全避免保存到文件的方法。谢谢!
尝试使用 pyttsx3。用法:
import pyttsx3 engine = pyttsx3.init() engine.say("I will speak this text") engine.runAndWait()
这不会将音频保存到 mp3 文件并且可以离线工作。
链接到源代码
您还可以使用此功能,它可以让您选择修改语音文本的速度,在下面的示例中,速度为 178:
engine.setProperty("rate", 178)