-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Permission denied #209
Comments
Pydub uses temp files (specifically NamedTemporaryFile) pretty heavily. It looks like you don't have permission to write in the temp directory your python interpreter is configured to use. You can try setting the |
I changed the TMPDIR environment variable to a subfolder of the current directory. It is still giving the same error. My python program is able to write and read files from this folder for sure. Somehow pydub seems to throw the error:
|
So, you open this temp file using 'with', right? def _play_with_ffplay(seg):
with NamedTemporaryFile("w+b", suffix=".wav") as f:
seg.export(f.name, "wav")
subprocess.call([PLAYER, "-nodisp", "-autoexit", "-hide_banner", f.name]) But then you pass its name to AudioSegment.export(), which is, as you described, formatted as string: out_f (string): At this point, the file is still open. Then you open it again: out_f = _fd_or_path_or_tempfile(out_f, 'wb+') On linux distros, it works, but Windows isn't as forgiving. Opening a file twice, what for? A quick and dirty fix is to just save the name in a local variable, and pass that to the seg.export and subprocess.call calls, like this: def _play_with_ffplay(seg):
with NamedTemporaryFile("w+b", suffix=".wav") as f:
fileName = f.name
seg.export(fileName, "wav")
subprocess.call([PLAYER, "-nodisp", "-autoexit", "-hide_banner", fileName])
os.remove(fileName) But at the end of the day, antlarr's solution is better. No need to write pointless shite to the disk for every single audio playback. Goodest & bestest regards, |
…m_file Rename from_file to from_file_using_temporary_files just in case there's any case in which the new from_file doesn't work (I couldn't find any, but just in case, I guess it would be nice to keep it maybe as deprecated). Add a new from_file function that does all the reading on memory with pipes, not using any temporary file, which is faster and doesn't wear down disks for heavy usages. The new from_file function reads the input file and passes it to ffmpeg using a pipe and then reads ffmpeg output using another pipe directly to memory. Since wav files have the file length in the header and ffmpeg can't write it since it's working on a stream, we modify the resulting raw data from ffmpeg before reading it using the standard method. Fixes jiaaro#237 Might also fix jiaaro#209
Any update on this? I also have the problem. Traceback (most recent call last): |
Have Someone solved this problem? Please help me.
|
Same here, and looks like still no solution. I'm working on a Mac |
I have the same problem. I'm on windows 10. |
I had a similar problem (the same kind of "PermissionError: [Errno 13] Permission denied") with playback on Windows 8.1, and installing simpleaudio (executing 'pip install simpleaudio') solved the issue. |
On win 10, installing |
The fix for windows and other OSs that do not support opening same file twice is close the file stream before open it again. As pointed out by "kkealy", file is first opened by NamedTemporaryFile() then by seg.export() . Added a line in playback.py:
|
I used @GillHawk solution... worked like a charm on Win10. |
How is this one-liner bug fix not published before closing this ticket? |
@jiaaro take a look at GillHawk's Solution
|
That's it. This line in func _play_with_ffplay of playback.py resolve the problem :)
|
per jiaaro#209 (comment) Recent Windows update brought this issue back, this change resolves it.
im working on windows 11 pro but same problem do anyone have solution?? |
just "pip install simpleaudio" |
yes! this method is useful. |
Is there a problem with fixing this issue? It looks like it's been on hold for a VERY LONG time, given that it's basically a one liner. |
It does work! |
as @DaslavCl already said "pip install simpleaudio" magically solves the problem on Windows 11. |
i want use playback to play a music
but it alway tell me that i don't have permission,by the way, i can use cmd.exe to play a music.
code like that:
In [9]: sou1=AudioSegment.from_mp3(r'd:\02.mp3')
In [10]: play(sou1)
IOError Traceback (most recent call last)
in ()
----> 1 play(sou1)
c:\python27\lib\site-packages\pydub\playback.pyc in play(audio_segment)
44 _play_with_pyaudio(audio_segment)
45 except ImportError:
---> 46 _play_with_ffplay(audio_segment)
c:\python27\lib\site-packages\pydub\playback.pyc in _play_with_ffplay(seg)
16 def _play_with_ffplay(seg):
17 with NamedTemporaryFile("w+b", suffix=".wav") as f:
---> 18 seg.export(f.name, "wav")
19 subprocess.call([PLAYER, "-nodisp", "-autoexit", "-hide_banner",
f.name])
20
c:\python27\lib\site-packages\pydub\audio_segment.pyc in export(self, out_f, for
mat, codec, bitrate, parameters, tags, id3v2_version, cover)
579 id3v2_allowed_versions = ['3', '4']
580
--> 581 out_f = _fd_or_path_or_tempfile(out_f, 'wb+')
582 out_f.seek(0)
583
c:\python27\lib\site-packages\pydub\utils.pyc in _fd_or_path_or_tempfile(fd, mod
e, tempfile)
57
58 if isinstance(fd, basestring):
---> 59 fd = open(fd, mode=mode)
60
61 return fd
IOError: [Errno 13] Permission denied: 'c:\users\admini~1\appdata\local\tem
p\tmpuzjjby.wav'
System configuration
The text was updated successfully, but these errors were encountered: