shivank01
shivank01

Reputation: 1065

Add microphone in unity for Android platform

I want to take audio input in my unity application which I am building for Android platform. The code I have added in Start Function is as follows:

var audio = GetComponent< AudioSource > ();
audio.clip = Microphone.Start("Built-in Microphone", true, 10, 44100);
audio.loop = true;
while (!(Microphone.GetPosition(null) > 0)) { }
audio.Play();

But it is showing the following error:

ArgumentException: Couldn't acquire device ID for device name Built-in Microphone

I'm referring from this post to add microphone. How to resolve this? Also, is there any blog available for doing this end to end?

Upvotes: 1

Views: 3370

Answers (1)

HumanWrites
HumanWrites

Reputation: 945

The error message clearly indicates that it can't find a Microphone device named "Built-in Microphone". So you should probably see what devices it can find.

Try running the following code in the Start method and see what output you get:

foreach (var device in Microphone.devices)
    {
        Debug.Log("Name: " + device);
    }

Once you have a list of the devices, then replace "Built-in Microphone" with the name of your desired device. If "Built-in Microphone" is in the list or you get the same issue with a different device, then you're probably dealing with a permissions issue.

Upvotes: 1

Related Questions