Errno2没有这样的文件或目录



我一直在尝试在python脚本中运行sox,但它不能输出文件并给我[errno2]

def AudioToSpectrogram(self, files, pixel_per_sec, height, width):
file_name = ("tmp_{}.png").format(random.randint(0, 100000))
command  = "sox -V0 {} -n remix 1 rate 10k spectrogram -y {} -x {} -X {} -m -r -o {}".format(files, height, width, pixel_per_sex, file_name)
p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
Output, errors = p.communicate()
If errors:
Print(errors)
Image = Image.open(file_name)
Os.remove(file_name)
Return np.array(image)

这是它给出的错误

Exception: [errno2] No such file or Directory: 'tmp_47483.png' 

我希望你能给我一些指点,因为我在这个领域还是个新手,提前感谢!

假设实际上正在创建tmp_47483.png,问题可能是命令将文件放置在另一个文件夹中,Python无法在当前工作目录中找到它。

# manually set the full path (make sure the backslashes are escaped by putting two each)
file_name = f"C:\Full\Path\To\File\tmp_{random.randint(0, 100000}.png"
# use the os module to join the path
base_dir = "C:\Full\Path\To\File"
file_name = os.path.join(base_dir, f"tmp_{random.randint(0, 100000}.png")
# if you want it to appear in the same folder as your script:
CWD = os.path.dirname(os.path.realpath(__file__))    # mostly fool-proof way of getting a script's Current Working Directory
file_name = os.path.join(CWD, f"tmp_{random.randint(0, 100000}.png")

试试这些,看看它们是否有用。如果不是,请确保command实际工作并在某处输出文件。

相关内容

  • 没有找到相关文章