Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your <code>recordButton_Click</code> code isn't recording, it's piping data from a <code>WaveIn</code> to a <code>WaveOut</code>, which will play the data coming from your source (microphone) directly to the output (speakers). It doesn't retain that data for later use, it just pipes it from one to the other. If you want to subsequently save that data to disk, you need to buffer it yourself.</p> <p>The <code>saveResponse_Click</code> on the other hand is <em>starting</em> the direct recording of data from the microphone to a wave file on disk. If you click your <code>Save Response</code> button, wait for a bit, then click your <code>Stop</code> button, you should get a recorded wave file.</p> <p>If you want to record directly to disk, this is fine. If you want to record to memory, then optionally write to disk, then you need to save the data as it comes in. Perhaps use a memory stream to hold the data while recording, then write that to the <code>WaveFileWriter</code> when it comes time to save the file.</p> <hr> <p>Here's the code I used for testing direct recording to a wave file on disk:</p> <pre><code>public WaveIn waveSource = null; public WaveFileWriter waveFile = null; private void StartBtn_Click(object sender, EventArgs e) { StartBtn.Enabled = false; StopBtn.Enabled = true; waveSource = new WaveIn(); waveSource.WaveFormat = new WaveFormat(44100, 1); waveSource.DataAvailable += new EventHandler&lt;WaveInEventArgs&gt;(waveSource_DataAvailable); waveSource.RecordingStopped += new EventHandler&lt;StoppedEventArgs&gt;(waveSource_RecordingStopped); waveFile = new WaveFileWriter(@"C:\Temp\Test0001.wav", waveSource.WaveFormat); waveSource.StartRecording(); } private void StopBtn_Click(object sender, EventArgs e) { StopBtn.Enabled = false; waveSource.StopRecording(); } void waveSource_DataAvailable(object sender, WaveInEventArgs e) { if (waveFile != null) { waveFile.Write(e.Buffer, 0, e.BytesRecorded); waveFile.Flush(); } } void waveSource_RecordingStopped(object sender, StoppedEventArgs e) { if (waveSource != null) { waveSource.Dispose(); waveSource = null; } if (waveFile != null) { waveFile.Dispose(); waveFile = null; } StartBtn.Enabled = true; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload