You have to get all the file names in your directory and then iterate for all file names.
You can use os
module to get list of all the files in the current directory.
from pydub import AudioSegment
from pydub.utils import make_chunks
import os
def process_sudio(file_name):
myaudio = AudioSegment.from_file(file_name, "wav")
chunk_length_ms = 8000 # pydub calculates in millisec
chunks = make_chunks(myaudio,chunk_length_ms) #Make chunks of one sec
for i, chunk in enumerate(chunks):
chunk_name = './chunked/' + file_name + "_{0}.wav".format(i)
print ("exporting", chunk_name)
chunk.export(chunk_name, format="wav")
all_file_names = os.listdir()
try:
os.makedirs('chunked') # creating a folder named chunked
except:
pass
for each_file in all_file_names:
if ('.wav' in each_file):
process_sudio(each_file)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…