Elisavet Fakou Elisavet Fakou - 1 year ago 96
JSON Question

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. 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. As you can see I want to keep the name of my audio the same and just add the .json
extension. 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. Can somebody help me?

Answer Source
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')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download