簡體   English   中英

使用pydub時拒絕訪問

[英]Access denied when using pydub

我想使用此腳本將 mp3 文件轉換為 wav 文件。

import pydub
from pydub import AudioSegment
pydub.AudioSegment.converter=r"C:\Users\sunha\ffmpeg-4.1-win64-static\bin"
sound = AudioSegment.from_mp3("筷子兄弟 - 小蘋果.mp3")
sound.export("筷子兄弟 - 小蘋果.wav", format="wav")

但問題是我的訪問被拒絕。

Traceback (most recent call last):

File "<ipython-input-1-5faa7bcb6b97>", line 1, in <module>
    runfile('C:/Users/sunha/project-001/untitled1.py', wdir='C:/Users/sunha/project-001')

File "E:\program\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
    execfile(filename, namespace)

File "E:\program\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/sunha/project-001/untitled1.py", line 4, in <module>
    sound = AudioSegment.from_mp3("筷子兄弟 - 小蘋果.mp3")

File "E:\program\lib\site-packages\pydub\audio_segment.py", line 716, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)

File "E:\program\lib\site-packages\pydub\audio_segment.py", line 697, in from_file
    stdout=subprocess.PIPE, stderr=subprocess.PIPE)

File "E:\program\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 143, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)

File "E:\program\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)

File "E:\program\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)

PermissionError: [WinError 5] 拒絕訪問。

我怎樣才能解決這個問題?

我嘗試了多種解決方案,這對我有幫助,如下所示:

  • 重新啟動計算機和/或 IDE,
  • 更新 Python、IDE、計算機、
  • pip install pydirectory (命令/Anaconda 提示符,以管理員身份運行)
  • 對文件應用讀取權限,
  • 指定文件路徑,並在路徑前添加“r”,表示您要“讀取”音頻文件,例如底部。

我希望這可以幫助您或至少其他人遇到此錯誤。

祝你好運。

來源

例如,在與音頻文件相同的文件夾中運行:

from pydub import AudioSegment
import os

os.chmod('audio2.mp3', 777)  #You might not need this

sound = AudioSegment.from_mp3(r"D:/audio.mp3")
#Put the 'r' in front of the filepath, to 'read' the audio file.
sound.export("audio.wav", format="wav")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM