This thread is from 2012 and uses:
AudioClip audioClip = new AudioClip();
That’s not allowed, so I’m guessing it’s outdated.
public float[] data;
string device;
AudioClip audioClip;
AudioSource audioSource;
void Start()
{
data = new float[128];
StartMicrophone();
device = Microphone.devices[0];
audioClip = Microphone.Start(device, true, 1, 44100);
//audioSource = GetComponent<AudioSource>();
//audioSource.clip = Microphone.Start(device, true, 1, 44100);
//audioSource.Play();
}
void Update()
{
int position = Microphone.GetPosition(null);
_ = audioClip.GetData(data, position);
//_ = audioSource.clip.GetData(data, position);
}
I can see the data changing in the inspector, but only at the beginning of the recording. If I set the lengthSec to 3, it updates every 3 seconds.
even If I use the clip with an audio source, I can hear what’s recorded in almost realtime, but the GetData only updates on the start of the recording.
I only want to trigger an event when the overall volume exceeds a certain threshold, not use the actual recording for anything.