public AudioStreamHandler() { log = Logger.GetLogger(GetType()); WaveIn = new WasapiLoopbackCapture(); WaveIn.DataAvailable += DataAvailable; WaveIn.RecordingStopped += RecordingStopped; WaveOut = new WaveOut(); WaveOut.Init(new SilentWaveProvider()); }
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; }
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; } }
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(); } }
void waveSource_RecordingStopped(object sender, StoppedEventArgs e) { if (Source != null) { Source.Dispose(); Source = null; } if (File != null) { File.Dispose(); File = null; } }
public WasapiProvider() { // Init Pipes this.recordingStream = new PipeStream(); this.LoopbackMp3Stream = new PipeStream(); this.LoopbackL16Stream = new PipeStream(); // Init Wave Processor thread Thread waveProcessorThread = new Thread(new ThreadStart(this.waveProcessor)) { Priority = ThreadPriority.Highest }; // Init Wasapi Capture this.loopbackWaveIn = new WasapiLoopbackCapture(); this.loopbackWaveIn.DataAvailable += new EventHandler<WaveInEventArgs>(this.loopbackWaveIn_DataAvailable); // Init Raw Wav (16bit) WaveStream rawWave16b = new Wave32To16Stream(new RawSourceWaveStream(this.recordingStream, NAudio.Wave.WaveFormat.CreateIeeeFloatWaveFormat(this.loopbackWaveIn.WaveFormat.SampleRate, this.loopbackWaveIn.WaveFormat.Channels))); // Convert Raw Wav to PCM with audio format in settings var audioFormat = AudioSettings.GetAudioFormat(); if (rawWave16b.WaveFormat.SampleRate == audioFormat.SampleRate && rawWave16b.WaveFormat.BitsPerSample == audioFormat.BitsPerSample && rawWave16b.WaveFormat.Channels == audioFormat.Channels) { // No conversion ! this.rawConvertedStream = null; this.pcmStream = WaveFormatConversionStream.CreatePcmStream(rawWave16b); } else { // Resampler this.rawConvertedStream = new WaveProviderToWaveStream(new MediaFoundationResampler(rawWave16b, audioFormat)); this.pcmStream = WaveFormatConversionStream.CreatePcmStream(rawConvertedStream); } // Init MP3 Encoder this.mp3Writer = new LameMP3FileWriter(this.LoopbackMp3Stream, pcmStream.WaveFormat, AudioSettings.GetMP3Bitrate()); // Start Recording this.loopbackWaveIn.StartRecording(); // Start Wave Processor thread waveProcessorThread.Start(); }
///////////////////////////////////////////////////////////////////////////События формы /// <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(); }
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); } }
/// <summary> /// Initialises a new instance of the WASAPI capture class /// </summary> // Token: 0x060007EA RID: 2026 RVA: 0x00017272 File Offset: 0x00015472 public WasapiLoopbackCapture() : this(WasapiLoopbackCapture.GetDefaultLoopbackCaptureDevice()) { }
private void Init() { _capture = new WasapiLoopbackCapture(); _capture.DataAvailable += _capture_DataAvailable; _capture.RecordingStopped += _capture_RecordingStopped; }
/// <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; }
/// <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; }
/// <summary> /// Set Parameters to WasapiLoopCapture /// </summary> private void InitializeWasapiLoopCapture() { _wasapiLoopback = new WasapiLoopbackCapture(); _wasapiLoopback.DataAvailable += WasapiLoopbackOnDataAvailable; }
public Recorder() { waveIn = new WasapiLoopbackCapture(); waveIn.DataAvailable += InputBufferToFileCallback; }