PvRecorder is an easy-to-use, cross-platform audio recorder designed for real-time speech audio processing. It allows developers access to an audio device's input stream, broken up into data frames of a given size.
- .NET 8.0
Platform compatible with .NET Framework 4.6.1+:
- Windows (x86_64)
Platforms compatible with .NET Core 2.0+:
- macOS (x86_64)
- Windows (x86_64)
Platform compatible with .NET 6.0+:
-
Raspberry Pi:
- 3 (32 and 64 bit)
- 4 (32 and 64 bit)
- 5 (32 and 64 bit)
-
Linux (x86_64)
-
Windows (arm64)
-
macOS (arm64)
You can install the latest version of PvRecorder by adding the latest PvRecorder Nuget package in Visual Studio or using by using the .NET CLI:
dotnet add package PvRecorder
Initialize and begin recording:
using Pv;
PvRecorder recorder = PvRecorder.Create(frameLength: 512);
recorder.Start();
Read frames of audio:
while (recorder.IsRecording)
{
short[] frame = recorder.Read();
// process audio frame
}
To stop recording:
recorder.Stop();
Once you are done, free the resources acquired by PvRecorder. You do not have to call Stop()
before Dispose()
:
recorder.Dispose();
To have resources freed immediately after use without explicitly calling the Dispose()
function, wrap PvRecorder
in a using
statement:
using (PvRecorder recorder = PvRecorder.Create(frameLength: 512)) {
// PvRecorder usage
}
To print a list of available audio devices:
string[] devices = PvRecorder.GetAudioDevices();
The index of the device in the returned list can be used in Create()
to select that device for audio capture:
PvRecorder recorder = PvRecorder.Create(
frameLength: 512,
deviceIndex: 2);
The PvRecorder .NET demo is a .NET command-line application that demonstrates how to use PvRecorder to record audio to a file.