from sympy.ntheory import factorint
FACTOR_LIMIT = 100

def bestFFTlength(n):
    while max(factorint(n)) >= FACTOR_LIMIT:
        n -= 1
return n
a = np.zeros(166400)
audio_fft = np.fft.fft(a, bestFFTlength(len(a)))
strange numpy fft performance