Ejemplo n.º 1
0
        static void Main()
        {
            // create virtual interface to system default audio device
            using var alsaDevice = AlsaDeviceBuilder.Create(new SoundDeviceSettings());

            // provide a wav stream
            using var inputStream = new FileStream("example.wav", FileMode.Open, FileAccess.Read, FileShare.Read);

            // play on the device
            alsaDevice.Play(inputStream);

            // alternative: directly play a wav file
            // alsaDevice.Play("example.wav");
        }
Ejemplo n.º 2
0
        static void Main()
        {
            // create virtual interface to system default audio device
            using var alsaDevice = AlsaDeviceBuilder.Create(new SoundDeviceSettings());

            // set some mixer values
            alsaDevice.RecordingVolume = 100;
            alsaDevice.PlaybackVolume  = 45;

            // record 10s of audio
            alsaDevice.Record(10, "output.wav");

            // play recording back to device
            alsaDevice.Play("output.wav");
        }
Ejemplo n.º 3
0
        static void Main()
        {
            // create virtual interface to system default audio device
            using var alsaDevice = AlsaDeviceBuilder.Create(new SoundDeviceSettings());

            // create stream to hold recorded data - will be pcm data including wav header
            using var outputStream = new MemoryStream();

            // create a cancellation token to stop recording after 10s
            using var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));

            // actually record
            alsaDevice.Record(outputStream, tokenSource.Token);

            // alternative: record for 10s directly to file
            //alsaDevice.Record(10, "output.wav");
        }
Ejemplo n.º 4
0
        static void Main()
        {
            // create a config for your audio hardware setup
            var config = new SoundDeviceSettings
            {
                RecordingDeviceName = "hw:recording01", // alsa name of recording device. use arecord -L for a list of available devices. "default" for systems default
                PlaybackDeviceName  = "hw:playback01",  // alsa name of playback device. use aplay -L for a list of available devices. "default" for systems default
                MixerDeviceName     = "hw:mixer01",     // alsa name of mixer device. ensure your device actually supports this. some might not have volume channels etc.

                RecordingBitsPerSample = 16,            // bit depth of recorded audio data. check your devices capabilities on values to set here. default is 16
                RecordingChannels      = 2,             // number of audio channels to record. default is 2
                RecordingSampleRate    = 8000           // number of samples per second of the recorded audio data. check your device on values to set here. default is 8000 even though this sounds terrible
            };

            // create virtual interface to use your config
            using var alsaDevice = AlsaDeviceBuilder.Create(config);

            // do something with your device e.g. record and play something
            // alsaDevice.Record(10, "output.wav");
            // alsaDevice.Play("output.wav");
        }