Пример #1
0
        /// <summary>
        /// Ends the Mic stream.
        /// </summary>
        public void StopRecording()
        {
            if (!IsRecording)
            {
                return;
            }

            IsRecording = false;

            StopCoroutine(ReadRawAudio());

            Debug.Log("[Mic] Stopped recording with " + CurrentDeviceName);
            if (OnStopRecording != null)
            {
                OnStopRecording.Invoke();
            }
        }
Пример #2
0
        private void InitWaveInEvent()
        {
            waveIn.DataAvailable += (s, a) =>
            {
                writer.Write(a.Buffer, 0, a.BytesRecorded);
                if (writer.Position > waveIn.WaveFormat.AverageBytesPerSecond * 30)
                {
                    waveIn.StopRecording();
                }
            };

            waveIn.RecordingStopped += (s, a) =>
            {
                writer?.Dispose();
                writer = null;
                OnStopRecording?.Invoke();
            };
        }
Пример #3
0
        /// <summary>
        /// Recording has stopped.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _recorder_RecordingStopped(object sender, IO.Audio.StoppedEventArgs e)
        {
            // Lock the client
            lock (_syncObject)
            {
                // Get the number of bytes left in the buffer.
                long length = _audioBuffer.Length;

                // Read audio data in the buffer.
                byte[] buffer = new byte[(int)length];
                int    read   = _audioBuffer.Read(buffer, 0, (int)length);

                // Send the header data to the speech server.
                _client.Send(buffer.Take(read).ToArray(), true);

                // Stopped.
                OnStopRecording?.Invoke(this, new EventArgs());
            }
        }
Пример #4
0
        /// <summary>
        /// Ends the Mic stream.
        /// </summary>
        public void StopRecording()
        {
            if (!Microphone.IsRecording(CurrentDeviceName))
            {
                return;
            }

            IsRecording = false;

            Microphone.End(CurrentDeviceName);
            Destroy(AudioClip);
            AudioClip = null;

            StopCoroutine(ReadRawAudio());

            if (OnStopRecording != null)
            {
                OnStopRecording.Invoke();
            }
        }
Пример #5
0
        // Stop recording
        public virtual void StopRecording()
        {
            // Ignore
            if (!IsRecording)
            {
                return;
            }

            // Stop Recording
            IsRecording = false;

            // Stop reading
            if (_reader != null)
            {
                StopCoroutine(_reader);
                _reader = null;
            }

            // Stop recording
            OnStopRecording?.Invoke();
        }