示例#1
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);
    }
示例#2
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();
        }
示例#3
0
        /// <summary>
        ///     Close application event
        /// </summary>
        /// <param name="sender">Window object</param>
        /// <param name="e">Event arguments</param>
        private void Window_Closed(object sender, EventArgs e)
        {
            _isRun = false;

            _wasapiLoopbackCapture?.StopRecording();
            _waveIn?.StopRecording();
        }
示例#4
0
文件: Audio.cs 项目: Soembodi/Luxuino
 public void Stop()
 {
     canReact = false;
     timer.Stop();
     toggleButton.Theme = MetroFramework.MetroThemeStyle.Dark;
     toggleButton.Text  = "Start";
     capture.StopRecording();
 }
        /// <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();
        }
示例#7
0
        private void stopWatch_EventArrived(object sender, EventArrivedEventArgs e)
        {
            try
            {
                Process[] proc = Process.GetProcessesByName("Slack");
                if (proc.Length < 8)
                {
                    if (counter == 3)
                    {
                        notifyIcon1.Visible = true;
                        notifyIcon1.ShowBalloonTip(1000, "Slack Recorder", "Call recorded", ToolTipIcon.Info);
                        notifyIcon1.Visible = false;

                        if (waveIn != null)
                        {
                            try
                            {
                                waveIn.StopRecording();
                                CaptureInstance.StopRecording();

                                saveDate = DateTime.Now.ToString("dd.MM.yyyy");
                                saveTime = DateTime.Now.ToString("HH.mm.ss");

                                MixTwoSamples();

                                ConvertToMP3(saveDirectory.SelectedPath + "\\" + "result.wav", saveDirectory.SelectedPath + "\\" + saveDate + "_" + saveTime + ".mp3", 128);

                                DeleteTempFiles();

                                InsertIntoDatabase(saveDate, saveTime, saveDirectory.SelectedPath);
                            }
                            #pragma warning disable CS0168 // Variable is declared but never used
                            catch (NullReferenceException ex)
                            #pragma warning restore CS0168 // Variable is declared but never used
                            {
                                waveIn.StopRecording();
                                CaptureInstance.StopRecording();
                            }
                        }
                        counter = 0;
                    }
                    counter++;
                }
            }
            catch (NullReferenceException ex)
            {
                //MessageBox.Show("Slack call servers are down, please try later");
            }
        }
示例#8
0
    /* Stop Capturing */
    public bool Stop()
    {
        if (!isRecording)
        {
            return(false);
        }

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

        // Kill Timers
        PInvoke.timeKillEvent(captureTimerId);
        PInvoke.timeKillEvent(durationTimerId);

        captureTimerId        = 0;
        captureTimerDelegate  = null;
        durationTimerId       = 0;
        durationTimerDelegate = null;

        status      = "Idle";
        isRecording = false;
        return(isRecording);
    }
示例#9
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();
        }
示例#10
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();
        }
示例#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
 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 { }
 }
示例#13
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();
        }
示例#14
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();
        }
 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;
 }
示例#16
0
 public void stopRecording()
 {
     Console.WriteLine(" Stopping recording.");
     Form1.window.radioButton1.Checked = Form1.recordMode = false;
     capture.StopRecording();
     recording = false;
 }
示例#17
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     mainLoop.Stop();
     _waveIn.StopRecording();
     Application.Exit();
     Environment.Exit(0);
 }
示例#18
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;
            }
        }
示例#19
0
        public async void Run()
        {
            Running = true;
            await Task.Delay(50);

            _waveIn = new WasapiLoopbackCapture(_userSettings.SpotifyAudioSession.AudioEndPointDevice);

            _waveIn.DataAvailable    += WaveIn_DataAvailable;
            _waveIn.RecordingStopped += WaveIn_RecordingStopped;

            _currentOutputFile = _fileManager.GetOutputFile(_userSettings.OutputPath);

            _writer = new WaveFileWriter(_currentOutputFile.ToPendingFileString(), _waveIn.WaveFormat);
            if (_writer == null)
            {
                Running = false;
                return;
            }

            _waveIn.StartRecording();
            _form.WriteIntoConsole(I18nKeys.LogRecording, _currentOutputFile.File);

            while (Running)
            {
                await Task.Delay(50);
            }

            _waveIn.StopRecording();
        }
示例#20
0
        public async Task Run(CancellationTokenSource cancellationTokenSource)
        {
            if (!_canDo)
            {
                return;
            }

            _cancellationTokenSource = cancellationTokenSource;
            Running = true;

            _waveIn.StartRecording();
            _waveOut.Init(_bufferedWaveProvider);

            // TODO: Stop duplicate playback with user settings
            // _waveOut.Play();

            while (Running)
            {
                if (_cancellationTokenSource.IsCancellationRequested)
                {
                    return;
                }
                await Task.Delay(100);
            }

            _waveOut.Stop();
            _waveIn.StopRecording();
        }
示例#21
0
 public void Stop()
 {
     if (capture != null)
     {
         capture.StopRecording();
     }
 }
示例#22
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;
        }
示例#23
0
        public void Run()
        {
            Running = true;
            WaveIn  = new WasapiLoopbackCapture();

            WaveIn.DataAvailable    += waveIn_DataAvailable;
            WaveIn.RecordingStopped += waveIn_RecordingStopped;

            Writer = GetFileWriter(WaveIn);

            if (Writer == null)
            {
                if (!Directory.Exists(_path))
                {
                    _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logInvalidOutput"));
                    return;
                }
                _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logWriterIsNull"));
                return;
            }

            WaveIn.StartRecording();
            _form.WriteIntoConsole(string.Format(FrmEspionSpotify.Rm.GetString($"logRecording") ?? "{0}", BuildFileName(_path, false)));

            while (Running)
            {
                Thread.Sleep(30);
            }
            WaveIn.StopRecording();
        }
示例#24
0
        private void StopRecordingButton_Click(object sender, System.EventArgs e)
        {
            capture.StopRecording();

            StartRecordingButton.Enabled = true;
            StopRecordingButton.Enabled  = false;
        }
        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();
        }
        private void StopButton_Click(object sender, EventArgs e)
        {
            StopButton.Enabled = false;
            stopwatch.Stop();

            capture.StopRecording();                                //stops the recording process
            wave.StopRecording();

            if (outputFileNameSounds == null)
            {
                return;
            }

            if (outputFileNameMic == null)
            {
                return;
            }

            var processStartInfo = new ProcessStartInfo                     //open explorer after saving
            {
                FileName        = Path.GetDirectoryName(outputFileNameMic), //search used path
                UseShellExecute = true                                      //use Operating System Shell to execute
            };

            Process.Start(processStartInfo);                        //start Procces (open Folder)
        }
示例#27
0
        public void Run()
        {
            Running = true;
            Thread.Sleep(50);
            _waveIn = new WasapiLoopbackCapture();

            _waveIn.DataAvailable    += WaveIn_DataAvailable;
            _waveIn.RecordingStopped += WaveIn_RecordingStopped;

            _writer = GetFileWriter(_waveIn);

            if (_writer == null)
            {
                return;
            }

            _waveIn.StartRecording();
            _form.WriteIntoConsole(string.Format(FrmEspionSpotify.Rm.GetString($"logRecording") ?? "{0}", _fileManager.BuildFileName(_userSettings.OutputPath, false)));

            while (Running)
            {
                Thread.Sleep(50);
            }

            _waveIn.StopRecording();
        }
 private void TransmitForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     audioClient.Close();
     output.Stop();
     capture.StopRecording();
     receiverThread.Abort();
     speaker.AudioEndpointVolume.Mute = muteAudio ? wasAudioMuted : speaker.AudioEndpointVolume.Mute;
 }
示例#29
0
 public static void StopRecording()
 {
     if (!_readyForRecording)
     {
         //starts StopRecording event
         _waveSource.StopRecording();
         _readyForRecording = true;
     }
 }
示例#30
0
        public async void Stop()
        {
            if (_capture != null)
            {
                await Task.Delay((int)PostWait);

                _capture.StopRecording();
            }
        }