【问题标题】:how can i fix "file not found error " in my code如何在我的代码中修复“找不到文件错误”
【发布时间】:2019-11-05 23:56:24
【问题描述】:

我试图制作一个将普通音频转换为 8d 音频的程序,我从 github https://github.com/TheJoin95/ambisonics-3d-audio/blob/master/init.py 获取了这段代码

from glob import glob
from pydub import AudioSegment
from pydub.generators import WhiteNoise
from math import *
from random import *
import sys

if len(sys.argv) > 2:
    AudioSegment.converter = sys.argv[1] #ffmpeg installation exe dir path
    AudioSegment.ffmpeg = sys.argv[1] #ffmpeg installation exe dir path
    AudioSegment.ffprobe = sys.argv[2] #ffprobe installation exe dir path

def calc_pan(index):
    return cos(radians(index))

#playlist_songs = [AudioSegment.from_mp3(mp3_file) for mp3_file in glob("mp3/*.mp3")]

#first_song = playlist_songs.pop(0)
interval = 0.2 * 1000 # sec
song = AudioSegment.from_mp3('mp3/hellomp.mp3')
song_inverted = song.invert_phase()
song.overlay(song_inverted)

splitted_song = splitted_song_inverted = []
song_start_point = 0

print("split song in part")
while song_start_point+interval < len(song):
    splitted_song.append(song[song_start_point:song_start_point+interval])
    song_start_point += interval

if song_start_point < len(song):
    splitted_song.append(song[song_start_point:])

print("end splitting")
print("total pieces: " + str(len(splitted_song)))

ambisonics_song = splitted_song.pop(0)
pan_index = 0
for piece in splitted_song:
    pan_index += 5
    piece = piece.pan(calc_pan(pan_index))
    ambisonics_song = ambisonics_song.append(piece, crossfade=interval/50)


# lets save it!
out_f = open("compiled/everlong.mp3", 'wb')

ambisonics_song.export(out_f, format='mp3')


我希望是 8D 音频,但我遇到了一些错误,我该如何修复它并让我的代码正常工作

警告(来自警告模块):文件 "C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\utils.py", 第 165 行 warn("找不到 ffmpeg 或 avconv - 默认为 ffmpeg,但可能无法工作",RuntimeWarning) RuntimeWarning: 找不到 ffmpeg 或 avconv - 默认为 ffmpeg,但可能无法使用 Traceback(最近 最后调用):文件 "C:/Users/lenovo/AppData/Local/Programs/Python/Python37-32/8dmusic.py", 第 20 行,在 song = AudioSegment.from_mp3('mp3/hellomp.mp3') 文件 "C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\audio_segment.py", 第 716 行,在 from_mp3 中 return cls.from_file(file, 'mp3', parameters=parameters) File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\audio_segment.py", 第 610 行,在 from_file 中 file = _fd_or_path_or_tempfile(file, 'rb', tempfile=False) 文件 "C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pydub\utils.py", 第 57 行,在 _fd_or_path_or_tempfile fd = open(fd, mode=mode) FileNotFoundError: [Errno 2] No such file or directory: 'mp3/hellomp.mp3'

【问题讨论】:

  • 您需要在您的机器上安装 ffmpeg 或 avconv 程序才能运行
  • 我的路径100%正确,我检查了两次

标签: python audio mp3


【解决方案1】:

我认为您需要像绝对路径这样的文件路径。 mp3/hellomp.mp3 看起来像一个相对路径,但您应该检查包含源代码的当前目录路径。这个词加上'../'或'./'表示合理。

【讨论】:

    【解决方案2】:

    回溯给你答案“[Errno 2] No such file or directory: 'mp3/hellomp.mp3'

    python 音频 mp3"。

    程序正在尝试在不存在的文件夹中查找文件。检查文件夹是否存在,然后检查路径是否 100% 正确

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-02
      • 2019-12-04
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      相关资源
      最近更新 更多