我想使用 pyttsx3 将文本离线转换为语音,并且我想将输出保存到音频文件中。
我已经看到了这个问题,第一个答案正是我所需要的。我只是无法让它发挥作用。
运行时:
import pyttsx3
tts = pyttsx3.init()
tts.setProperty('voice', tts.getProperty('voice')[1])
tts.save_to_file("What an amazing day today! I'm gonna go for a swim.", "./filename.mp3")
tts.runAndWait()
它不会给我一个错误,它只是不输出任何东西并且不创建文件。我的其余部分应该是正确的,因为如果我这样做:
import pyttsx3
tts = pyttsx3.init()
tts.setProperty('voice', tts.getProperty('voice')[1])
tts.say("What an amazing day today! I'm gonna go for a swim.")
tts.runAndWait()
一切正常。
我希望代码的最高位输出到文件,相反,它什么也不做。我正在运行 Windows 10,最新更新。Python 3.7.4 32-bit 和 pyttsx3 2.71 版本 感谢您的帮助!
哦,还有一件事,我知道 save_to_file 的输出很可能不是 mp3,但我不知道它会是什么,我下一步需要它在 mp3 中,所以这就是我所说的。如果我尝试将文件扩展名设置为其他内容,它的运行方式相同。