pydub icon indicating copy to clipboard operation
pydub copied to clipboard

pydub.playback.play(),‘PermissionError: [Errno 13] Permission denied’

Open RickyWang111 opened this issue 2 years ago • 10 comments

Steps to reproduce

from pydub.playback import play
from pydub import AudioSegment
a=AudioSegment.from_wav(r'G:\aaaa11.wav')
play(a)

Expected behavior

Audio should be played normally.

Actual behavior

Outputs of section "Steps to reporduce" mentioned:

G:\pythonProject\djangoProject\gongju_heji\Scripts\python.exe G:/gongju_heji/linshi/a_1.py 
Traceback (most recent call last):
  File "G:\gongju_heji\linshi\a_1.py", line 4, in <module>
    play(a)
  File "G:\pythonProject\djangoProject\gongju_heji\lib\site-packages\pydub\playback.py", line 71, in play
    _play_with_ffplay(audio_segment)
  File "G:\pythonProject\djangoProject\gongju_heji\lib\site-packages\pydub\playback.py", line 15, in _play_with_ffplay
    seg.export(f.name, "wav")
  File "G:\pythonProject\djangoProject\gongju_heji\lib\site-packages\pydub\audio_segment.py", line 867, in export
    out_f, _ = _fd_or_path_or_tempfile(out_f, 'wb+')
  File "G:\pythonProject\djangoProject\gongju_heji\lib\site-packages\pydub\utils.py", line 60, in _fd_or_path_or_tempfile
    fd = open(fd, mode=mode)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Hasee\\AppData\\Local\\Temp\\tmppzzfa4vs.wav'

Your System configuration

  • Python version: 3.10.8
  • Pydub version: 0.25.1
  • ffmpeg or avlib?: ffmpeg
  • ffmpeg/avlib version:

RickyWang111 avatar Oct 21 '22 02:10 RickyWang111

Hello, had the same issue. Use / instead of \ in the filepath Like that:

from pydub.playback import play
from pydub import AudioSegment 
a=AudioSegment.from_wav(r'G:/aaaa11.wav') 
play(a)

hurdurderp avatar Nov 12 '22 16:11 hurdurderp

The issue isn't opening the source sound file. The issue is with pydub.playback.play() writing a file in the user's TEMP directory as shown in the last line of the @RickyWang111 output. Perhaps somewhere in the utils.py code there is some code that Windows is choking on. Someone suggested installing simpleaudio to replace the tempfile code but that didn't work for me.

I'm having the same problem on Windows 10 with Python 3.11.1 (released today)

I note that I have no trouble writing temporary files using the tempfile package.

fleabiter avatar Dec 27 '22 19:12 fleabiter

I got the same problem and by luck I tested to set "delete=False" in the below code: python

mian3kth avatar Dec 28 '22 11:12 mian3kth

This was after I installed ffmpeg and added it to path... Now it plays the sound in my sample wav-file. However, now it will fill up with a new wav file in temp directory each time I play the sound I guess... This problem is beyond my paygrade :-)

mian3kth avatar Dec 28 '22 11:12 mian3kth

The errant code is likely in the utils.py where the code tries to figure out how near the temporary file is to being open. The problem is shown as being in the function def _fd_or_path_or_tempfile where it tries to determine at what stage the opening of the temporary file is: None, a string (the file path) or a file handle.

Ideally, the Tempfile wouldn't need to be checked and rechecked and I suspect the problem lies in trying to open a file that is already opened by either the TemporaryFile or NamedTemporaryFile functions of the tempfile package.

fleabiter avatar Dec 28 '22 16:12 fleabiter

I got the same problem and by luck I tested to set "delete=False" in the below code: python

thanks, it works for me

kaiwangyu avatar Dec 30 '23 03:12 kaiwangyu

mian3kth 님 감사합니다.

ralrdsxo94 avatar Jan 16 '24 15:01 ralrdsxo94

I got the same problem and by luck I tested to set "delete=False" in the below code: python

It does indeed work but EVERY time you play an audio, it generates a temporary file which does NOT get deleted since you have provided that argument causing the memory to be filled with temporary files if you ever integrate this in an actual software.

maaz25925 avatar Mar 04 '24 20:03 maaz25925

(Translate) Mesmo fazendo isso aí, agora to recebendo esse erro:

Captura de tela 2024-03-15 110256

Failed to set value 'C:\Users\WINDOW~1\AppData\Local\Temp\tmp2kxg6ejz.wav' for option 'hide_banner': Option not found

TiranoZero avatar Mar 15 '24 14:03 TiranoZero

For windows, installing PyAudio solved the issue of permissions.

Sudheer-Nanduri avatar Jul 16 '24 12:07 Sudheer-Nanduri