Example #1
0
        private void recordDevice_RecordingStopped(object sender, StoppedEventArgs e)
        {
            try
            {
                Logger.WriteDebug(MethodBase.GetCurrentMethod(), "recordDevice -> Stopped");

                if (_einsatz != null)
                {
                    //Raise Event
                    EinsatzFinished.RaiseEvent(this, new EinsatzFinishedEventArgs(_einsatz));
                    //Reset Einsatz
                    _einsatz = null;
                    Logger.WriteDebug(MethodBase.GetCurrentMethod(), "Reset einsatz -> finish");
                }

                _recordMp3Writer?.Dispose();
                _recordWaveStream?.Dispose();
            }
            catch (Exception ex)
            {
                ExceptionOccured.RaiseEvent(this, new ExceptionEventArgs
                {
                    Methode = MethodBase.GetCurrentMethod(),
                    Error   = ex
                });
            }
            finally
            {
                _recordState      = RecordState.Stopped;
                _recordWaveStream = null;
                _recordMp3Writer  = null;
            }
        }
Example #2
0
        static void OnRecordingStopped(object sender, StoppedEventArgs e)
        {
            requestSender.CloseConnection();

            waveSource?.Dispose();
            waveSource = null;
        }
Example #3
0
 public void Dispose()
 {
     waveIn.DataAvailable -= OnAudioCaptured;
     waveIn.StopRecording();
     waveIn.Dispose();
     waveIn?.Dispose();
 }
Example #4
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            waveIn?.Dispose();
            writer?.Dispose();
        }
Example #5
0
        private void OnRecordingStopped(object sender, StoppedEventArgs e)
        {
            writer?.Dispose();
            writer = null;

            waveIn?.Dispose();
            waveIn = null;
        }
Example #6
0
 public void Dispose()
 {
     WaveIn.DataAvailable -= OnAudioCaptured;
     WaveIn.StopRecording();
     WaveIn.Dispose();
     WaveIn?.Dispose();
     AudioSender?.Dispose();
 }
Example #7
0
 private void Clear()
 {
     WaveIn?.Dispose();
     Writer?.Close();
     Writer?.Dispose();
     DeleteTestFile();
     if (Player != null)
     {
         Player.Stop();
         Player.Dispose();
     }
 }
    /// <summary>
    /// Callback executed when the recording is stopped
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void RecordingStopped(object sender, StoppedEventArgs e)
    {
        _waveSource.DataAvailable    -= DataAvailable;
        _waveSource.RecordingStopped -= RecordingStopped;
        _waveSource?.Dispose();
        _waveWriter?.Dispose();

        /*Convert the recorded file to MP3*/
        ConvertWaveToMp3(_tempFilename, _filename);
        /*Send notification that the recording is complete*/
        RecordingFinished?.Invoke(this, null);
    }
 private void Execute(ISender client, GetMicrophone message)
 {
     if (message.CreateNew)
     {
         _isStarted = false;
         _audioDevice?.Dispose();
         OnReport("Audio streaming started");
     }
     if (message.Destroy)
     {
         Destroy();
         OnReport("Audio streaming stopped");
         return;
     }
     if (_client == null)
     {
         _client = client;
     }
     if (!_isStarted)
     {
         try
         {
             _deviceID    = message.DeviceIndex;
             _audioDevice = new WaveInEvent
             {
                 DeviceNumber = _deviceID,
                 WaveFormat   = new WaveFormat(message.Bitrate, WaveIn.GetCapabilities(_deviceID).Channels)
             };
             _audioDevice.BufferMilliseconds = 50;
             _audioDevice.DataAvailable     += sourcestream_DataAvailable;
             _audioDevice.StartRecording();
             _isStarted = true;
         }
         catch (Exception)
         {
             //do nothing at the moment
         }
     }
 }
Example #10
0
        public void Dispose()
        {
            if (!disposed)
            {
                _udp.Dispose();
                _ws.Dispose();
                _audioIn.Dispose();
                _audioOut.Dispose();
                tokenSource.Dispose();

                disposed = true;
            }
        }
 /// <summary>
 /// ボイスチェンジャーの停止
 /// </summary>
 private void StopRecording()
 {
     waveIn?.StopRecording();
     waveIn?.Dispose();
     waveIn = null;
     wavPlayer?.Stop();
     wavPlayer?.Dispose();
     wavPlayer = null;
     waveWriter_In?.Close();
     waveWriter_In = null;
     waveWriter_Out?.Close();
     waveWriter_Out = null;
 }
Example #12
0
        public void Stop()
        {
            if (!Started)
            {
                throw new Exception("Input not started");
            }

            Started = false;

            waveIn.StopRecording();
            waveIn.Dispose();
            waveIn = null;
        }
Example #13
0
        public void StartRecording(string outputFilePath)
        {
            this.outputFilePath     = outputFilePath;
            this.LoopbackFilePath   = Path.Combine(Path.GetDirectoryName(this.outputFilePath), Path.GetFileNameWithoutExtension(this.outputFilePath) + "_i" + Path.GetExtension(this.outputFilePath));
            this.MicrophoneFilePath = Path.Combine(Path.GetDirectoryName(this.outputFilePath), Path.GetFileNameWithoutExtension(this.outputFilePath) + "_m" + Path.GetExtension(this.outputFilePath));
            // Redefine the capturer instance with a new instance of the LoopbackCapture class
            this.LoopbackCapture = new WasapiLoopbackCapture();
            this.SilencePlayer   = new WasapiOut(WasapiLoopbackCapture.GetDefaultLoopbackCaptureDevice(), AudioClientShareMode.Shared, false, 100);
            this.SilencePlayer.Init(new SilenceProvider(LoopbackCapture.WaveFormat));
            this.SilencePlayer.Play();

            // Redefine the audio writer instance with the given configuration
            this.LoopbackWriter = new WaveFileWriter(this.LoopbackFilePath, LoopbackCapture.WaveFormat);

            // When the capturer receives audio, start writing the buffer into the mentioned file
            this.LoopbackCapture.DataAvailable += (s, a) =>
            {
                this.LoopbackWriter.Write(a.Buffer, 0, a.BytesRecorded);
            };

            // When the Capturer Stops
            this.LoopbackCapture.RecordingStopped += (s, a) =>
            {
                this.LoopbackWriter.Close();
                this.LoopbackWriter.Dispose();
                this.LoopbackWriter = null;
                this.SilencePlayer.Stop();
                LoopbackCapture.Dispose();
            };

            // Start recording !
            this.LoopbackCapture.StartRecording();

            this.MicrophoneCapture = new WaveInEvent();
            this.MicrophoneCapture.DeviceNumber       = 0;
            this.MicrophoneCapture.WaveFormat         = LoopbackCapture.WaveFormat;
            this.MicrophoneCapture.BufferMilliseconds = 50;
            this.MicrophoneWriter = new WaveFileWriter(this.MicrophoneFilePath, LoopbackCapture.WaveFormat);
            this.MicrophoneCapture.DataAvailable += (s, a) =>
            {
                this.MicrophoneWriter.Write(a.Buffer, 0, a.BytesRecorded);
            };
            this.MicrophoneCapture.RecordingStopped += (s, a) =>
            {
                this.MicrophoneWriter.Close();
                this.MicrophoneWriter.Dispose();
                this.MicrophoneWriter = null;
                MicrophoneCapture.Dispose();
            };
            MicrophoneCapture.StartRecording();
        }
Example #14
0
 private void WaveSource_RecordingStopped(object sender, StoppedEventArgs e)
 {
     if (WaveSource == null)
     {
         return;
     }
     WaveSource.Dispose();
     WaveSource = null;
     Application.Current.Dispatcher.BeginInvoke(new Action(delegate
     {
         var w = (MainWindow)Application.Current.MainWindow;
         w.levelMeter.Value = 0;
     }));
 }
Example #15
0
 public void stopRecording()
 {
     if (wavWriter != null)
     {
         wavWriter.Dispose();
         wavWriter = null;
     }
     if (waveInEvent != null)
     {
         waveInEvent.StopRecording();
         waveInEvent.Dispose();
         waveInEvent = null;
     }
 }
Example #16
0
        private void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
        {
            if (waveSource != null)
            {
                waveSource.Dispose();
                waveSource = null;
            }

            if (waveFile != null)
            {
                //waveFile.Dispose();
                waveFile = null;
            }
        }
Example #17
0
        private void RecordingStopped(WaveInEvent wS, WaveFileWriter wF)
        {
            if (wS != null)
            {
                wS.Dispose();
                wS = null;
            }

            if (wF != null)
            {
                wF.Dispose();
                wF = null;
            }
        }
Example #18
0
        void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
        {
            if (WaveSource != null)
            {
                WaveSource.Dispose();
                WaveSource = null;
            }

            if (WaveFile != null)
            {
                WaveFile.Dispose();
                WaveFile = null;
            }
        }
Example #19
0
        private void DoneRecord()
        {
            waveOut.Stop();
            waveIn.StopRecording();

            if (waveIn != null)
            {
                waveIn.Dispose();
            }
            if (waveOut != null)
            {
                waveOut.Dispose();
            }
        }
Example #20
0
        public void SetRecordingSettings(int sampleRate, int channels)
        {
            var capabilities     = WaveIn.GetCapabilities(Config.Instance.RecordingDevice.Number);
            var waveSourceFormat = new WaveFormat(sampleRate, channels);

            if (_waveSource != null)
            {
                _waveSource.Dispose();
            }

            _waveSource = new WaveInEvent();
            _waveSource.BufferMilliseconds = 20;
            _waveSource.WaveFormat         = waveSourceFormat;
            _waveSource.DeviceNumber       = Config.Instance.RecordingDevice.Number;
            _waveSource.DataAvailable     += waveSource_DataAvailable;

            _waveSourceProvider = new BufferedWaveProvider(waveSourceFormat);
            _waveSourceProvider.DiscardOnBufferOverflow = true;

            _waveSourceMeter = new MeteringSampleProvider(_waveSourceProvider.ToSampleProvider());
            _waveSourceMeter.StreamVolume += _waveSourceMeter_StreamVolume;

            Debugging.Write(string.Format("Changed recording config to: samplingRate: {0}, channels: {1}", sampleRate, channels));
        }
 public void Stop()
 {
     if (recordingState == RecordingState.Recording)
     {
         recordingState = RecordingState.RequestedStop;
         waveIn.StopRecording();
     }
     if (recordingState == RecordingState.Monitoring)
     {
         recordingState = RecordingState.Stopped;
         waveIn.StopRecording();
         waveIn.Dispose();
         waveIn = null;
     }
 }
Example #22
0
 /// <summary>
 /// Record audio
 /// </summary>
 /// <param name="time">time to record in msec</param>
 public void Record(int time)
 {
     _waveIn = new WaveInEvent();
     _waveIn.DataAvailable    += new EventHandler <WaveInEventArgs>(waveIn_DataAvailable);
     _waveIn.RecordingStopped += new EventHandler <StoppedEventArgs>(waveIn_RecordingStopped);
     _waveIn.StartRecording();
     System.Threading.Thread.Sleep(time);
     _waveIn.StopRecording();
     while (!_writeComplete)
     {
         System.Threading.Thread.Sleep(100);
     }
     _waveIn.Dispose();
     _waveIn = null;
 }
Example #23
0
        public void testFunc()
        {
            // Define Output Path and Create a new WaveInEvent
            var outputFilePath = @"C:\Users\Joe\source\repos\Monotone\Monotone\bin\x64\Debug\audio.wav";
            var waveInEvent    = new WaveInEvent();

            // Prepare the fileWriter
            fileWriter = new WaveFileWriter(outputFilePath, waveInEvent.WaveFormat);

            // Start Recording
            waveInEvent.StartRecording();

            Console.WriteLine("Begin Recording... ");
            Console.WriteLine("Press Any Key to Stop Recording.");

            // NAudio WaveInEvent Event-Based Handeling
            #region NAudio WaveInEvent Event-Based Handeling
            waveInEvent.DataAvailable += (s, a) =>
            {
                fileWriter.Write(a.Buffer, 0, a.BytesRecorded);

                // Force Stop Recording after 30 seconds
                if (fileWriter.Position > waveInEvent.WaveFormat.AverageBytesPerSecond * 30)
                {
                    waveInEvent.StopRecording();
                }
            };

            waveInEvent.RecordingStopped += (s, a) =>
            {
                Console.WriteLine($"Sampling Rate: {waveInEvent.WaveFormat.SampleRate}");
                Console.WriteLine($"Bits Per Sample: {waveInEvent.WaveFormat.BitsPerSample}");
                Console.WriteLine($"Channels: {waveInEvent.WaveFormat.Channels}");
                Console.WriteLine($"Encoding: {waveInEvent.WaveFormat.Encoding}");

                fileWriter?.Dispose();
                fileWriter = null;
            };
            #endregion

            Console.ReadKey();

            // Stop Recording and dispose object
            waveInEvent.StopRecording();
            waveInEvent.Dispose();

            Console.WriteLine("Recording Stopped.");
        }
Example #24
0
        public void Reset()
        {
            MyWaveIn.StopRecording();
            StopReplay();

            _buffer      = _buffer = new byte[(int)(MyWaveIn.WaveFormat.AverageBytesPerSecond * RecordTime)];
            _isFull      = false;
            _isRecording = false;
            _pos         = 0;
            MyWaveIn.Dispose();
            MyWaveIn = new WaveInEvent();
            MyWaveIn.DeviceNumber      = Device;
            MyWaveIn.DataAvailable    += DataAvailable;
            MyWaveIn.RecordingStopped += Stopped;
            MyWaveIn.DeviceNumber      = _deviceIndex;
        }
Example #25
0
        /// <summary>
        /// Stops recording.
        /// </summary>
        public void StopRecording()
        {
            if (waveIn != null)
            {
                waveIn.StopRecording();
                waveIn.Dispose();
                waveIn = null;
            }
            if (writer != null)
            {
                writer.Dispose();
                writer = null;
            }

            isRecording = false;
        }
Example #26
0
        static void OnRecordingStopped(object sender, StoppedEventArgs e)
        {
            if (waveSource != null)
            {
                waveSource.Dispose();
                waveSource = null;
            }

            StreamingStopped?.Invoke(sender, new StreamingAudioStoppedEventArgs());

            //if (waveFile != null)
            //{
            //	waveFile.Dispose();
            //	waveFile = null;
            //}
        }
        /// <summary>
        ///     The stop.
        /// </summary>
        public void Stop()
        {
            if (waveSource != null)
            {
                waveSource.StopRecording();
                waveSource.DataAvailable -= OnWaveSourceOnDataAvailable;
                waveSource.Dispose();
                waveSource = null;
            }

            if (waveFile != null)
            {
                waveFile.Dispose();
                waveFile = null;
            }
        }
Example #28
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var outputFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "NAudio");

            Directory.CreateDirectory(outputFolder);
            var            outputFilePath = Path.Combine(outputFolder, "recorded.wav");
            var            waveIn         = new WaveInEvent();
            WaveFileWriter writer         = null;
            bool           closing        = false;

            //pentru inregistrare audio
            button1.Click += (s, a) =>
            {
                writer = new WaveFileWriter(outputFilePath, waveIn.WaveFormat);
                waveIn.StartRecording();
                button1.Enabled = false;
                button3.Enabled = true;
            };
            waveIn.DataAvailable += (s, a) =>
            {
                writer.Write(a.Buffer, 0, a.BytesRecorded);
            };
            waveIn.DataAvailable += (s, a) =>
            {
                writer.Write(a.Buffer, 0, a.BytesRecorded);
                if (writer.Position > waveIn.WaveFormat.AverageBytesPerSecond * 30)
                {
                    waveIn.StopRecording();
                }
            };
            //pentru oprire inregistrare
            button3.Click    += (s, a) => waveIn.StopRecording();
            this.FormClosing += (s, a) => { closing = true; waveIn.StopRecording(); };

            waveIn.RecordingStopped += (s, a) =>
            {
                writer?.Dispose();
                writer          = null;
                button1.Enabled = true;
                button3.Enabled = false;
                if (closing)
                {
                    waveIn.Dispose();
                }
            };
        }
Example #29
0
        void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
        {
            AppCoordinator.RecordLog += MSG_RECORDING_ENDS + fileOutput + "\n\n";
            recording = false;

            if (waveSource != null)
            {
                waveSource.Dispose();
                waveSource = null;
            }

            if (waveFile != null)
            {
                waveFile.Dispose();
                waveFile = null;
            }
        }
Example #30
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_config != null)
                {
                    Toml.WriteFile(_config, "config.toml", _tomlSettings);
                    _config = null;
                }

                _waveIn?.StopRecording();
                _waveIn?.Dispose();
                _waveIn = null;

                _speechRecognizer?.Dispose();
                _speechRecognizer = null;

                _skFont?.Dispose();
                _skFont = null;

                _skStrokePaint?.Dispose();
                _skStrokePaint = null;

                _skFillPaint?.Dispose();
                _skFillPaint = null;

                _skScreenSurface?.Dispose();
                _skScreenSurface = null;

                _skScreenRenderTarget?.Dispose();
                _skScreenRenderTarget = null;

                _skContext?.Dispose();
                _skContext = null;

                _skInterface?.Dispose();
                _skInterface = null;

                _tkContext?.Dispose();
                _tkContext = null;

                _tkWindow?.Dispose();
                _tkWindow = null;
            }
        }