private void ResizeRecording()
 {
     if (recordStarted)
     {
         if (captureType == CaptureType.VOD)
         {
             // add the next second of recorded audio to temp vector
             int     length   = outputSampleRate * Constants.MIC_AUDIO_INTERVAL_SECONDS;
             float[] clipData = new float[length];
             audioSource.clip.GetData(clipData, 0);
             tempRecording.AddRange(clipData);
             Invoke("ResizeRecording", Constants.MIC_AUDIO_INTERVAL_SECONDS);
         }
         else if (captureType == CaptureType.LIVE)
         {
             int     length   = outputSampleRate * Constants.LIVE_VIDEO_SLICE_SECONDS;
             float[] clipData = new float[length];
             audioSource.clip.GetData(clipData, 0);
             AudioClip clip = AudioClip.Create("recorded samples", clipData.Length, 1, outputSampleRate, false);
             clip.SetData(clipData, 0);
             WavEncoder.Save(audioSlicePath, clip);
             FFmpegStreamer.singleton.EnqueueAudioSlice(audioSlicePath);
             // restart
             audioSlicePath = string.Format("{0}{1}.wav",
                                            saveFolderFullPath,
                                            Utils.GetTimestampString());
             Invoke("ResizeRecording", Constants.LIVE_VIDEO_SLICE_SECONDS);
         }
     }
 }
        public bool StopRecord()
        {
#if !UNITY_WEBGL
            if (!recordStarted)
            {
                Debug.LogFormat(LOG_FORMAT, "Microphone record session not start yet!");
                return(false);
            }

            recordStarted = false;

            // stop recording, get length, create a new array of samples
            int length = Microphone.GetPosition(deviceName);

            Microphone.End(deviceName);

            if (captureType == CaptureType.VOD)
            {
                float[] clipData = new float[length];
                audioSource.clip.GetData(clipData, 0);

                // create a larger vector that will have enough space to hold our temporary
                // recording, and the last section of the current recording
                float[] fullClip = new float[clipData.Length + tempRecording.Count];
                for (int i = 0; i < fullClip.Length; i++)
                {
                    // write data all recorded data to fullCLip vector
                    if (i < tempRecording.Count)
                    {
                        fullClip[i] = tempRecording[i];
                    }
                    else
                    {
                        fullClip[i] = clipData[i - tempRecording.Count];
                    }
                }

                AudioClip clip = AudioClip.Create("recorded samples", fullClip.Length, 1, outputSampleRate, false);
                clip.SetData(fullClip, 0);

                WavEncoder.Save(audioSavePath, clip);

                OnComplete(audioSavePath);
            }

            tempRecording.Clear();
            tempRecording = null;

            return(true);
#else
            return(false);
#endif
        }