/// <summary> /// Starts recoring audio. /// </summary> /// <param name="micDevice">MMDevice for microphone to record.</param> /// <param name="speakDevice">MMdevice for speakers to record.</param> public void startRecording(MMDevice micDevice, MMDevice speakDevice) { window.lockForRecording(); playSilence(); makeFileNames(); micCapture = new WasapiCapture(); micCapture.Device = micDevice; micCapture.Initialize(); speakCapture = new WasapiLoopbackCapture(); speakCapture.Device = speakDevice; speakCapture.Initialize(); micSource = new SoundInSource(micCapture); micWriter = MediaFoundationEncoder.CreateMP3Encoder(micSource.WaveFormat, micFileName); byte[] micBuffer = new byte[micSource.WaveFormat.BytesPerSecond]; micSource.DataAvailable += (s, e) => { int read = micSource.Read(micBuffer, 0, micBuffer.Length); micWriter.Write(micBuffer, 0, read); }; micCapture.Start(); speakSource = new SoundInSource(speakCapture); speakWriter = MediaFoundationEncoder.CreateMP3Encoder(speakSource.WaveFormat, speakFileName); byte[] speakBuffer = new byte[speakSource.WaveFormat.BytesPerSecond]; speakSource.DataAvailable += (s, e) => { int read = speakSource.Read(speakBuffer, 0, speakBuffer.Length); speakWriter.Write(speakBuffer, 0, read); }; speakCapture.Start(); }
public void startRecording(MMDevice micDevice, MMDevice speakDevice) { window.lockForRecording(); playSilence(); makeFileNames(); micCapture = new WasapiCapture(micDevice); speakCapture = new WasapiLoopbackCapture(speakDevice); micWriter = new WaveFileWriter(micFileName, micCapture.WaveFormat); speakWriter = new WaveFileWriter(speakFileName, speakCapture.WaveFormat); micCapture.DataAvailable += (s, e) => { micWriter.Write(e.Buffer, 0, e.BytesRecorded); }; speakCapture.DataAvailable += (s, e) => { speakWriter.Write(e.Buffer, 0, e.BytesRecorded); }; micCapture.StartRecording(); speakCapture.StartRecording(); }