Extreme quantization of audio
So, you describe what you want to do relatively explicitly:


You care about the amplitude, not the sign of the signal.
you need to detect periods where that doesn't change much.
You want to quantize the result.
You want to Run-Length Encode (RLE) the result


So, to achieve each point:


abssignal = numpy.abs(signal)
Apply a low-pass filter. Simply design one using scipy.signal.
Quantization as ${0,\ldots,N}$: Divide by max(filtered_signal), multiplying by $N$ and then casting to integer (numpy.astype).
Apply RLE