from pydub import AudioSegment from pydub.utils import make_chunks from scipy.fftpack import fft from scipy.io import wavfile # get the api from scipy import arange from python_speech_features import mfcc from python_speech_features import delta from python_speech_features import logfbank import numpy as np import glob import os import csv from pydub import AudioSegment, scipy_effects myaudio = AudioSegment.from_file("out.wav" , "wav") chunk_length_ms = 2000 # pydub calculates in millisec chunks = make_chunks(myaudio, chunk_length_ms) #Make chunks of one sec csvfile = open("output.csv", "w") writer = csv.writer(csvfile, delimiter=',') #Export all of the individual chunks as wav files for i, chunk in enumerate(chunks): song = chunk.set_channels(1) y = song.get_array_of_samples() y = np.array(y) fs = song.frame_rate Ts = 1.0/fs t = arange(0,1,Ts) n = len(y) k = arange(n) T = n/fs # where fs is the sampling frequency frqLabel = k/T frq = frqLabel[range(n/2)] frq = frq[:6000] Y = fft(y)/n # calculate fourier transform (complex numbers list) Y = Y[range(n/2)] # you only need half of the fft list (real signal symmetry) Y = Y[:6000] writer.writerow(abs(Y[::2])) csvfile.close()