# Audio sample grabber

Media Blocks SDK .Net

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 direction Media type Pins count
Input Uncompressed audio 1
Output Uncompressed audio 1

# The sample pipeline

graph LR;
    UniversalSourceBlock-->AudioSampleGrabberBlock;
    AudioSampleGrabberBlock-->AudioRendererBlock;

# 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.