/// <summary> /// Start the record. /// </summary> /// <param name="audio">Audio source (Unity).</param> /// <param name="microphone">Microphone.</param> /// <param name="seconds">Record length in seconds.</param> public static void Start(AudioSource audio, FlapiMicrophone microphone, int seconds) { sourceIsFile = false; _sampleRate = microphone.maxSamplingRate; // Check sample rate. // A zero value indicates that the microphone can support any frequency. if (_sampleRate == 0) _sampleRate = DEFAULT_SAMPLE_RATE; tickMinDelta = _sampleRate / TICKS_PER_SEC_MAX; tickSamples = (int)(TICK_LENGTH / 2 * _sampleRate); _ticks = new bool[seconds * _sampleRate]; _buffer = new float[seconds * _sampleRate]; //StartAudioFile (audio, "blowshort.wav"); StartMicrophone (audio, microphone, seconds); Debug.Log (microphone.name); // Start the process, no playback. audio.Play (); audio.volume = 0.0f; }
//------------------------------------------------------------------------- private static void StartMicrophone(AudioSource audio, FlapiMicrophone microphone, int seconds) { sourceIsFile = false; RequireAuthorization (); string device = microphone.name; audio.clip = UnityEngine.Microphone.Start (device, false, seconds, _sampleRate); // Simple trick to ensure the microphone and the audio card are synchronized. // Avoid laggy records. while (!(UnityEngine.Microphone.GetPosition(device) > 0)) { } ; }
public static FlapiMicrophone[] GetMicrophones() { FlapiMicrophone[] microphones; string[] devices; int devicesAvailables; int deviceMinFrequency; int deviceMaxFrequency; devices = UnityEngine.Microphone.devices; devicesAvailables = devices.Length; microphones = new FlapiMicrophone[devicesAvailables]; for (int i = 0; i < devicesAvailables; i++) { UnityEngine.Microphone.GetDeviceCaps (devices [i], out deviceMinFrequency, out deviceMaxFrequency); microphones [i].name = devices [i]; microphones [i].minSamplingRate = deviceMinFrequency; microphones [i].maxSamplingRate = deviceMaxFrequency; } return microphones; }