从一个目录中提取所有音频文件,并将它们放入一个新的目录中| python

2024-04-28 15:12:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个文件夹,里面有1600个音频文件,我想用essentia提取器提取它们,然后将它们转换成同一目录下另一个文件夹中的.json文件。为此,我使用以下行:

os.system("/usr/local/bin/essentia_streaming_extractor_music 2.mp3 2.mp3.json")

是2.mp3是原始文件,2是我音频文件的id。如您所见,我希望保持音频的名称不变,只需添加.json 扩展。我不知道如何保存每个文件的id,以及需要做什么样的迭代和递归编程来实现这一点。有人能帮帮我吗?在


Tags: 文件目录文件夹idjsonbinosusr
1条回答
网友
1楼 · 发布于 2024-04-28 15:12:12
import os
allfiles = os.listdir('.') # Lists all files in the current directory
for item in allfiles: # iterate over all files in the current directory
    if item.endswith('.mp3'): # Checks if the file is a mp3 file
        os.system('/usr/local/bin/essentia_streaming_extractor_music '+item+' '+item+'.json')

相关问题 更多 >