Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Audio.Mute disable microphone in my Game

Discussion in 'Audio & Video' started by GMSUnity, Jan 2, 2018.

?

This is my script which is working fine on android device..The only problem is i am hearing my voice

  1. Audio Source

    3 vote(s)
    100.0%
  2. Chicken Scream Clone

    1 vote(s)
    33.3%
Multiple votes are allowed.
  1. GMSUnity

    GMSUnity

    Joined:
    Apr 25, 2017
    Posts:
    3
    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<AudioSource>() != null)
    {

    _audio.mute = true;
    _audio = GetComponent<AudioSource>();
    _audio = GetComponent<AudioSource>();
    _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<AudioSource>() != null)
    {
    _audio.GetOutputData(data, 0);
    }
    foreach (float s in data)
    {
    a += Mathf.Abs(s);
    }
    return a;
    }

    void BoostOnYAxis()
    {
    GetComponent<Rigidbody2D>().velocity = new Vector2(0, VelocityPerJump);
    if(GetComponent<AudioSource>() != null)
    {
    GetComponent<AudioSource>().PlayOneShot(FlyAudioClip);
    }
    }
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    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.
     
  3. GMSUnity

    GMSUnity

    Joined:
    Apr 25, 2017
    Posts:
    3
    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...
     
  4. GMSUnity

    GMSUnity

    Joined:
    Apr 25, 2017
    Posts:
    3
    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
     
  5. znbmir

    znbmir

    Joined:
    Sep 10, 2018
    Posts:
    4
    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 :(
     
  6. infinity135

    infinity135

    Joined:
    Feb 5, 2018
    Posts:
    17
    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 ?
     
  7. unity_QoPbiZLdsCYp-Q

    unity_QoPbiZLdsCYp-Q

    Joined:
    Oct 5, 2018
    Posts:
    1