Problem with audio

I have a GameObject to which I attached an Audio Source Component. In the script attached to the GameObject I wanted to add the following lines:

public AudioClip[] sound;

public void play_sound(int n){
   audio.clip = sound[n];
   audio.Play()
}

So whenever I want to play a sound I just call the play_sound function. Problem is that audio is not seen in the function for some reason. Why is this happening?

The “audio” variable has been deprecated. Replace every “audio” with GetComponent <AudioSource>() to fix your error.