예제 #1
0
        private void btStop_Click(object sender, EventArgs e)
        {
            if (sourceStream != null)
            {
                sourceStream.StopRecording();
                sourceStream.Dispose();
                sourceStream = null;
            }

            if (sourceStream1 != null)
            {
                sourceStream1.StopRecording();
                sourceStream1.Dispose();
                sourceStream1 = null;
            }
            if (this.waveWriter == null)
            {
                return;
            }
            this.waveWriter.Dispose();
            waveWriter2.Dispose();
            this.waveWriter        = null;
            waveWriter2            = null;
            this.sbtRecord.Enabled = false;
            this.sbtStop.Enabled   = false;
            sbtPlay.Enabled        = true;
            sbtPlay.Focus();

            //mix();
        }
        /// <summary>
        /// Stops recording wave data from SoundCard and releases all resources
        /// </summary>
        public void StopRecording()
        {
            wasapiLoopbackCapture.StopRecording();
            RecordingState = false;

            waveFileWriter.Dispose();
            waveFileWriter = null;
            wasapiLoopbackCapture.Dispose();
        }
        private async void connect_Click(object sender, EventArgs e)
        {
            UpdateState(connected: false);

            _connection = new HubConnectionBuilder()
                          .WithUrl(address.Text)
                          //.AddMessagePackProtocol()
                          .Build();

            _connection.On <string, string>("broadcastMessage", OnSend);

            _connection.On("ListenDesktop", () =>
            {
                MessageBox.Show("A friend wants to listen to your music ! :p");
                try
                {
                    cap = new WasapiLoopbackCapture();
                    cap.DataAvailable += InputBufferToFileCallback;

                    cap.RecordingStopped += stoppedrecordingCallback;
                    //var outputFilePath = "C:\\Users\\Smail\\Desktop\\output-sound-card.mp3";
                    //writer = new WaveFileWriter(outputFilePath, cap.WaveFormat);
                    //file_base64 = new StreamWriter(@"C:\\Users\\Smail\\Desktop\\output-sound-Base64.txt");
                    cap.StartRecording();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("error while listening :" + ex.Message);
                }
            });
            _connection.On("StopListenDesktop", () =>
            {
                cap.StopRecording();
                //writer.Dispose();
                //writer = null;
                cap.Dispose();
                //MessageBox.Show("stopped recording .");
            });

            Log(Color.Gray, "Starting connection...");
            try
            {
                await _connection.StartAsync();
            }
            catch (Exception ex)
            {
                Log(Color.Red, ex.ToString());
                return;
            }

            Log(Color.Gray, "Connection established.");

            UpdateState(connected: true);

            message.Focus();
        }
예제 #4
0
        //private static WaveIn waveSource = null;
        //private static WaveFileWriter waveFile = null;

        public static void RecordSystemAudio(string outFile, int msToRecord = 10000)
        {
            // Redefine the capturer instance with a new instance of the LoopbackCapture class
            WasapiLoopbackCapture CaptureInstance = new WasapiLoopbackCapture();

            // Redefine the audio writer instance with the given configuration
            WaveFileWriter RecordedAudioWriter = new WaveFileWriter(outFile, CaptureInstance.WaveFormat);

            // When the capturer receives audio, start writing the buffer into the mentioned file
            CaptureInstance.DataAvailable += (s, a) =>
            {
                // Write buffer into the file of the writer instance
                RecordedAudioWriter.Write(a.Buffer, 0, a.BytesRecorded);
            };

            // When the Capturer Stops, dispose instances of the capturer and writer
            CaptureInstance.RecordingStopped += (s, a) =>
            {
                RecordedAudioWriter.Dispose();
                RecordedAudioWriter = null;
                CaptureInstance.Dispose();
            };

            // Start audio recording !
            CaptureInstance.StartRecording();
            Thread.Sleep(msToRecord);
            CaptureInstance.StopRecording();
        }
예제 #5
0
        public void StartCapture()
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            var writer = new WaveFileWriter(path, capture.WaveFormat);

            capture.DataAvailable += (s, a) =>
            {
                writer.Write(a.Buffer, 0, a.BytesRecorded);
            };

            capture.RecordingStopped += (s, a) =>
            {
                writer.Dispose();
                writer = null;
                capture.Dispose();
            };

            WasapiCapture waveLoop = new WasapiLoopbackCapture();

            waveLoop.Initialize();
            waveLoop.DataAvailable += waveLoop_DataAvailable;
            waveLoop.Stopped       += waveLoop_Stopped;
            waveLoop.Start();

            capture.StartRecording();
        }
 public void StopRecording()
 {
     if (waveOut != null)
     {
         waveOut.StopRecording();
         waveOut.Dispose();
         waveOut = null;
     }
     if (waveIn != null)
     {
         waveOneOut.Stop();
         waveIn.StopRecording();
         waveIn.Dispose();
     }
     if (this.waveWriter_in != null)
     {
         this.waveWriter_in.Flush();
         this.waveWriter_in.Dispose();
         this.waveWriter_in = null;
     }
     if (this.waveWriter_out != null)
     {
         this.waveWriter_out.Flush();
         this.waveWriter_out.Dispose();
         this.waveWriter_out = null;
     }
     MixFile();
     Startded = false;
 }
예제 #7
0
        private async void WaveIn_RecordingStopped(object sender, StoppedEventArgs e)
        {
            if (_streamWriter == null || _fileWriter == null)
            {
                return;
            }
            _streamOutput.Position = 0;
            await WriteStreamOutputToFileBasedOnNumberOfChannels();

            await _streamWriter.FlushAsync();

            _streamWriter.Dispose();
            _waveIn.Dispose();

            await _fileWriter.FlushAsync();

            _fileWriter.Dispose();

            if (CountSeconds < _userSettings.MinimumRecordedLengthSeconds)
            {
                _form.WriteIntoConsole(I18nKeys.LogDeleting, _currentOutputFile.File, _userSettings.MinimumRecordedLengthSeconds);
                _fileManager.DeleteFile(_currentOutputFile.ToPendingFileString());
                return;
            }

            var length = TimeSpan.FromSeconds(CountSeconds).ToString(@"mm\:ss");

            _form.WriteIntoConsole(I18nKeys.LogRecorded, _track.ToString(), length);

            _fileManager.Rename(_currentOutputFile.ToPendingFileString(), _currentOutputFile.ToString());

            await UpdateOutputFileBasedOnMediaFormat();
        }
예제 #8
0
        public MainWindow()
        {
            InitializeComponent();
            this.Topmost = true;

            Storyboard seconds = (Storyboard)second.FindResource("sbseconds");

            seconds.Begin();
            seconds.Seek(new TimeSpan(0, 0, 0, DateTime.Now.Second, 0));

            Storyboard minutes = (Storyboard)minute.FindResource("sbminutes");

            minutes.Begin();
            minutes.Seek(new TimeSpan(0, 0, DateTime.Now.Minute, DateTime.Now.Second, 0));

            Storyboard hours = (Storyboard)hour.FindResource("sbhours");

            hours.Begin();
            hours.Seek(new TimeSpan(0, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, 0));

            //Eye Movement
            DispatcherTimer dispatcherTimer = new DispatcherTimer();

            dispatcherTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 200);
            dispatcherTimer.Start();

            //Eye Blink
            DispatcherTimer dispatcherBlinkTimer = new DispatcherTimer();

            dispatcherBlinkTimer.Tick    += new EventHandler(blinkTimer);
            dispatcherBlinkTimer.Interval = TimeSpan.FromSeconds(rand.Next(2, 10));
            dispatcherBlinkTimer.Start();

            //Outter border light
            DispatcherTimer dispatcherLightTimer = new DispatcherTimer();

            dispatcherLightTimer.Tick    += new EventHandler(lightTimer);
            dispatcherLightTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
            dispatcherLightTimer.Start();

            //Audio Visualizer
            DispatcherTimer dispatcherVisualizerTimer = new DispatcherTimer();

            dispatcherVisualizerTimer.Tick    += new EventHandler(DrawVisualizerTimer);
            dispatcherVisualizerTimer.Interval = new TimeSpan(0, 0, 0, 0, 200);
            dispatcherVisualizerTimer.Start();

            //Main Scale
            mainScaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, new DoubleAnimation(AppScale, TimeSpan.FromMilliseconds(200)));
            mainScaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, new DoubleAnimation(AppScale, TimeSpan.FromMilliseconds(200)));

            //Audio capture
            capture.DataAvailable    += DataAvailable;
            capture.RecordingStopped += (s, a) =>
            {
                capture.Dispose();
            };
            capture.StartRecording();
        }
예제 #9
0
        public static void StopMirroring()
        {
            if (Application.Current.MainWindow != null)
            {
                Application.Current.MainWindow.IsEnabled = false;
            }

            capture.StopRecording();
            foreach (MirrorHandler mirror in mirrors)
            {
                mirror.StopMirroring();
            }
            mirrors.Clear();
            capture.Dispose();

            capture = null;

            IsMirroring = false;
            ((System.Windows.Controls.MenuItem)(ti.ContextMenu.Items[1])).Header = "Enable";
            ti.ToolTipText = "SoundMirrorer (Not Mirroring)";

            if (Application.Current.MainWindow != null)
            {
                Application.Current.MainWindow.IsEnabled = true;
            }
        }
예제 #10
0
 private void Stop_button_Click(object sender, EventArgs e)
 {
     try
     {
         coverArt.ImageLocation = Environment.CurrentDirectory + "\\AudioWizard.png";
         playBox.Items.Clear();
         if (IsRecording == false)
         {
             currentTime_label.Text = "00:00:00";
             outputDevice.Dispose();
             foundationReader.Dispose();
             foundationReader = null;
             GC.Collect();
             Play_button.Text = "►";
         }
         else
         {
             capture.StopRecording();
             capture.RecordingStopped += (s, o) =>
             {
                 writer.Dispose();
                 writer = null;
                 capture.Dispose();
             };
             IsRecording = false;
             SFD.Filter  = "WAV|*wav";
             if (SFD.ShowDialog() == DialogResult.OK)
             {
                 File.Move(Environment.CurrentDirectory + "\\recording.wav", SFD.FileName + ".wav");
             }
         }
     }
     catch { }
 }
예제 #11
0
        /// <summary>
        /// Finish recording and close WAV file.
        /// </summary>
        public void StopRecording()
        {
            if (!_isRecording)
            {
                return;
            }

            if (_captureInput != null)
            {
                _captureInput.DataAvailable -= _OnDataAvailable;
                _captureInput.StopRecording();
                GC.SuppressFinalize(_captureInput);
                _captureInput.Dispose();
                _captureInput = null;
            }
            if (_waveWriter != null)
            {
                _waveWriter.Flush();
                _waveWriter.Close();
                _waveWriter.Dispose();
                GC.SuppressFinalize(_waveWriter);
                Debug.WriteLine("Recording finished.\n\tFile=" + _tempWavFilePath + "\n");
                _waveWriter = null;
            }
            _isRecording = false;
            _state       = RecorderState.RecordingFinsihed;
            Debug.WriteLine("Recording of " + _tempWavFilePath + " stopped");
        }
예제 #12
0
        public static void StopRecording(bool saveFile)
        {
            Recording = false;

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

            writer?.Close();

            if (saveFile)
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Filter = "Wav Files|*.wav";
                if (dialog.ShowDialog() == true)
                {
                    File.Move("temp.wav", dialog.FileName);
                }
            }

            if (File.Exists("temp.wav"))
            {
                File.Delete("temp.wav");
            }

            writer?.Dispose();
            writer = null;
        }
예제 #13
0
        public void stopRecording()
        {
            isRecording = false;
            micCapture.Stop();
            speakCapture.Stop();
            micWriter.Dispose();
            speakWriter.Dispose();
            micCapture.Dispose();
            speakCapture.Dispose();
            soundout.Stop();
            soundout.Dispose();

            string micSize = "-", speakSize = "-";

            if (File.Exists(micFileName))
            {
                FileInfo f      = new FileInfo(micFileName);
                int      mbytes = (int)(f.Length / 1024 / 1024);
                micSize = mbytes.ToString();
            }
            else
            {
                MessageBox.Show("No file with name\n   " + micFileName + "\nexists.\n\nMicrophone may not have been recorded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (File.Exists(speakFileName))
            {
                FileInfo f      = new FileInfo(speakFileName);
                int      mbytes = (int)(f.Length / 1024 / 1024);
                speakSize = mbytes.ToString();
            }

            window.updateInfo(micFileName, micSize, speakFileName, speakSize);

            window.UnlockUI();
        }
예제 #14
0
        void startRecording()
        {
            // Define the output wav file of the recorded audio
            string outputFilePath = @"system_recorded_audio.wav";

            // Redefine the capturer instance with a new instance of the LoopbackCapture class
            this.CaptureInstance = new WasapiLoopbackCapture();

            // Redefine the audio writer instance with the given configuration
            this.RecordedAudioWriter = new WaveFileWriter(outputFilePath, CaptureInstance.WaveFormat);

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

            // When the Capturer Stops
            this.CaptureInstance.RecordingStopped += (s, a) =>
            {
                this.RecordedAudioWriter.Dispose();
                this.RecordedAudioWriter = null;
                CaptureInstance.Dispose();
            };

            // Start recording !
            this.CaptureInstance.StartRecording();
        }
예제 #15
0
        void startRecordingW()
        {
            this.CreateDataRecoClient();
            var capture = new WasapiLoopbackCapture();

            writer = new WaveFileWriter("temp.wav", capture.WaveFormat);

            this.dataClient.AudioStart();

            capture.DataAvailable += (s, a) =>
            {
                writer.Write(a.Buffer, 0, a.BytesRecorded);
                if (writer.Position > capture.WaveFormat.AverageBytesPerSecond * 5)
                {
                    capture.StopRecording();
                }
            };

            capture.RecordingStopped += (s, a) =>
            {
                writer.Dispose();
                writer = null;
                capture.Dispose();
                startAnalysis();
            };

            capture.StartRecording();
        }
예제 #16
0
        private void WaveIn_RecordingStopped(object sender, StoppedEventArgs e)
        {
            if (_writer != null)
            {
                _writer.Flush();
                _writer.Dispose();
                _waveIn.Dispose();
            }

            if (CountSeconds >= _userSettings.MinimumRecordedLengthSeconds)
            {
                if (!_userSettings.MediaFormat.Equals(MediaFormat.Mp3))
                {
                    return;
                }

                var mp3TagsInfo = new MediaTags.MP3Tags()
                {
                    Track = _track,
                    OrderNumberInMediaTagEnabled = _userSettings.OrderNumberInMediaTagEnabled,
                    Count       = _userSettings.OrderNumber,
                    CurrentFile = _currentFile
                };

                Task.Run(mp3TagsInfo.SaveMediaTags);

                return;
            }

            _form.WriteIntoConsole(string.Format(FrmEspionSpotify.Rm.GetString($"logDeletingTooShort") ?? $"{0}{1}", _fileManager.BuildFileName(_userSettings.OutputPath, false), _userSettings.MinimumRecordedLengthSeconds));

            _fileManager.DeleteFile(_currentFile);
        }
예제 #17
0
        //Start
        private void button1_Click(object sender, EventArgs e)
        {
            this.timeLabel.Text = "00:00:00";

            startTime      = DateTime.Now;
            endTime        = DateTime.Now;
            timer.Interval = 1000; //set the interval to x second.
            timer.Tick    += new EventHandler(tmrClock_Tick);
            timer.Start();
            //No timer
            if (duration == 0)
            {
                this.checkBox1.Checked = false;
            }
            else //Has a timer
            {
                endTime = endTime.AddSeconds(duration);

                mytimer.Interval = duration * 1000 + 100; //set the interval to x second.
                mytimer.Tick    += new EventHandler(mytimer_Tick);
                mytimer.Start();
            }


            // Redefine the capturer instance with a new instance of the LoopbackCapture class
            this.CaptureInstance = new WasapiLoopbackCapture();

            // Redefine the audio writer instance with the given configuration
            this.RecordedAudioWriter = new LameMP3FileWriter(outputFilePath, CaptureInstance.WaveFormat, bitRate);

            // When the capturer receives audio, start writing the buffer into the mentioned file
            this.CaptureInstance.DataAvailable += (s, a) =>
            {
                this.RecordedAudioWriter.Write(a.Buffer, 0, a.BytesRecorded);
                if (RecordedAudioWriter.Position > CaptureInstance.WaveFormat.AverageBytesPerSecond * 36000)
                {
                    CaptureInstance.StopRecording();
                }
            };

            // When the Capturer Stops
            this.CaptureInstance.RecordingStopped += (s, a) =>
            {
                this.RecordedAudioWriter.Dispose();
                this.RecordedAudioWriter = null;
                CaptureInstance.Dispose();
            };

            // Enable "Stop button" and disable "Start Button"
            this.button1.Enabled   = false;
            this.button2.Enabled   = true;
            this.checkBox1.Enabled = false;
            this.textBox1.Enabled  = false;
            this.textBox2.Enabled  = false;
            this.textBox3.Enabled  = false;
            this.label1.Enabled    = false;
            this.button3.Enabled   = false;
            // Start recording !
            this.CaptureInstance.StartRecording();
        }
예제 #18
0
        public void StartRecording(string outputFileName)
        {
            this.outputFileName = outputFileName;
            Directory.CreateDirectory(outputFolder);

            capture = new WasapiLoopbackCapture();
            writer  = new WaveFileWriter(outputFilePathWav, capture.WaveFormat);
            capture.DataAvailable += (s, a) =>
            {
                writer.Write(a.Buffer, 0, a.BytesRecorded);
                if (writer.Position > capture.WaveFormat.AverageBytesPerSecond * 20)
                {
                    capture.StopRecording();
                }
            };
            capture.RecordingStopped += (s, a) =>
            {
                // TODO dispose before new writer...
                writer.Dispose();
                writer = null;
                capture.Dispose();
            };
            capture.StartRecording();
            new Thread(() =>
            {
                while (capture.CaptureState != NAudio.CoreAudioApi.CaptureState.Stopped)
                {
                    Thread.Sleep(10);
                }
            }).Start();
        }
예제 #19
0
        // These WasapiCapture objects _and_ their WasapiCapture.Device members must be
        // Dispose()d when you're done with them.
        static Queue <WasapiCapture> GetAudioCaptures()
        {
            // This is run on another thread; it should not use UnityEngine APIs
            var q = new Queue <WasapiCapture>();

            using (var deviceEnumerator = new MMDeviceEnumerator())
                using (var activeDevices = deviceEnumerator.EnumAudioEndpoints(
                           DataFlow.Render, DeviceState.Active))
                {
                    foreach (MMDevice device in activeDevices)
                    {
                        var audioCapture = new WasapiLoopbackCapture();
                        audioCapture.Device = device;
                        try
                        {
                            audioCapture.Initialize();
                            q.Enqueue(audioCapture);
                        }
                        catch (CSCore.CoreAudioAPI.CoreAudioAPIException)
                        {
                            audioCapture.Device.Dispose();
                            audioCapture.Dispose();
                        }
                    }
                }
            return(q);
        }
예제 #20
0
    /// <summary>
    /// Stop Recording
    /// </summary>
    /// <returns>Successful</returns>
    public bool Stop()
    {
        if (!isRecording)
        {
            return(false);
        }

        // Stop Capturing Audio
        if (recordAudio)
        {
            audioSource.StopRecording();

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

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

        // Kill Timers
        StopTimers();

        status      = "Idle";
        isRecording = false;
        return(isRecording);
    }
예제 #21
0
        private void waveIn_RecordingStopped(object sender, StoppedEventArgs e)
        {
            if (Writer != null)
            {
                Writer.Flush();
                Writer.Dispose();
                WaveIn.Dispose();
            }

            if (Count >= _minTime)
            {
                if (_format != Format.Mp3)
                {
                    return;
                }

                var mp3TagsInfo = new Mp3TagsInfo
                {
                    Song        = _song,
                    BCdTrack    = _bCdTrack,
                    Compteur    = _compteur,
                    CurrentFile = _currentFile
                };
                mp3TagsInfo.SetTagLibDataToMp3();

                return;
            }

            _form.WriteIntoConsole(string.Format(FrmEspionSpotify.Rm.GetString($"logDeletingTooShort") ?? $"{0}{1}", BuildFileName(_path, false), _minTime));

            File.Delete(_currentFile);
        }
        static void Main(string[] args)
        {
            // Setup MP3 writer to output at 32kbit/sec (~2 minutes per MB)
            wri = new LameMP3FileWriter(@"C:\temp\test_output.mp3", waveIn.WaveFormat, 32);
            // Start recording from loopback
            IWaveIn waveIn = new WasapiLoopbackCapture();

            waveIn.DataAvailable    += waveIn_DataAvailable;
            waveIn.RecordingStopped += waveIn_RecordingStopped;
            waveIn.StartRecording();
            stopped = false;
            // Keep recording until Escape key pressed
            while (!stopped)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey(true);
                    if (key != null && key.Key == ConsoleKey.Escape)
                    {
                        waveIn.StopRecording();
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(50);
                }
            }
            // flush output to finish MP3 file correctly
            wri.Flush();
            // Dispose of objects
            waveIn.Dispose();
            wri.Dispose();
        }
예제 #23
0
 private void OnDataStopped(object sender, StoppedEventArgs e)
 {
     if (waveInStream != null)
     {
         waveInStream.Dispose();   //ramden stream siliniyor.
         bilgisayarSesleriniOku(); // Değişkenler tekrar oluşturuluyor.
     }
 }
예제 #24
0
 public void shutDown()
 {
     _waveInStream.StopRecording();
     _waveIn16Stream = null;
     _waveTemp       = null;
     _waveInStream.Dispose();
     _waveInStream = null;
 }
예제 #25
0
        public void StartRecordingLoopback(string outputFileName)
        {
            var recordedAudioWriter = new WaveFileWriter(outputFileName, _loopbackCapture.WaveFormat);

            _loopbackCapture.DataAvailable += (o, e) =>
            {
                recordedAudioWriter.Write(e.Buffer, 0, e.BytesRecorded);
            };
            _loopbackCapture.RecordingStopped += (o, e) =>
            {
                recordedAudioWriter.Dispose();
                recordedAudioWriter = null;
                _loopbackCapture.Dispose();
            };

            _loopbackCapture.StartRecording();
        }
예제 #26
0
 void OnApplicationQuit()
 {
     if (enabled)
     {
         loopbackCapture.Stop();
         loopbackCapture.Dispose();
     }
 }
예제 #27
0
 public void Dispose()
 {
     if (!_isDisposed)
     {
         _isDisposed = true;
         _waveIn.Dispose();
         _waveOut.Dispose();
     }
 }
예제 #28
0
        private void Capture_RecordingStopped(object sender, StoppedEventArgs e)
        {
            if (capture != null)
            {
                capture.Dispose();
            }

            capture = null;
        }
예제 #29
0
    void StopListen()
    {
        singleBlockNotificationStream.SingleBlockRead -= SingleBlockNotificationStream_SingleBlockRead;

        soundInSource.Dispose();
        realTimeSource.Dispose();
        loopbackCapture.Stop();
        loopbackCapture.Dispose();
    }
예제 #30
0
        private void Application_ApplicationExit(object sender, EventArgs e)
        {
            beatDetector.BeatDetected -= BeatDetector_BeatDetected;
            beatDetector.BpmDetected  -= BeatDetector_BpmDetected;

            wasapi.DataAvailable -= Wasapi_DataAvailable;
            wasapi.Stop();
            wasapi.Dispose();
        }