我试图制作一个将普通音频转换为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行 警告(“找不到ffmpeg或avconv-默认为ffmpeg,但可能不起作用”,RuntimeWarning)RuntimeWarning:找不到ffmpeg或 avconv-默认为ffmpeg,但可能无法使用Traceback(最新 最后调用):文件 “ C:/Users/lenovo/AppData/Local/Programs/Python/Python37-32/8dmusic.py”, 第20行,在 歌曲= 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中 返回cls.from_file(文件,“ mp3”,参数=参数)文件“ 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”, _fd_or_path_or_tempfile中的第57行 fd = open(fd,mode = mode)FileNotFoundError:[错误2]没有这样的文件或目录:'mp3 / hellomp.mp3'
答案 0 :(得分:0)
回溯给您答案“ [Errno 2]没有这样的文件或目录:'mp3 / hellomp.mp3'
python音频mp3”。
程序正在尝试在不存在的文件夹中查找文件。检查文件夹是否存在,然后检查路径是否正确100%
答案 1 :(得分:0)
我认为您需要像绝对路径这样的文件路径。
mp3/hellomp.mp3
看起来像一个相对路径,但是您应该检查当前目录中包含源代码的路径。该词在合理范围内添加了“ ../”或“ ./”。