jiaaro / pydub

Manipulate audio with a simple and easy high level interface
http://pydub.com
MIT License
8.96k stars 1.05k forks source link

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

Open RickyWang111 opened 2 years ago

RickyWang111 commented 2 years ago

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

hurdurderp commented 2 years ago

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)
fleabiter commented 1 year ago

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.

mian3kth commented 1 year ago

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

mian3kth commented 1 year ago

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

fleabiter commented 1 year ago

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.

kaiwangyu commented 10 months ago

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

thanks, it works for me

ralrdsxo94 commented 10 months ago

mian3kth 님 감사합니다.

maaz25925 commented 8 months ago

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.

TiranoZero commented 8 months ago

(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

Sudheer-Nanduri commented 4 months ago

For windows, installing PyAudio solved the issue of permissions.

freemedom commented 3 weeks ago

i have to say that after i solved by "delete=False", ffplay still doesn't have sound in windows. so i used the pyaudio to play sound.