Hi there, I am quite new to playing with Microphone audio on Unity.
For a project I require to create an Echo Effect to the Microphone audio on Unity.
First of all I want to create a Push to Talk kind of Option, so when I press “S” I start getting audio input and as soon as I leave that button it stops.
While this audio is being input, I want to process it with an Echo algorithm and generate a real time effect.
I understand that for this I should use the Microphone.Start and get my data, but somehow I am unable to even understand how the recording process works in unity.
As given,
Start(deviceName: string, loop: bool, lengthSec: int, frequency: int):
What is the Loop parameter here for?
In the example given,
// Start recording with built-in Microphone and play the recorded audio right away
function Start() {
audio.clip = Microphone.Start("Built-in Microphone", true, 10, 44100);
audio.Play();
}
It does not play the audio right away! Isnt this being called just once on start, then how will it play all the data right away?
My major task is to get the real time data samples, and play them immediately, and then apply some kind of delay and fade multiplier to get the ECHO effect.
Please help me out! Thanks!
EDIT : So I have made some progress or a hack more to say,
If I add a delay before I call the AudioSource.Play(), such as by counting down a timer for about 0.5s I am getting the output. Also I call this Play from my Update(). But in the last 4 seconds of the sound, I get a really bad stutter! Can anyone explain that?
using UnityEngine;
using System.Collections;
public class EchoTest : MonoBehaviour {
public AudioSource tempSource;
AudioClip tempClip;
// Use this for initialization
void Start () {
string deviceName = "";
foreach (string device in Microphone.devices)
deviceName = device;
tempClip = Microphone.Start(deviceName, false,15, 44100);
tempSource = this.GetComponent<AudioSource>();
tempSource.clip = tempClip;
}
bool a = true;
float timer = 0.1f;
// Update is called once per frame
void Update () {
if (timer > 0)
timer = timer - Time.deltaTime;
else if (timer <= 0&&a)
{
tempSource.playOnAwake = false;
tempSource.loop = false;
tempSource.Play();
a = false;
}
}
AudioClip createdelay(AudioClip temp)
{
if (timer > 0)
timer = timer - Time.deltaTime;
if (timer <= 0)
return temp;
return null;
}
}
Have you tried this? [Audio Echo filter][1] Its a PRO effect though. [1]: http://docs.unity3d.com/Documentation/ScriptReference/AudioEchoFilter.html
– StarwalkerHi Starwalker, ty for your response. Yes, I did but for my project I need some further processing on the sounds, hence I need further control. My real problem is to get this audio coming back to me real time. I have made some progress, Ill modify my question..
– jschhabria
– Starwalkerelse if (timer <= 0&&a)A <= (B and C) When your timer moves closer to 0, unity gets precision issues when you compare to float, try this:else if ((timer < 0) && a), ( A < B) and C, force A' and C comparison.I was trying to see why you are having the last four seconds be garbled. I'm not quite sure, but I see that you are setting it to record for 15 seconds. Maybe if you set that to a longer time, it will be able to catch that part of the recording.
– AndyMartin458So I was able to prevent the stutter at the end, by setting the loop attribute to true, such as,
– jschhabriatempClip = Microphone.Start(deviceName, true,15, 44100);I wonder why that stops the stutter..Still working on this.