Animating a Bezier Curve to Music
You can easily achieve this with the animation nodes add-on for blender (it's basically like coding but with nodes)
There's even a tutorial on YouTube for exactly what you are looking for!
:)