I just started using the new Microphone class in 3.5 and noticed a delay between the audio from the audio source its playing though and the actual audio being inputted from the microphone. Restarting Unity or my computer all together seems to help sometimes but the delay usually returns after a few minutes of use. Has anyone else had this issue?
the delay you are talking about it’s actually comon and dependent on your sound card, there are several forms of audio processing such as asio , wmm and wmd type drivers. i for example in my case have 3 sound drivers two are internal and a external audio interface that’s mainly used for recording. if i use my defaulp pc sound card i will hear a huge delay even just using the mic by itself meaning not even using unity itself. nof my othe sound card have the ability to be able to switch and change the delay of the sound. technically it’s actually called latency.
you can alway try downloading “asio4all” this is a software that cheats your driver to try to give it some for of a boost of latency thus letting you being able to change it for some change.
then again this might not be the correct answer after all. i still haven’t messed much with the microfone class in unity. i wonder if we are going to be able to do voip like talking through the network. it would be sick.
Ahh I hadn’t thought about trying some different drivers. I’ll try an ASIO driver, see if it makes a difference, then repost.
I downloaded the ASIO driver and then realized I had no idea how to assign it to the device. In audio software you typically choose a driver to use, but I’m not sure if/how you can do that in Unity.
Does anyone else have any suggestions for reducing the microphone latency?
bump
Have you looked at Unity - Scripting API: Microphone.GetPosition ?
**Microphone.GetPosition **
static function GetPosition (deviceName : String) : int
Parameters
deviceName the name of the device. Passing null or an empty string will pick the default device. Get device names with Microphone.devices Description
Get the position in samples of the recording.
You can use this to control latency. If you want a 30ms latency, poll getRecordPosition() until 30ms (in samples) has gone and then start the audio.
====================================
I’m doing real time pitch detection using the mic and it is working well, but I am currently getting 80 - 90 ms hiccups when it hits the loop time.
This does not seem to be a problem on Desktop due to CPU horsepower, but I’m trying to hunt this down at the moment as it is a killer for synchronization on the iPad.
I’m not sure how delaying the audio source playing will help me in my situation. I need the audio clip generated from the microphone class to be synced (at least closely) with the user’s speech.
Maybe a better description of what I’m trying to do would help: I’m analyzing sample data from the microphone class to get amplitude which will control the mouth of a character being open or closed; basically a simple mouth flapper. I’ve got the volume detection working pretty well and got it linked to my character, but there is a delay between speech into the microphone and the audio clip generated from the microphone class. The delay exists with or without an analysis running on the clip so I know its not coming from there. I’m using the code below (from the docs) to start the Microphone recording and playing.
audio.clip = Microphone.Start(Microphone.devices[0], true, 1, AudioSettings.outputSampleRate);
audio.Play();
Unless I’m not understanding correctly, adding a delay between starting the recording and playing it from the source is only going to add more delay. In any case, I did it anyway with a delay of few different values (varying from 0.03 seconds up to 3) and it did not help. Did you have/resolve this issue?
My problem was simple, I forgot to loop the audiosource…doh. Recreating it every time was the cause of the spiking.
Apart from that I’m not getting noticeable delay on desktop. I have slight processing delay on iPad2, but I think that is more related to the pitch detection processing.