[英]Extract all audio files from a directory and put them to a new one | python
I have a folder with 1600 audio files inside which I want to extract them using the essentia extractor and changing them into a .json file in another folder in the same directory. 我有一个包含1600个音频文件的文件夹,我要在其中使用essentia提取器提取它们,并将它们更改为同一目录中另一个文件夹中的.json文件。 To do this I use this line: 为此,我使用以下行:
os.system("/usr/local/bin/essentia_streaming_extractor_music 2.mp3 2.mp3.json")
were 2.mp3 is the original file and 2 is the id of my audio file. 2.mp3是原始文件,2是我的音频文件的ID。 As you can see I want to keep the name of my audio the same and just add the .json extension. 如您所见,我想保持音频名称不变,只是添加.json扩展名。 I don't know though how to keep the id of each file and what kind of iteration and recursive programming I need to do to make this happen. 我不知道如何保留每个文件的ID,以及我需要做哪种迭代和递归编程。 Can somebody help me? 有人可以帮我吗?
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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.