How to make the player not hear a specific audio source
I made a speech recognition script that I put on my player that activates a mouth animation object and deactivates the non moving mouth when the player speaks at a certain volume into their microphone. It works but the only problem is that the player speaks into the microphone but then the game plays their voice back to them. How do I make the script work while the player doesn't hear their own voice? Like, is their some way for the player not to hear a certain audio source even though it's playing and the audio is up? Here's my code:
{
public float sensitivity = 100;
public float loudness = 0;
AudioSource _audio;
public GameObject Normal_Mouth;
public GameObject Talk_Mouth;
public float LoudnessSet;
// Start is called before the first frame update
void Start()
{
_audio = GetComponent<AudioSource>();
_audio.clip = Microphone.Start(null, true, 10, 44100);
_audio.loop = true;
_audio.mute = false;
while (!(Microphone.GetPosition(null) > 0)) { }
_audio.Play();
}
// Update is called once per frame
void Update()
{
loudness = GetAveragedVolume() * sensitivity;
if (loudness > LoudnessSet)
{
Normal_Mouth.SetActive(false);
Talk_Mouth.SetActive(true);
}
if (loudness < LoudnessSet)
{
Normal_Mouth.SetActive(true);
Talk_Mouth.SetActive(false);
}
}
//
float GetAveragedVolume()
{
float[] data = new float[256];
float a = 0;
_audio.GetOutputData(data, 0);
foreach(float s in data)
{
a += Mathf.Abs(s);
}
return a / 256;
}
}
Your answer
Follow this Question
Related Questions
How to stop current audio before another audio starts? 0 Answers
Second AudioClip won't play 0 Answers
Listening to Sound Card Output 0 Answers
How do I get the parent from a AudioMixerGroup Object 2 Answers
HOw to get 3D audio with the Vive? 0 Answers