0

What is working - Save file

What is not: - Audio file is blank (as a length but no audible sound, aka sound is blank) Edit (for clarity): The file weight is not 0.

Already implemented a solution with winmm.dll but looking for something better than 16-bit quality. Already using NAudio wrapper for libmp3lame dll so using NAudio is a viable option.

public void Start()
        {
            if(this.isInitialized)
            {
                string outputFilePath = "...";
                this.capture = new NAudio.Wave.WasapiLoopbackCapture();
                this.writer = new NAudio.Wave.WaveFileWriter(outputFilePath, this.capture.WaveFormat);

                this.capture.DataAvailable += (s, a) =>
                {
                    this.writer.Write(a.Buffer, 0, a.BytesRecorded);
                };

                this.capture.RecordingStopped += (s, a) =>
                {
                    this.writer.Dispose();
                    this.writer = null;
                    this.capture.Dispose();
                };

                this.capture.StartRecording();
            }


        }

        public void StopAndSave()
        {
            if(this.isInitialized)
            {
                this.capture.StopRecording();
            }
        }

Expected: to record audio in a WAV audio file format

this.isInitialized check for path and file naming convention. Because the file save to expected location did not added the code. This code part is working as expected.

Note - using NAudio 1.8.5 - target system is Win10 x64 pro

  • 1
    "What is not: - Audio file is blank (as a length but no audible sound, aka sound is blank)" doesn't make much sense. Are you saying that the file contains data (it's not 0 bytes in length) but the data contains no sound? –  Jan 03 '19 at 20:09
  • 1
    @Will Correct. I updated my question to reflect that –  Jan 03 '19 at 20:10
  • 1
    Have you verified via another sound recording application that your computer is actually capturing sound from the source you believe it is? –  Jan 03 '19 at 20:14
  • 1
    @Will Yes. Sound recording capability have been verified. I implemented a solution using winmm.dll. I was able to capture audio and play it back. I also troubleshoot recording device on target machine to confirm the recording device is working properly. –  Jan 03 '19 at 20:16
  • 1
    @Will Tomorrow I will test with an analog recording device. I suspect the problem could be because the recording device is connected trough USB, which might introduce complexities. –  Jan 03 '19 at 20:23
  • 1
    Did you try to create and use a WaveIn object with a proper input device id? You can get the number of available WaveIn devices with WaveIn.DeviceCount. – NthDeveloper Jan 03 '19 at 21:59
  • @NthDeveloper it is my understanding WasapiLoopbackCapture take no device argument in WASAPI mode. Anyway I tried it and it crashed immediatly. Looking up HRESULT error messsage on SO point out to the same understanding. Do I understand it wrong? –  Jan 04 '19 at 15:25
  • @Will I tried with analog microphone with the same result as with the USB microphone –  Jan 04 '19 at 15:26
  • I'm starting to wondering if there are any real advantage between 16-bit and 24-bit in regard of voice quality because in the end the file with be converted to mp3 anyway. What do you think? –  Jan 04 '19 at 15:27
  • @NthDeveloper here is the link I forgot to add to my previous comment addressed to you https://stackoverflow.com/a/24569799 –  Jan 04 '19 at 15:34

1 Answers1

1

You are using WasapiLoopbackCapture which attempts to capture audio being played on the computer. If you meant to capture an input device (like a microphone), you should use WasapiCapture instead.

Mark Heath
  • 48,273
  • 29
  • 137
  • 194