How to select an object based on audio input?

I have a room full of objects. Each object has an audio file attached to it. Now I want to build a general script which randomly selects one of the objects and plays the respective audio. The player should then search for the right object and select it. How do I access different audio files from a script attached to the main camera?

Please help! thx

A quick way would be to attach a script to each object that is able to store a audio clip and return it when needed.

public class AudioObject : MonoBehaviour
{
	public AudioClip soundClip;
}

Next, our Manager will have a list of all the objects that can play sounds.

public class Manager : MonoBehaviour 
{    
	public List<AudioObject> audioObjects = new List<AudioObject>();
}

Next, our Manager will call a random object and get the audio and play the objects song.

public void PlayRandomAudio()
	{
		int randomInt = Random.Range(0, audioObjects.Count);
    
		GetComponent<AudioSource>().clip = selectedObject.soundClip;
		GetComponent<AudioSource>().Play();
	}

But, now there is a problem, how do we know which object have been randomly chosen? No worries, we can just cache a copy of the selected AudioObject. My new updated Manager and PlayRandomAudio function.

public class Manager : MonoBehaviour 
{
	private AudioObject selectedObject;

	public List<AudioObject> audioObjects = new List<AudioObject>();

	public void PlayRandomAudio()
	{
		int randomInt = Random.Range(0, audioObjects.Count);

		selectedObject = audioObjects[randomInt];

		GetComponent<AudioSource>().clip = selectedObject.soundClip;
		GetComponent<AudioSource>().Play();
	}
}

And to check, all we need to do is just do a comparison.

public void CheckChosenObject(AudioObject obj)
	{
		if(selectedObject == obj)
		{
			// True
			Debug.Log("Correct");
		}
		else
		{
			// False
			Debug.Log("Wrong");
		}
	}

Hopefully it helps. All the best.