示例#1
2
		public void Start(string path)
		{
			Source = new WasapiLoopbackCapture();

			Source.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
			Source.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);

			File = new WaveFileWriter(path, Source.WaveFormat);

			Source.StartRecording();
			Recording = true;
		}
示例#2
0
        public MemoryStream GetMp3Sample(int seconds, string filepath = "")
        {
            try
            {
                var stream = new MemoryStream();
                // Start recording from loopback
                IWaveIn waveIn = new WasapiLoopbackCapture();
                waveIn.DataAvailable += waveIn_DataAvailable;
                waveIn.RecordingStopped += waveIn_RecordingStopped;
                // Setup MP3 writer to output at 96kbit/sec
                writer = new LameMP3FileWriter(stream, waveIn.WaveFormat, LAMEPreset.ABR_96);
                _isRecording = true;
                waveIn.StartRecording();

                // Wait for X seconds
                System.Threading.Thread.Sleep(seconds * 1000);
                waveIn.StopRecording();

                // flush output to finish MP3 file correctly
                writer.Flush();
                // Dispose of objects
                waveIn.Dispose();
                writer.Dispose();

                if (filepath != "")
                    using (var file = new FileStream(filepath, FileMode.Create, FileAccess.Write))
                        stream.WriteTo(file);

                return stream;
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#3
0
 public static void Start(TrackDto track)
 {
     lock (Lock)
     {
         currentTrack = track;
         waveIn = new WasapiLoopbackCapture();
         lameMp3FileWriter = new LameMP3FileWriter(GetFileName(), waveIn.WaveFormat, 256);
         recordingStopped = new ManualResetEvent(false);
         waveIn.DataAvailable += LoopbackDataAvailable;
         waveIn.RecordingStopped += LoopbackRecordingStopped;
         waveIn.StartRecording();
     }
 }
示例#4
0
        ///////////////////////////////////////////////////////////////////////////События формы
        /// <summary>
        /// Cобытие после загрузки формы
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_Form_Load(object sender, EventArgs e)
        {
            Eq = new EQ();
            Eq.Show();
            Eq.Visible = false;

            btStart     = btPlay;
            PlayListBox = listBox1;
            NameTrack   = tbName;
            Author      = tbAuthor;
            Date        = tbDate;
            Time        = tbTime;

            timer1.Start();
            timer2.Start();
            timer3.Start();

            loadChanges();

            Capt = new WasapiLoopbackCapture();
            Capt.DataAvailable += OnDataAvailable;
            Capt.StartRecording();
        }
示例#5
0
        public void button1_Click(object sender, EventArgs e)
        {
            Console.WriteLine("starting:");
            Console.WriteLine("");

            serialPort1.PortName  = textBox1.Text;
            serialPort1.BaudRate  = 115200;
            serialPort1.RtsEnable = true;
            serialPort1.DtrEnable = true;
            if (serialPort1.IsOpen)
            {
                try
                {
                    serialPort1.Close();
                }
                catch
                {
                }
            }
            try
            {
                serialPort1.Open();
            }
            catch
            {
                MessageBox.Show("Не удалось подключиться!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            capt = new WasapiLoopbackCapture();
            capt.DataAvailable += OnDataAvailable;
            capt.StartRecording();
            serialPort1.DataReceived += OnDataReceived;

            if (serialPort1.IsOpen)
            {
                MessageBox.Show("Успешно подключено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#6
0
    /// <summary>
    /// Start Recording
    /// </summary>
    /// <param name="recordAudio">Record Audio</param>
    /// <returns>Successful</returns>
    public bool Start(bool recordAudio = false)
    {
        if (isRecording)
            return false;

        // Reset
        status = "Pending";
        frames = 0;

        // Create Temporary Directory
        CreateTemporaryPath();

        // Setup Audio Recording
        if (recordAudio)
        {
            this.recordAudio = recordAudio;
            audioSource = new WasapiLoopbackCapture();
            audioSource.DataAvailable += new EventHandler<WaveInEventArgs>(WriteAudio);
            audioFile = new WaveFileWriter(Path.Combine(tempPath, "audio.wav"), audioSource.WaveFormat);

            audioSource.StartRecording();
        }

        // Start Timers
        StartTimers();

        status = "Recording";
        isRecording = true;
        return isRecording;
    }