Last active
November 16, 2017 02:27
-
-
Save m0o0scar/42cca9fe504fcbb20b623831e0c62243 to your computer and use it in GitHub Desktop.
Unity To Playback A Microphone Input In Real Time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
[RequireComponent(typeof(AudioSource))] | |
public class Microphone : MonoBehaviour { | |
AudioSource source; | |
void Start () { | |
if(Microphone.devices.Length > 0) { | |
int minFreq, maxFreq, freq; | |
Microphone.GetDeviceCaps(null, out minFreq, out maxFreq); | |
freq = Mathf.Min(44100, maxFreq); | |
source = GetComponent<AudioSource>(); | |
source.clip = Microphone.Start(null, true, 5, freq); | |
source.loop = true; | |
while(!(Microphone.GetPosition(null) > 0)){} | |
source.Play(); | |
} | |
else { | |
Debug.Log("No Mic connected!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment