简体   繁体   中英

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?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM