0
\$\begingroup\$

I'm working on a mobile app inside Unity, in which I need to input and repeat microphone input almost immediately..

I've worked it out and it works great when I play it from within the Unity Editor. I get some very strange behavior though when I try it from my Android phone (Galaxy Note 3)..

So I decided to run some tests and noticed quite different behavior..

Using this sample code:

using UnityEngine;
using System.Collections;

public class testingMicScript : MonoBehaviour {

    void Start () {
        audio.loop = true;
        audio.clip = Microphone.Start (null,true,10,44100);
        while(!(Microphone.GetPosition(null)>0)){}
        audio.Play ();
    }
}

and playing it from withing the Editor it works great, I speak and hear myself back after a few milliseconds. I compile the app and run it from my phone and when I speak I get a very strange echo which goes on until the sound is completely distorted and I get a strange hiss, until audio is completely muted..

Why is that? Is there any particular setting I should go through? Or do I have to change something in my code?

\$\endgroup\$
  • 1
    \$\begingroup\$ How are you listening to the audio on your computer versus your phone? If you are hearing an echo, it could be from feedback from your speakers being picked up from the phones mic. Have you tried using headphones? \$\endgroup\$ – BrianGameDev Feb 13 '15 at 3:16
1
\$\begingroup\$

In case anyone else is having this issue, Im working on the same kind of app but Iam also muting the recorded feedback using an audio mixer and parsing the data to get sound volumes and pitch.

I noticed unity and android are different when it comes to the mic. I had to query the specific device microphone to determine what its max frequency is. The following snippet is a simple method i used to start a microphone

public void BeginListener(int index)
{
    int min = 0;
    int max = 0;

    Microphone.GetDeviceCaps(Microphone.devices[index], out min, out max);


    _AudioSource.clip = Microphone.Start(Microphone.devices[index], true, 2, max);

    while (!(Microphone.GetPosition(Microphone.devices[index]) > 1)) 
    { 
        // Wait until the recording has started
    } 

    _AudioSource.loop = true;
    _AudioSource.Play();
}

I feel this is a good solution to start listeniing on a microphone on device and works with multiple microphones. If anyone else knows of a better way please feel free to correct anything

Thanks!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.