Пример #1
0
    /// <summary>
    /// Stop Recording
    /// </summary>
    /// <returns>Successful</returns>
    public bool Stop()
    {
        if (!isRecording)
        {
            return(false);
        }

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

            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 StartRecord()
        {
            using (WasapiCapture capture = new WasapiLoopbackCapture())
            {
                //if nessesary, you can choose a device here
                //to do so, simply set the device property of the capture to any MMDevice
                //to choose a device, take a look at the sample here: http://cscore.codeplex.com/

                //initialize the selected device for recording
                capture.Initialize();

                //create a wavewriter to write the data to
                using (var stream = new FileStream("dump.wav", FileMode.CreateNew))
                {
                    using (var w = new WaveWriter(stream, capture.WaveFormat))
                    {
                        //setup an eventhandler to receive the recorded data
                        capture.DataAvailable += (s, args) =>
                        {
                            //save the recorded audio
                            w.Write(args.Data, args.Offset, args.ByteCount);
                        };

                        //start recording
                        capture.Start();

                        SpinWait.SpinUntil(() => !_recording);

                        //stop recording
                        capture.Stop();
                    }
                    stream.Flush(true);
                }
            }
        }
Пример #3
0
        internal static void RecordToWma(string fileName)
        {
            using (var wasapiCapture = new WasapiLoopbackCapture())
            {
                wasapiCapture.Initialize();
                var wasapiCaptureSource = new SoundInSource(wasapiCapture);
                using (var stereoSource = wasapiCaptureSource.ToStereo())
                {
                    using (var writer = MediaFoundationEncoder.CreateWMAEncoder(stereoSource.WaveFormat, fileName))
                    {
                        byte[] buffer = new byte[stereoSource.WaveFormat.BytesPerSecond];
                        wasapiCaptureSource.DataAvailable += (s, e) =>
                        {
                            int read = stereoSource.Read(buffer, 0, buffer.Length);
                            writer.Write(buffer, 0, read);
                            Console.Write(".");
                        };

                        wasapiCapture.Start();

                        Console.ReadKey();

                        wasapiCapture.Stop();
                    }
                }
            }
        }
Пример #4
0
    public NaudioDemo()
    {
        using (WasapiCapture capture = new WasapiLoopbackCapture()) {
            //if nessesary, you can choose a device here
            //to do so, simply set the device property of the capture to any MMDevice
            //to choose a device, take a look at the sample here: http://cscore.codeplex.com/

            //initialize the selected device for recording
            capture.Initialize();

            //create a wavewriter to write the data to
            using (WaveWriter w = new WaveWriter("dump.wav", capture.WaveFormat)) {
                //setup an eventhandler to receive the recorded data
                capture.DataAvailable += (s, e) =>
                {
                    //save the recorded audio
                    w.Write(e.Data, e.Offset, e.ByteCount);
                };

                //start recording
                capture.Start();

                Thread.Sleep(1000);

                //stop recording
                capture.Stop();
            }
        }
    }
Пример #5
0
        internal static void RecordToWav(string fileName)
        {
            using (WasapiCapture capture = new WasapiLoopbackCapture())
            {
                //if nessesary, you can choose a device here
                //to do so, simply set the device property of the capture to any MMDevice
                //to choose a device, take a look at the sample here: http://cscore.codeplex.com/

                //initialize the selected device for recording
                capture.Initialize();

                //create a wavewriter to write the data to
                using (WaveWriter w = new WaveWriter(fileName, capture.WaveFormat))
                {
                    //setup an eventhandler to receive the recorded data
                    capture.DataAvailable += (s, e) =>
                    {
                        //save the recorded audio
                        w.Write(e.Data, e.Offset, e.ByteCount);
                        Console.Write(".");
                    };

                    //start recording
                    capture.Start();

                    Console.ReadKey();

                    //stop recording
                    capture.Stop();
                }
            }
        }
Пример #6
0
        public async Task <MemoryStream> GetLoopbackAudio(int ms)
        {
            var Stream = new MemoryStream();

            using (WasapiCapture virtualaudiodev =
                       new WasapiLoopbackCapture())
            {
                virtualaudiodev.Initialize();
                var soundInSource = new SoundInSource(virtualaudiodev)
                {
                    FillWithZeros = false
                };
                var convertedSource = soundInSource.ChangeSampleRate(44100).ToSampleSource().ToWaveSource(16);
                using (convertedSource = convertedSource.ToMono())
                {
                    using (var waveWriter = new WaveWriter(Stream, convertedSource.WaveFormat))
                    {
                        soundInSource.DataAvailable += (s, e) =>
                        {
                            var buffer = new byte[convertedSource.WaveFormat.BytesPerSecond / 2];
                            int read;
                            while ((read = convertedSource.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                waveWriter.Write(buffer, 0, read);
                            }
                        };
                        virtualaudiodev.Start();
                        Thread.Sleep(ms);
                        virtualaudiodev.Stop();
                    }
                }
            }

            return(Stream);
        }
Пример #7
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();
        }
Пример #8
0
        static void Main(string[] args)
        {
            using (var wasapiCapture = new WasapiLoopbackCapture())
            {
                wasapiCapture.Initialize();
                var wasapiCaptureSource = new SoundInSource(wasapiCapture);
                using (var stereoSource = wasapiCaptureSource.ToStereo())
                {
                    //using (var writer = MediaFoundationEncoder.CreateWMAEncoder(stereoSource.WaveFormat, "output.wma"))
                    using (var writer = new WaveWriter("output.wav", stereoSource.WaveFormat))
                    {
                        byte[] buffer = new byte[stereoSource.WaveFormat.BytesPerSecond];
                        wasapiCaptureSource.DataAvailable += (s, e) =>
                        {
                            int read = stereoSource.Read(buffer, 0, buffer.Length);
                            writer.Write(buffer, 0, read);
                        };

                        wasapiCapture.Start();

                        Console.ReadKey();

                        wasapiCapture.Stop();
                    }
                }
            }
        }
Пример #9
0
 void OnApplicationQuit()
 {
     if (enabled)
     {
         loopbackCapture.Stop();
         loopbackCapture.Dispose();
     }
 }
Пример #10
0
        public static int Capture(string output_file, int time)
        {
            int sampleRate    = 48000;
            int bitsPerSample = 24;


            //create a new soundIn instance
            using (WasapiCapture soundIn = new WasapiLoopbackCapture())
            {
                //initialize the soundIn instance
                soundIn.Initialize();

                //create a SoundSource around the the soundIn instance
                SoundInSource soundInSource = new SoundInSource(soundIn)
                {
                    FillWithZeros = false
                };

                //create a source, that converts the data provided by the soundInSource to any other format
                IWaveSource convertedSource = soundInSource
                                              .ChangeSampleRate(sampleRate) // sample rate
                                              .ToSampleSource()
                                              .ToWaveSource(bitsPerSample); //bits per sample

                //channels...
                using (convertedSource = convertedSource.ToStereo())
                {
                    //create a new wavefile
                    using (WaveWriter waveWriter = new WaveWriter(output_file, convertedSource.WaveFormat))
                    {
                        //register an event handler for the DataAvailable event of the soundInSource
                        soundInSource.DataAvailable += (s, e) =>
                        {
                            //read data from the converedSource
                            byte[] buffer = new byte[convertedSource.WaveFormat.BytesPerSecond / 2];
                            int    read;

                            //keep reading as long as we still get some data
                            while ((read = convertedSource.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                //write the read data to a file
                                waveWriter.Write(buffer, 0, read);
                            }
                        };

                        //start recording
                        soundIn.Start();

                        //delay and keep recording
                        Thread.Sleep(time);

                        //stop recording
                        soundIn.Stop();
                    }
                }
            }
            return(0);
        }
Пример #11
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();
        }
Пример #12
0
    void StopListen()
    {
        singleBlockNotificationStream.SingleBlockRead -= SingleBlockNotificationStream_SingleBlockRead;

        soundInSource.Dispose();
        realTimeSource.Dispose();
        loopbackCapture.Stop();
        loopbackCapture.Dispose();
    }
Пример #13
0
        public void Cleanup()
        {
            if (_soundIn != null)
            {
                _soundIn.Stop();
            }

            ClearPrograms();
        }
Пример #14
0
        public void StopListen()
        {
            _singleBlockNotificationStream.SingleBlockRead -= singleBlockNotificationStream_SingleBlockRead;

            _soundInSource.Dispose();
            _realtimeSource.Dispose();
            _receiveAudio = null;
            _loopbackCapture.Stop();
            _loopbackCapture.Dispose();
        }
Пример #15
0
        private void StopListening()
        {
            blockNotifyStream.SingleBlockRead -= SingleBlockRead;

            soundIn.Dispose();
            realtime.Dispose();

            loopback?.Stop();
            loopback?.Dispose();
        }
Пример #16
0
        public void ChangeQuality(int sampleRate, int bitsPerSecond)
        {
            SampleRate   = sampleRate;
            BitPerSecond = bitsPerSecond;

            _soundIn.Stop();
            _targetSoundSource = _defaultSoundSource
                                 .ChangeSampleRate(SampleRate)
                                 .ToSampleSource()
                                 .ToStereo()
                                 .ToWaveSource(BitPerSecond);
            _soundIn.Start();
        }
Пример #17
0
        private void OnClosing(object sender, FormClosingEventArgs e)
        {
            UpdateTimer.Stop();

            if (_soundIn != null)
            {
                _soundIn.Stop();
                _soundIn.Dispose();
                _soundIn = null;
            }
            if (_source != null)
            {
                _source.Dispose();
                _source = null;
            }
        }
        void OnKey(object sender, InterceptKeys.KeyOfInterest e)
        {
            _keyTicks.Add(_tracker.CurrentTime);

            if (_audioTicks.Count == _keyTicks.Count)
            {
                Console.WriteLine($"offset {(_keyTicks.Last()- _audioTicks.Last()) / 10000 }ms");
                if (_audioTicks.Count >= c_sampleCount)
                {
                    _capture.Stop();
                    InterceptKeys.Stop();
                    _output.Stop();
                    _capture.Dispose();
                    _output.Dispose();
                    _done.Set();
                }
            }
        }
Пример #19
0
        public static void listen(long ms)
        {
            using (WasapiCapture capture = new WasapiLoopbackCapture())
            {
                //if nessesary, you can choose a device here
                //to do so, simply set the device property of the capture to any MMDevice
                //to choose a device, take a look at the sample here: http://cscore.codeplex.com/

                double time = DateTime.Now.TimeOfDay.TotalMilliseconds;

                //initialize the selected device for recording
                capture.Initialize();

                //create a wavewriter to write the data to
                using (WaveWriter w = new WaveWriter("dance_r.wav", capture.WaveFormat))
                {
                    bool caught = false;
                    //setup an eventhandler to receive the recorded data
                    capture.DataAvailable += (s, e) =>
                    {
                        //save the recorded audio

                        Console.WriteLine(e.ByteCount);

                        caught = true;

                        //w.Write(e.Data, e.Offset, e.ByteCount);
                    };

                    //start recording
                    capture.Start();

                    while (!caught)
                    {
                    }

                    //stop recording
                    capture.Stop();
                }
            }
        }
Пример #20
0
        /// <summary>
        /// Stops recording.
        /// </summary>
        public void stopRecording()
        {
            micCapture.Stop();
            speakCapture.Stop();
            micWriter.Dispose();
            speakWriter.Dispose();
            micCapture.Dispose();
            speakCapture.Dispose();
            window.unlock();
            string size1 = "-1";
            string size2 = "-1";

            if (File.Exists(micFileName))
            {
                FileInfo f      = new FileInfo(micFileName);
                int      mbytes = (int)(f.Length / 1024 / 1024);
                size1 = 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);
                size2 = mbytes.ToString();
            }
            else
            {
                MessageBox.Show("No file with name\n   " + speakFileName + "\nexists.\n\nSpeakers may not have been recorded.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            window.setLabelMicText(micFileName + "   -   " + size1 + "MB");
            window.setLabelSpeakText(speakFileName + "   -   " + size2 + "MB");
        }
Пример #21
0
        public async Task AudioStreamCommand([
                                                 Summary("Voice Channel name")]
                                             IVoiceChannel channel = null,
                                             [Summary("Number of audio channels, 1 for mono, 2 for stereo (Default)")]
                                             int nAudioChannels = 2,
                                             [Summary("Sample rate in hertz, 48000 (Default)")]
                                             int sampleRate = 48000,
                                             [Summary("Number of bits per sample, 16 (Default)")]
                                             int bitsPerSample = 16)
        {
            var connection = await channel.ConnectAsync();

            var dstream = connection.CreatePCMStream(AudioApplication.Mixed);

            using (WasapiCapture soundIn = new WasapiLoopbackCapture())
            {
                //initialize the soundIn instance
                soundIn.Initialize();

                //create a SoundSource around the the soundIn instance
                //this SoundSource will provide data, captured by the soundIn instance
                SoundInSource soundInSource = new SoundInSource(soundIn)
                {
                    FillWithZeros = false
                };

                //create a source, that converts the data provided by the
                //soundInSource to any other format
                //in this case the "Fluent"-extension methods are being used
                IWaveSource convertedSource = soundInSource
                                              .ChangeSampleRate(sampleRate) // sample rate
                                              .ToSampleSource()
                                              .ToWaveSource(bitsPerSample); //bits per sample
                //int channels = 2;
                //channels...
                using (convertedSource = nAudioChannels == 1 ? convertedSource.ToMono() : convertedSource.ToStereo())
                {
                    //register an event handler for the DataAvailable event of
                    //the soundInSource
                    //Important: use the DataAvailable of the SoundInSource
                    //If you use the DataAvailable event of the ISoundIn itself
                    //the data recorded by that event might won't be available at the
                    //soundInSource yet
                    soundInSource.DataAvailable += (s, e) =>
                    {
                        //read data from the converedSource
                        //important: don't use the e.Data here
                        //the e.Data contains the raw data provided by the
                        //soundInSource which won't have your target format
                        byte[] buffer = new byte[convertedSource.WaveFormat.BytesPerSecond / 2];
                        int    read;

                        //keep reading as long as we still get some data
                        //if you're using such a loop, make sure that soundInSource.FillWithZeros is set to false
                        while ((read = convertedSource.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            //write the read data to a file
                            // ReSharper disable once AccessToDisposedClosure
                            dstream.Write(buffer, 0, read);
                        }
                    };

                    //we've set everything we need -> start capturing data
                    soundIn.Start();

                    Console.WriteLine("Capturing started ... press any key to stop.");
                    Console.ReadKey();
                    soundIn.Stop();
                }
            }
        }
Пример #22
0
 public void Stop()
 {
     _soundIn?.Stop();
 }
Пример #23
0
        static async Task MainAsync()
        {
            Console.Title = "Audio Streamer - PC to Android";

            IPAddress IPAddr;
            bool      UseAdb = false;

            try
            {
                var AdbDevices = Process.Start(new ProcessStartInfo()
                {
                    FileName               = "adb",
                    Arguments              = "devices",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true
                });

                await AdbDevices.StandardOutput.ReadLineAsync();

                UseAdb = !string.IsNullOrWhiteSpace(await AdbDevices.StandardOutput.ReadLineAsync());
            }
            catch (System.ComponentModel.Win32Exception)
            {
            }

            if (UseAdb)
            {
                IPAddr = IPAddress.Loopback;
            }
            else
            {
                Console.Write("IP: ");
                IPAddr = IPAddress.Parse(Console.ReadLine());
            }

            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
            using (Capture = new WasapiLoopbackCapture(0, new CSCore.WaveFormat(), ThreadPriority.Highest))
            {
                while (true)
                {
                    var NoSpamDelay = Task.Delay(1000);
                    if (UseAdb)
                    {
                        Process.Start(new ProcessStartInfo()
                        {
                            FileName        = "adb",
                            Arguments       = "forward tcp:1420 tcp:1420",
                            UseShellExecute = false
                        });
                    }

                    using (var Conn = new TcpClient()
                    {
                        NoDelay = true,
                        ReceiveBufferSize = 64,
                        SendBufferSize = 1 << 12    //2^12 = ~4000 so 1000 floats
                    })
                    {
                        try
                        {
                            await Conn.ConnectAsync(IPAddr, ServerPort);

                            Stream = Conn.GetStream();
                            if (Stream.ReadByte() == 1)
                            {
                                Console.WriteLine("Connected to " + IPAddr.ToString());
                                Capture.Initialize();
                                using (Source = new SoundInSource(Capture))
                                {
                                    int SampleRateServer = Source.WaveFormat.SampleRate;
                                    int SampleRateClient = Stream.ReadByte() | Stream.ReadByte() << 8 | Stream.ReadByte() << 16;
                                    if (SampleRateClient != SampleRateServer)
                                    {
                                        Console.WriteLine($"Sample rate mismatch, PC was {SampleRateServer} Hz but client was {SampleRateClient} Hz");
                                        Console.WriteLine("Adjust your PC's sample rate then press any key to try again");
                                        Console.ReadKey();
                                        Console.Clear();
                                    }
                                    else
                                    {
                                        // Start Capturing
                                        Source.DataAvailable += DataAvailable;
                                        Capture.Start();

                                        Console.WriteLine($"Started recording audio at {SampleRateServer} Hz");
                                        Window.SetWindowShown(false);

                                        // Stop Capturing
                                        await(DisconnectWaiter = new TaskCompletionSource <bool>()).Task;
                                        await Task.Run(() => Capture.Stop());

                                        Window.SetWindowShown(true);
                                        Console.WriteLine("Disconnected, stopped recording audio");
                                    }
                                }
                            }
                        }
                        catch { }
                        await NoSpamDelay;
                    }
                }
            }
        }
Пример #24
0
        static int Main(string[] args)
        {
            int    time;
            string output_file;

            switch (args.Length)
            {
            case 1:
                if (args[0] == "-h")
                {
                    System.Console.WriteLine("Usage:");
                    System.Console.WriteLine("    LoopbackCapture.exe <output/wav> <time/milliseconds>");
                    return(1);
                }
                output_file = args[0];
                time        = 0;
                break;

            case 2:
                output_file = args[0];
                try
                {
                    time = Int32.Parse(args[1]);
                }
                catch
                {
                    time = 0;
                }
                break;

            default:
                time        = 0;
                output_file = "record.wav";
                break;
            }

            int sampleRate    = 48000;
            int bitsPerSample = 24;

            //create a new soundIn instance
            using (WasapiCapture soundIn = new WasapiLoopbackCapture())
            {
                //initialize the soundIn instance
                soundIn.Initialize();

                //create a SoundSource around the the soundIn instance
                SoundInSource soundInSource = new SoundInSource(soundIn)
                {
                    FillWithZeros = false
                };

                //create a source, that converts the data provided by the soundInSource to any other format

                IWaveSource convertedSource = soundInSource
                                              .ChangeSampleRate(sampleRate) // sample rate
                                              .ToSampleSource()
                                              .ToWaveSource(bitsPerSample); //bits per sample

                //channels...
                using (convertedSource = convertedSource.ToStereo())
                {
                    //create a new wavefile
                    using (WaveWriter waveWriter = new WaveWriter(output_file, convertedSource.WaveFormat))
                    {
                        //register an event handler for the DataAvailable event of the soundInSource
                        soundInSource.DataAvailable += (s, e) =>
                        {
                            //read data from the converedSource
                            byte[] buffer = new byte[convertedSource.WaveFormat.BytesPerSecond / 2];
                            int    read;

                            //keep reading as long as we still get some data
                            while ((read = convertedSource.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                //write the read data to a file
                                waveWriter.Write(buffer, 0, read);
                            }
                        };

                        //start recording
                        soundIn.Start();

                        //delay and keep recording
                        if (time != 0)
                        {
                            Thread.Sleep(time);
                        }
                        else
                        {
                            Console.ReadKey();
                        }

                        //stop recording
                        soundIn.Stop();
                    }
                }
            }
            return(0);
        }
Пример #25
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     _capture.Stop();
     _capture.Dispose();
 }
Пример #26
0
 // Clear resources
 private void Application_ApplicationExit(object sender, EventArgs e)
 {
     wasapi.Stop();
     wasapi.DataAvailable -= Wasapi_DataAvailable;
     wasapi.Dispose();
 }
Пример #27
0
 public void Dispose()
 {
     _soundIn.Stop();
     _soundIn.Dispose();
 }
Пример #28
0
 private void Form_Closing(object sender, FormClosingEventArgs e)
 {
     _soundIn.Stop();
     _soundIn.Dispose();
 }
Пример #29
0
        void loopRecord()
        {
            // Get current window title of active window
            string title = GetWindowTitle();

            // Wait for the title to change, check 10 times per second
            while (title == GetWindowTitle() || GetWindowTitle() == "Advertisement" || GetWindowTitle() == "Spotify")
            {
                Thread.Sleep(100);
            }
            updateWindowNameDisplay();
            btn_toggleRecord.Invoke((MethodInvoker) delegate
            {
                btn_toggleRecord.Text      = "Recording...";
                btn_toggleRecord.BackColor = Color.LightGreen;
                btn_toggleRecord.ForeColor = Color.White;
            });
            while (!stopRecording)
            {
                using (WasapiCapture capture = new WasapiLoopbackCapture())
                {
                    currentlyplaying cp = null;
                    while (cp == null)
                    {
                        cp = get_Currently_Playing();
                    }
                    if (cp.item != null)
                    {
                        string filename = cp.item.id; // GetWindowTitle();

                        //rtxt_songlist.Invoke((MethodInvoker)delegate {
                        //    // Running on the UI thread
                        //    rtxt_songlist.Text += filename + "\n";
                        //});

                        // rtxt_songlist.Text += filename + "\n";
                        //foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                        //{
                        //    filename = filename.Replace(c, '_');
                        //}


                        //initialize the selected device for recording
                        capture.Initialize();

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        //create a wavewriter to write the data to
                        using (WaveWriter w = new WaveWriter(path + "\\" + filename + ".wav", capture.WaveFormat))
                        {
                            //setup an eventhandler to receive the recorded data
                            capture.DataAvailable += (s, E) =>
                            {
                                //save the recorded audio
                                w.Write(E.Data, E.Offset, E.ByteCount);
                            };

                            //start recording
                            capture.Start();

                            //for (int i = 0; i < 100; i++)
                            //{
                            //    Thread.Sleep(time / 100);
                            //    prog_recording.Value = 1 * i;
                            //}

                            // Get current window title of active window
                            string newTitle = GetWindowTitle();
                            // Wait for the title to change, check 10 times per second
                            while (newTitle == GetWindowTitle())
                            {
                                Thread.Sleep(100);
                                updateWindowNameDisplay();
                            }
                            //stop recording
                            capture.Stop();
                            updateWindowNameDisplay();
                            while (GetWindowTitle() == "Advertisement" || GetWindowTitle() == "Spotify")
                            {
                                Thread.Sleep(100);
                                updateWindowNameDisplay();
                            }
                            convertTagAsynch(path, filename, cp);


                            // Thread.Sleep(time);
                        }
                    }
                }

                if (title == GetWindowTitle())
                {
                    stopRecording = true;
                }
            }
            btn_toggleRecord.Invoke((MethodInvoker) delegate
            {
                btn_toggleRecord.Text      = "Record";
                btn_toggleRecord.BackColor = Color.FromArgb(30, 30, 30);
                btn_toggleRecord.ForeColor = Color.White;
            });
        }
Пример #30
0
 protected override void OnClose(CloseEventArgs e)
 {
     _capture.Stop();
     _capture.Dispose();
     base.OnClose(e);
 }