我在 python 中将 gTTS 与 winsound 一起使用,文件正在保存,但它发出 windows 声音

I am using gTTS with winsound in python, the file is saving, but it makes the windows sound

我试图让它保存一个 .wav 文件,上面写着 "Good morning." 它这样做,等待两秒钟,然后播放 windows 声音。我正在使用 Python 3.7.2 并在 Windows 10.

上运行
from gtts import gTTS
import winsound
import time

tts = gTTS(text='Good morning', lang='en')
tts.save("good.wav")
time.sleep(2)
#it works until here
winsound.PlaySound("good", winsound.SND_FILENAME)

这是因为,winsound 模块仅适用于 wav 文件格式和 gtts保存为mp3格式,所以你需要使用一些可以播放mp3格式的模块,比如vlc模块.

我使用 vlc 模块进行了相同的尝试,并且成功了。

可以安装vlc包

pip install python-vlc