Audio.Mute disable microphone in my Game

public float sensitivity = 1000;
public float loudness = 0;
public Slider thresholdTopSlider;
public Slider thresholdBottomSlider;
public float thresholdTop;
public float thresholdBottom;
public bool clapping = false;

AudioSource _audio;
public float VelocityPerJump = 3;
public AudioClip FlyAudioClip;

// Use this for initialization
void Start () {

if (GetComponent() != null)
{

_audio.mute = true;
_audio = GetComponent();
_audio = GetComponent();
_audio.clip = Microphone.Start(Microphone.devices[0].ToString(), false, 1000, 44100);

while (!(Microphone.GetPosition(Microphone.devices[0]) > 0))
{

_audio.Play();

}
}
}

// Update is called once per frame
void Update () {

thresholdTop = thresholdTopSlider.value;
thresholdBottom = thresholdBottomSlider.value;
loudness = GetAverageVolume() * sensitivity;
if (loudness > thresholdTop && !clapping)
{
clapping = true;
BoostOnYAxis();
}
if (loudness < thresholdBottom)
{
clapping = false;
}
}

float GetAverageVolume() {
float[ ] data = new float[1];
float a = 0;
if (GetComponent() != null)
{
_audio.GetOutputData(data, 0);
}
foreach (float s in data)
{
a += Mathf.Abs(s);
}
return a;
}

void BoostOnYAxis()
{
GetComponent().velocity = new Vector2(0, VelocityPerJump);
if(GetComponent() != null)
{
GetComponent().PlayOneShot(FlyAudioClip);
}
}

Use code tags. Your code is hard to read without them.

In Start I see you are setting mute to true, then replacing the reference to the AudioSource before starting the microphone (which you’re also doing twice for some reason). Depending on what AudioSource _audio was set to before you GetComponent another one, it may not have been the same AudioSource you are muting that you are using for the microphone recording. So I’d start looking at what you are trying to do there first.

hey joe sensored i really appreciate your answer but the problem is that i have mute the audio after audio.play() but it mutes the microphone…i dont know why…tell me i want that player do not listen his voice when he produces his sound…all code work perfect but when i mute the audio then microphone do not respond what player is saying…

my game is like when player makes some voice on mobile then my character jumps…
so i record his voice through microphone…but while testing my game i am hearing my own voice from the game too…that is not what i want…i just want microphone to listen my voice then with out producing any sound jumps the character…which microphone is doing well but with alot of noises and with my own voice

Dear GMSUnity,

May I know if you have found any solution for this issue?
I have a same problem and I couldn’t find any answer for that :frowning:

Hey, When I record Audio with microphone, it also records the InGame Audio THROUGH THE MICROPHONE. I want to avoid this how to do that ?