[Python] Playsound only plays the mp3 file once and then gives the error "Permission Denied"

Discussão em 'Python' iniciado por Stack, Agosto 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Playsound and gtts in Spyder IDE which creates an mp3 file and then plays it.

    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")


    It plays fine the first time but then shows this every time I run it:

    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'


    It works fine again after I restart Spyder, then again doesn't work after playing only once. My OS is Windows 10, Playsound version 1.2.2

    Continue reading...

Compartilhe esta Página