简体   繁体   English

从目录中提取所有音频文件,然后将它们放到新文件中。 蟒蛇

[英]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.

相关问题 从一个目录加载所有csv / txt文件并通过python合并它们 - Load all csv/txt files from one directory and merge them via python Python从多个文件中提取查询字符串并放入新文件 - Python extract query string from multiple files and put into new file 修改指定目录(包括子文件夹)中的所有文件并将它们保存在新目录中,同时保留文件夹结构(Python) - Modify all files in specified directory (including subfolders) and saving them in new directory while presevering folder structure (Python) 使用 ffmpeg 和 python 将视频中的所有音频流提取到单独的音频文件中 - Extract all audio streams from video into seperate audio files using ffmpeg and python 从2D python列表中提取唯一元素并将其放入新的2D列表中 - extract unique elements from a 2D python list and put them into a new 2D list Python pandas 将目录中的所有 tsv 文件连接到新文件 - Python pandas concatenate all tsv files from directory to new file python:提取不同列表的项目并将它们放在一组中 - python: extract items of different lists and put them in one set 如何从 .csv 文件中提取值并将它们放入数组中? - How to extract values from .csv files and put them in array? Python将目录中文件的所有功能导入一个名称空间 - Python import all functions from files within a directory into one namespace 使用 Python 将所有文件从一个目录移动到另一个目录 - Moving all files from one directory to another using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM