Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recording on WasapiCapture,a lot of noise. #473

Open
BigQ517 opened this issue Aug 22, 2022 · 4 comments
Open

Recording on WasapiCapture,a lot of noise. #473

BigQ517 opened this issue Aug 22, 2022 · 4 comments

Comments

@BigQ517
Copy link

BigQ517 commented Aug 22, 2022

I`m recording on WasapiCapture , sampleRate:16000, bits:16 and channels:1. There is a lot of noise when the sound is high. Is there a good solution?

@BigQ517
Copy link
Author

BigQ517 commented Aug 23, 2022

this.soundIn = new WasapiCapture();
            if (currentDevice != null)
            {
                this.soundIn.Device = currentDevice;
            }

            soundIn.Initialize();
            SoundInSource soundInSource = new SoundInSource(soundIn) { FillWithZeros = false };
            convertedSource = soundInSource
             .ChangeSampleRate(16000) // sample rate
             .ToSampleSource()
             .ToWaveSource(16); //bits per sample

            convertedSource =  convertedSource.ToMono() ;
            soundInSource.DataAvailable += OnDataAviailable;
            soundIn.Stopped += OnRecordingStopped;
            soundIn.Start();

@eugeneYz
Copy link

eugeneYz commented Mar 6, 2024

Me too. The recorded audio lasted a long time, but I didn't record it that long and it was all noise

private WasapiCapture capture;
private WaveWriter writer;

public void StartRecording(string fileName)
{
    capture = new WasapiCapture();
    capture.Initialize();

    // 设置录音格式
    var waveFormat = new WaveFormat(16000, 16, 1); // 16000Hz, 16bit, Mono

    writer = new WaveWriter(fileName, waveFormat);

    capture.DataAvailable += (s, e) =>
    {
        // 将捕获的音频数据写入文件
        writer.Write(e.Data, e.Offset, e.ByteCount);
    };

    capture.Start();
}

public void StopRecording()
{
    capture.Stop();
    capture.Dispose();
    writer.Dispose();
}

@filoe
Copy link
Owner

filoe commented Mar 6, 2024 via email

@eugeneYz
Copy link

eugeneYz commented Mar 14, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants