我在Spyder IDE 中使用Playsound和gtts来创建一个mp3文件然后播放它。
import gtts
from playsound import playsound
#pass text to gTTS object
# make request to google to get synthesis
english = gtts.gTTS("Hello world") #retrieved the actual audio speech from the API
# save the audio file
english.save("hello.mp3")
# play the audio file
playsound("hello.mp3")
它第一次播放良好,但每次运行时都会显示:
File "C:\Users\ASUS\.spyder-py3\all codes\Text2Speech.py", line 27, in <module>
english.save("hello.mp3")
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python39\Lib\site-packages\gtts\tts.py", line 312, in save
with open(str(savefile), 'wb') as f:
PermissionError: [Errno 13] Permission denied: 'hello.mp3'
我重新启动 Spyder 后它再次正常工作,然后只玩一次后再次无法正常工作。我的操作系统是 Windows 10,Playsound 版本 1.2.2