- Home /
Microphone Input Latency Android
Hi, I'm trying to implement a game where a character moves up or down depending on the sensitivity or loudness of the player speaking. When I try it on PC it work wells without lag but when I try it with mobile devices for example Android I get latency issues. I already changed the DSP Buffer Size so the game runs with "Best Latency", but that has not effect on the mobile aspect. Has anyone run into this issue or found a work-around, or know any tutorials for microphone games?
Here is my code:
void Awake()
{
_audioSource = GetComponent<AudioSource>();
_audioSource.clip = Microphone.Start(null, true, 10, 44100);
_audioSource.loop = true; // Set the AudioClip to loop
//_audioSource.mute = true;// ERROR
while (!(Microphone.GetPosition(null) > 0))
{
} // Wait until the recording has started
_audioSource.Play();
}
// Start is called before the first frame update
void Start()
{
playerRB = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
loudness = GetAverageVolume() * sensitivity;
if (loudness > 1)
{
GameObject.Find("Microphone").GetComponent<SpriteRenderer>().color = new Color(255, 255, 255, 100);
}
else
{
GameObject.Find("Microphone").GetComponent<SpriteRenderer>().color = new Color(255, 255, 255, 0);
}
}
float GetAverageVolume()
{
float[] data = new float[256];
float a = 0;
_audioSource.GetOutputData(data, 0);
foreach (float s in data)
{
a += Mathf.Abs(s);
}
return a / 256;
}
void FixedUpdate()
{
moveSpeed = loudness * 1f;
playerRB.velocity = transform.up * moveSpeed;
}
Answer by wsdfz · Aug 07, 2019 at 03:07 AM
also has this problem when playing microphone input in real time on android platform, have you fixed this problem?
this post is about this problem: https://support.unity3d.com/hc/en-us/articles/206485253-How-do-I-get-Unity-to-playback-a-Microphone-input-in-real-time-
but no help for me.
Your answer
Follow this Question
Related Questions
How do I achieve the smallest amount of latency between Audio Input and Audio Output? 0 Answers
Major Latency on Android when using Microphone 1 Answer
Why does Microphone.GetDeviceCaps lie? 0 Answers
Sound Quality and Lag when using WebRTC with Unity on LG Phones 0 Answers
!RIDICULOUS! Audio Latency - Android 3 Answers