- Home /
Question by
chetan_dabhi · Dec 26, 2016 at 09:21 PM ·
microphonerecordingvoice
Recording cannot proper play in unity?
I am making an application like talking tom in unity using following code, But I am facing a problem. If I record my voice by using Headphones, It repeats my voice properly. But It doesn't repeat my voice properly when I record it without using headphones. I can't get what is going wrong with this code.
#pragma strict
var audioSource : AudioSource;
var power : float;
private var samples : float[];
private var audioClip : AudioClip;
function Start()
{
Screen.sleepTimeout = SleepTimeout.NeverSleep;
audioClip = Microphone.Start("", true, 1, 44100);
audioSource.clip = AudioClip.Create("", 44100, 1, 44100, false, false);
audioSource.Play();
samples = new float[audioClip.samples * audioClip.channels];
}
function Update()
{
audioClip.GetData(samples, 0);
for (var i = 0; i < samples.length; i++)
{
samples[i] *= power;
}
audioSource.clip.SetData(samples, 0);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612103319im_/https://answers.unity.com/themes/thub/images/avi.jpg)