Skip to content

Latest commit

 

History

History

dotnet

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

PvRecorder Binding for .NET

PvRecorder

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.

Requirements

  • .NET 6.0

Compatibility

Platform compatible with .NET Framework 4.6.1+:

  • Windows (x86_64)

Platforms compatible with .NET Core 2.0+:

  • Linux (x86_64)
  • macOS (x86_64)
  • Windows (x86_64)

Platforms compatible with .NET Core 3.0+:

  • Raspberry Pi:
    • 2
    • 3 (32 and 64 bit)
    • 4 (32 and 64 bit)
    • 5 (32 and 64 bit)
  • NVIDIA Jetson Nano
  • BeagleBone

Platform compatible with .NET 6.0+:

  • macOS (arm64)

Installation

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

Usage

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
}

Selecting an Audio Device

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);

Demo

The PvRecorder .NET demo is a .NET command-line application that demonstrates how to use PvRecorder to record audio to a file.