Volume control based on analog inputs

I am trying to play a wav file on an Arduino and control the volume of wav file based on analog inputs.

Specifically, my Arduino is connected to a microphone, wave shield, and speaker. The microphone acquires analog inputs based on the volume of the environment. I am trying to play audio files and adjust the output volume based on the analog measurements obtained from the microphone/ the environment.

So far I have tried to use the tone command (which would work if I didn't need to play audio files), incorporate a transistor, and utilized different configurations to the circuitry but I have not been able to control the volume of the wav file based on the analog inputs.

Any help or ideas would be overly welcomed.

A question - since it plays sound, and is controlled by sound, how do you prevent it from responding to itself? Have you looked for a volume control function in your wave shield library? What kind of microphone or microphone module do you have?

jazbluegreen: Any help or ideas would be overly welcomed.

This VU Meter code is able to use the volume to increase the number of LEDs that are shown.

http://www.instructables.com/id/Neo-Pixel-Arduino-Vu-Meter/?ALLSTEPS

Perhaps you will be able to use some of that code in your project. I agree with aarg though, the volume of the sounds being played will create a feedback loop of increasing volume.

An arduino wouldn't be powerful enough to do active noise cancelling either.