Shadowphile You don't need a function that runs every frame for that. Simply tween the volume on the AudioStreamPlayer node or on amplify effect added to a bus.
In general, always look for ways to remove per frame processing from script and delegate it to engine's internal code. Tweens are an excellent way to do so in many cases.