ALSA (Advanced Linux Sound Architecture) implemented by .NET Core. The required minimum version of .NET Core is 2.1. Theoretically support all Linux devices running .NET Core (.NET Core JIT depends on ARMv7 instructions).
sudo apt-get install libasound2-dev
- Create a
SoundConnectionSettings
and set the parameters for recording (Optional).SoundConnectionSettings settings = new SoundConnectionSettings();
- Create a communications channel to a sound device.
using SoundDevice device = SoundDevice.Create(settings);
- Play a WAV file
device.Play("/home/pi/music.wav");
- Record some sounds
// Record for 10 seconds and save in "/home/pi/record.wav" device.Record(10, "/home/pi/record.wav");
cd Alsa.Samples
dotnet publish -c release -r linux-arm -o YOUR_FOLDER
sudo dotnet YOUR_FOLDER/Alsa.Samples.dll
Before build docker image, you need to modify SDK, runtime and apt sources(in China) to adapt to the corresponding Linux platform.
docker build -t alsa-sample -f Dockerfile .
docker run --rm -it --device /dev/snd -v /home/pi:/home/pi alsa-sample