Python Pydub Permission denied?
Asked Answered
E

4

6

When i run this code :

from pydub import AudioSegment
sound = AudioSegment.from_mp3("i.mp3")
sound.export("F:\\bh", format="wav")

A ffmpeg window pops up and i get this error:Error Pic

Even if i run it with admin privilleges: Error with admin privilleges

Note :
The error occurs on every location that I try to export

Ernestinaernestine answered 27/5, 2017 at 10:28 Comment(2)
same problem, no solutionHalt
Did you find the solution? @AnonymousMernamero
A
5

If you are on Windows, face this problem, and also have issues installing simpleaudio, you can try installing pyaudio instead.

If you are using Anaconda, you can install pyaudio with

conda install -c anaconda pyaudio

For me, simpleaudio on Anaconda is only available for Linux and MacOS and not Windows.

Allocate answered 24/8, 2019 at 3:47 Comment(1)
pip install pyaudio worked for me on windows 11Fatality
B
6

See this thread here. They suggest installing simpleaudio (pip install simpleaudio) to resolve this issue. It worked for me.

Bailor answered 2/8, 2019 at 16:3 Comment(0)
A
5

If you are on Windows, face this problem, and also have issues installing simpleaudio, you can try installing pyaudio instead.

If you are using Anaconda, you can install pyaudio with

conda install -c anaconda pyaudio

For me, simpleaudio on Anaconda is only available for Linux and MacOS and not Windows.

Allocate answered 24/8, 2019 at 3:47 Comment(1)
pip install pyaudio worked for me on windows 11Fatality
H
1

I had the same issue but fixed using the GillHawk solution from this thread (same link as Jondiepdoop gave). I added f.close() in the _play_with_ffplay function of the playback.py file :

def _play_with_ffplay(seg):
with NamedTemporaryFile("w+b", suffix=".wav") as f:
    f.close() # close the file stream
    seg.export(f.name, "wav")
    subprocess.call([PLAYER, "-nodisp", "-autoexit", "-hide_banner", f.name])
Hydrangea answered 31/12, 2022 at 9:10 Comment(1)
amazing solution. In my case, I also need no the r' before the file path, like sound = AudioSegment.from_file('C:\\temp\\audio1.mp3', format="mp3").Lavettelavigne
F
0

You can also choose to do the removal with os.remove()

import os

def _play_with_ffplay(seg):
    try:
        with NamedTemporaryFile("w+b", suffix=".wav", delete=False) as f:
            seg.export(f.name, "wav")
            subprocess.call([PLAYER, "-nodisp", "-autoexit", "-hide_banner", f.name])
    finally:
        os.remove(f.name)
Five answered 24/4 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.