Audio Output
.NET Quick Start
Platforms
- Linux (x86_64)
- macOS (x86_64, arm64)
- Windows (x86_64)
- Raspberry Pi (3, 4, 5)
Requirements
.NET Framework 4.6.1+ / .NET Standard 2.0+ / .NET Core 3.0+:
- Windows (x86_64)
.NET Standard 2.0+ / .NET Core 3.0+:
- Linux (x86_64)
- macOS (x86_64)
.NET Core 3.0+:
- Raspberry Pi (3, 4, 5)
.NET 6.0+:
- macOS (arm64)
Quick Start
Setup
Install .NET.
Install the PvSpeaker NuGet package in Visual Studio or using the .NET CLI:
Usage
Initialize and start PvSpeaker
:
Write PCM data to the speaker:
Note: the Write()
method only writes as much PCM data as the internal circular buffer can currently fit, and returns the number of samples that were successfully written.
When all frames have been written, run Flush()
to wait for all buffered PCM data (i.e. previously buffered via Write()
) to be played:
Note: calling Flush()
with PCM data as an argument will both write that PCM data and wait for all buffered PCM data to finish.
To stop the audio output device, run Stop()
:
Once you are done, free the resources acquired by PvSpeaker. You do not have to call Stop()
before Dispose()
:
To have resources freed immediately after use without explicitly calling the Dispose()
function, wrap PvSpeaker
in a using
statement:
Selecting an Audio Device
To print a list of available audio devices:
The index of the device in the returned list can be used in Create()
to select that device for audio playback:
Demo
For the PvSpeaker .NET SDK, we offer a demo application that demonstrates how use PvSpeaker to play audio from an audio file (.wav
).
Setup
- Clone the repository:
- Build the project:
Usage
To show the available audio devices run:
To run the demo, give it a file to play audio from:
You can also select the audio device index to use for playback (use --show_audio_devices
to see options):
For more information about our PvSpeaker demo, head over to our GitHub repository.