Example #1
0
        /// <summary>
        /// Starts to stream the input of the current Mic device
        /// </summary>
        public void StartRecording(int sampleLen = 10)
        {
            StopRecording();

            if (!Microphone.IsRecording(CurrentDeviceName))
            {
                Debug.Log("[Mic] " + CurrentDeviceName + " was not started when starting recording, restarting mic.");
                StartMicrophone();
            }

            IsRecording = true;

            SampleDurationMS = sampleLen;

            Sample = new float[AudioEncoding.samplerate / 1000 * SampleDurationMS * AudioClip.channels];

            if (AudioClip)
            {
                StartCoroutine(ReadRawAudio());

                // Make sure we seek before we start reading data
                Microphone.GetPosition(CurrentDeviceName);

                Debug.Log("[Mic] Started recording with " + CurrentDeviceName);
                if (OnStartRecording != null)
                {
                    OnStartRecording.Invoke();
                }
            }
            else
            {
                OnStartRecordingFailed.Invoke();
            }
        }
Example #2
0
        // Records at a specified sample duration in ms
        public virtual void StartRecording(int sampleDurationMS)
        {
            // Stop previous
            if (IsRecording)
            {
                StopRecording();
            }

            // Cannot start
            if (!IsInputAvailable)
            {
                OnStartRecordingFailed.Invoke();
                return;
            }

            // Recording
            IsRecording = true;

            // Available
            _reader = StartCoroutine(ReadRawAudio(sampleDurationMS));
        }
Example #3
0
        // ================================================

        #region RECORDING

        /// <summary>
        /// Starts to stream the input of the current Mic device
        /// </summary>
        public void StartRecording(int sampleLen = 10)
        {
            // Cant start unless available
            if (!IsInputAvailable)
            {
                SafeStartMicrophone();
            }
            // Still unavailable, exit
            if (!IsInputAvailable)
            {
                return;
            }

            // Stop recording if doing so
            StopRecording();

            IsRecording = true;

            SampleDurationMS = sampleLen;

            Sample = new float[AudioEncoding.samplerate / 1000 * SampleDurationMS * AudioClip.channels];

            if (AudioClip)
            {
                StartCoroutine(ReadRawAudio());

                // Make sure we seek before we start reading data
                Microphone.GetPosition(CurrentDeviceName);

                Debug.Log("[Mic] Started recording with " + CurrentDeviceName);
                if (OnStartRecording != null)
                {
                    OnStartRecording.Invoke();
                }
            }
            else
            {
                OnStartRecordingFailed.Invoke();
            }
        }