static void Main(string[] args) { string[] argReceived = args[0].Split('-'); for (int i = 0; i < argReceived.Length; i++) { Debug.WriteLine(i + " : = " + argReceived[i]); } Thread captureAudio; if (argReceived[0] == "start") { captureAudio = new Thread(new ThreadStart(wavtomp3)); captureAudio.Start(); } } static void wavtomp3() { // Start recording from loopback waveIn = new WasapiLoopbackCapture(); // MessageBox.Show("Sample Rate=" + waveIn.WaveFormat.SampleRate.ToString()); string fname = DateTime.Now.Ticks.ToString(); wri = new LameMP3FileWriter(fname, waveIn.WaveFormat, 44); waveIn.DataAvailable += waveIn_DataAvailable; waveIn.RecordingStopped += waveIn_RecordingStopped; waveIn.StartRecording(); } static void waveIn_RecordingStopped(object sender, StoppedEventArgs e) { if (waveIn != null) // working around problem with double raising of RecordingStopped { waveIn.Dispose(); waveIn = null; } if (wri != null) { wri.Close(); wri = null; } } static void waveIn_DataAvailable(object sender, WaveInEventArgs e) { if (wri != null) if (e.BytesRecorded == 0) { wri.Write(e.Buffer, 0, 12800); Debug.WriteLine("Adding Silence To File No Sound is playing"); } else if (e.BytesRecorded > 0) { wri.Write(e.Buffer, 0, e.BytesRecorded); Debug.WriteLine("Sound Playing From Sound Card and recording"); } Debug.WriteLine("bytes record=" + e.BytesRecorded); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)