I would like to take an audio sample and reduce it to a very limited set of numbers, with one value for amplitude and another for length.


Audacity screenshot

I want to find the dimensions of the red boxes, which represent areas of similar sound intensity. Ideally I'd like this as a python list in a format similar to:

[[2,10],[5,3],[2,8], ...]

(where [x,y] = [length,intensity])

During creation I'd like to specify resolution in some way, so I can take one sample and have a list of 100 items or 10 items or whatever.

Being able to specify y resolution would also be useful, so \$intensity can be 1-10 or 1-100 or so on. As I write that I realise that I can probably only specify one of those, if \$intensity is bounded as an integer 1-10 then the number of list items depends on that, I think?

I'm pretty familiar with using python for various things, audio/signal processing is totally out of my area of expertise so I'm a bit lost and any pointers on where to start would be much appreciated.

The context is I'd like to use that list as an input in a FreeCAD or Blender script which will generate various shapes and designs from audio samples, ultimately to be 3D printed.


So, you describe what you want to do relatively explicitly:

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

So, to achieve each point:

  1. abssignal = numpy.abs(signal)
  2. Apply a low-pass filter. Simply design one using scipy.signal.
  3. Quantization as ${0,\ldots,N}$: Divide by max(filtered_signal), multiplying by $N$ and then casting to integer (numpy.astype).
  4. Apply RLE
  • $\begingroup$ Marcus, thank you. That is exactly what I am trying to do and I will try your solution later today. Also thanks for providing only pointers and not working code, leaving me the fun bit to do! $\endgroup$ – mmmat Nov 28 '18 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.