/// <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(); } }
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(); }; }
/// <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()); } }
/// <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(); } }
// 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(); }