It's nice to see this sort of thing here. FWIW in computer music parlance this is usually called an envelope follower.
Here's an example of a realtime implementation: https://ccrma.stanford.edu/CCRMA/Courses/220b:1998/220b-98-0...
Here's an example of a realtime implementation: https://ccrma.stanford.edu/CCRMA/Courses/220b:1998/220b-98-0...