// 停止の初期化 private void CloseVideoSource() { if (!(videoSource == null)) { if (videoSource.IsRunning) { videoSource.SignalToStop(); videoSource.WaitForStop(); videoSource = null; Console.Out.WriteLine("videoSource Disposed"); } } if (!(audioSource == null)) { if (audioSource.IsRunning) { audioSource.SignalToStop(); audioSource.WaitForStop(); } audioSource.Dispose(); audioSource = null; Console.Out.WriteLine("audioSource Disposed"); } finalizeXAudio2(); }
public void Stop() { _stopwatch.Stop(); _recognizer.Recognizing -= OnSpeechRecognized; _recognizer.Recognized -= OnSpeechRecognized; _recognizer.SpeechStartDetected -= OnSpeechStartDetected; _recognizer.Canceled -= OnRecognitionCancelled; _audioCapture.NewFrame -= OnAudioFrameCaptured; _audioCapture.SignalToStop(); _audioCapture.WaitForStop(); _recognizer.StopContinuousRecognitionAsync().Wait(); }
public async void RecordAudioToFile(string _path = "1.wav") { if (_microphone == null) { SetRecorder(); } if (FinishRecord == null) { throw new Exception("FinishRecord function not set!"); } if (_path == null) { throw new ArgumentNullException("Error! Argument path is null!"); } else if (_path != "1.wav") { RecordPath = _path; } Task t = new Task(OnListeningAsync); try { _fileStream = new FileStream(RecordPath, FileMode.OpenOrCreate, FileAccess.Write); _audioSaver = new WaveEncoder(); _audioSaver.Open(_fileStream); IsRecordContinue = true; _microphone.Start(); t.Start(); await t; _microphone.WaitForStop(); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } finally { t.Dispose(); _microphone.Dispose(); _audioSaver?.Close(); _fileStream?.Close(); IsRecordContinue = false; } }
private void doAudioStop() { // Stops both cases if (AudioSource != null) { // If we were recording AudioSource.SignalToStop(); AudioSource.WaitForStop(); } var fileStream = File.Create(filenameAudio); stream.WriteTo(fileStream); fileStream.Close(); // Also zero out the buffers and screen Array.Clear(current, 0, current.Length); }