🚀 Best-in-class Voice AI!
Build compliant and low-latency AI applications using .NET without sending user data to 3rd party servers.
Start Free

Recording audio from a microphone in .NET or C# applications can be more challenging than it seems. Whether you're building voice-enabled apps, real-time speech-to-text, or accessibility features, capturing clear, high-quality audio in the correct format is crucial.

This guide explains how to record microphone audio in C# and .NET using PvRecorder: a lightweight, cross-platform .NET audio recording library that captures raw PCM audio frames for any speech recognition, voice command, or audio processing workflow.

If you need to play audio in your .NET application, check out PvSpeaker. Refer to the PvSpeaker .NET Quick Start guide and the PvSpeaker .NET API docs for more detailed info.

Recording Audio in .NET with PvRecorder

Before we begin, make sure your system meets the minimum .NET version requirements for your platform:

  • Windows (x86_64): .NET Framework 4.6.1+, .NET Standard 2.0+, or .NET Core 3.0+
  • macOS (x86_64): .NET Standard 2.0+ or .NET Core 3.0+
  • macOS (arm64), Windows (arm64), Linux (x86_64), Raspberry Pi (3, 4, 5): .NET 6.0+

1. Install the NuGet Package

Install the PvRecorder NuGet package:

2. Initialize PvRecorder

Pass in the required frame length for your processing engine or logic. Picovoice engines typically require a frame length of 512:

3. Start Audio Capture

Call Start() to begin recording audio:

4. Capture PCM Audio Frames

After starting the recorder, continuously read audio frames inside a loop:

Each frame is a short[] array containing raw 16-bit PCM samples that you can feed into your audio processing logic, speech recognizer, or write to a file.

5. Stop & Release Resources

To stop recording audio, call Stop(). If you no longer need PvRecorder, call Dispose() to free memory:

Complete .NET Audio Recording Example

Here's a complete .NET console example that records audio from the default microphone, prints the frame length read, and stops on Enter.

This is a simplified example but contains all the essential components to demonstrate audio recording functionality. If you'd like to see a complete working project, check out the PvRecorder .NET Demo on GitHub.

This tutorial uses the following package:

Explore our documentation for more details:

Next Steps

Now that you know how to record audio, you can add the speech recognition features your .NET application needs:

Start Building

Frequently Asked Questions

Can I use PvRecorder to record audio for any .NET application even if I don't use Picovoice on-device voice AI engines?
Yes! PvRecorder is a general-purpose audio recording library that works with any .NET or C# application requiring audio input.
Is audio processing in .NET/C# synchronous with PvRecorder?
Yes! After calling Start(), you can start reading audio frames. You can do it continuously in some kind of loop until a stop condition. Review the "4. Capture PCM Audio Frames" section in the article.
What are the sample rates for PvRecorder .NET?
PvRecorder is optimized for speech recognition, hence uses 16kHz, which is the optimal speech recognition sample rate. If you need different rates for your .NET application, you can resample the audio after capture.