Skip to main content

Audio sample grabber

The audio sample grabber calls an event for each audio frame. You can save or process the received audio frame.

Block info

Name: AudioSampleGrabberBlock.

Pin directionMedia typePins count
InputUncompressed audio1
OutputUncompressed audio1

The sample pipeline

Sample code

var pipeline = new MediaBlocksPipeline();

var filename = "test.mp3";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var audioSG = new AudioSampleGrabberBlock();
audioSG.OnAudioFrameBuffer += AudioSG_OnAudioFrameBuffer;
pipeline.Connect(fileSource.AudioOutput, audioSG.Input);

var audioRenderer = new AudioRendererBlock();
pipeline.Connect(audioSG.Output, audioRenderer.Input);

await pipeline.StartAsync();

private void AudioSG_OnAudioFrameBuffer(object sender, AudioFrameBufferEventArgs e)
{
// save or process the audio frame
}

Platforms

Windows, macOS, Linux, iOS, Android.