Table of Contents

Class SilenceDetectorBlock

Namespace
VisioForge.Core.MediaBlocks.AudioProcessing
Assembly
VisioForge.Core.dll

Silence detector block that analyzes uncompressed audio streams to detect periods of silence based on a configurable threshold level. This block monitors audio in real-time, identifies when audio levels drop below the specified threshold, and tracks the duration of silence periods. Features include real-time callbacks for silence start/end events, collection of all silence periods with precise timestamps, and JSON export functionality for detailed analysis and reporting. Essential for audio editing applications, speech processing, podcast production, and any scenario requiring automatic silence detection and analysis. Implements the VisioForge.Core.MediaBlocks.MediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals. Implements the IDisposable.

public class SilenceDetectorBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals

Inheritance

Implements

Inherited Members

Extension Methods

Constructors

SilenceDetectorBlock(double)

Initializes a new instance of the VisioForge.Core.MediaBlocks.AudioProcessing.SilenceDetectorBlock class with default silence detection settings suitable for general audio analysis.

public SilenceDetectorBlock(double thresholdDb = -40)

Parameters

thresholdDb double

The silence detection threshold in decibels (dB). Default: -40.0 dB.

Properties

Input

Gets the primary input pad for audio silence detection.

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets all input pads for this silence detector block. This block has a single input for audio analysis.

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

Output

Gets the primary output pad providing audio passthrough after silence detection.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets all output pads for this silence detector block. This block has a single output for passthrough audio.

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

ThresholdDb

Gets or sets the silence detection threshold in decibels (dB). Audio levels below this threshold will be considered as silence. Values are typically negative (e.g., -40.0 dB for fairly quiet audio, -60.0 dB for very quiet). Lower (more negative) values are less sensitive and require quieter audio to trigger silence detection. Higher (less negative) values are more sensitive and will detect silence at louder levels.

public double ThresholdDb { get; set; }

Property Value

double

Type

Gets the type of this media block.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

Methods

Build()

Constructs and initializes the silence detector and its associated GStreamer elements. This method creates the detector with the specified threshold, establishes input and output pads, sets up event forwarding, and prepares the block for analyzing audio streams.

public override bool Build()

Returns

bool

true if the detector was successfully built and configured; false if initialization failed.

CleanUp()

Releases all resources and performs cleanup operations for this silence detector block. This method disposes of the GStreamer elements and resets the build state.

public void CleanUp()

ClearSilencePeriods()

Clears all detected silence periods from the internal list. Useful when reusing the detector for multiple audio files or when resetting detection state between different processing operations.

public void ClearSilencePeriods()

Dispose(bool)

Releases unmanaged and - optionally - managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

ExportSilencePeriodsJson(bool)

Exports all detected silence periods to a JSON string. The JSON format includes an array of silence periods, each with start time, end time, and duration in various formats (milliseconds, seconds, and formatted strings). Suitable for saving to file, sending to APIs, or further processing by other tools.

public string ExportSilencePeriodsJson(bool prettyPrint = true)

Parameters

prettyPrint bool

If true, formats the JSON with indentation for readability. Default: true.

Returns

string

A JSON string containing all detected silence periods with detailed timing information.

FinalizeSilencePeriods(TimeSpan)

Finalizes any in-progress silence period and returns all detected periods. This should be called when the audio stream ends to ensure the final silence period (if the stream ended during silence) is properly recorded and included in the results.

public List<SilencePeriod> FinalizeSilencePeriods(TimeSpan endTime)

Parameters

endTime TimeSpan

The timestamp when the audio stream ended.

Returns

List<SilencePeriod>

A list of all detected silence periods including any finalized period.

GetCore()

Gets the core BaseElement wrapper that provides additional functionality around the GStreamer silence detector element.

public BaseElement GetCore()

Returns

BaseElement

The BaseElement wrapper instance that encapsulates the GStreamer silence detector.

GetElement()

Gets the underlying GStreamer element that performs the silence detection.

public Element GetElement()

Returns

Element

The GStreamer Element instance representing the silence detector.

GetSilencePeriods()

Gets all detected silence periods since the detector was started. Each period includes precise start time, end time, and duration information. Useful for post-processing analysis, report generation, or audio editing operations.

public List<SilencePeriod> GetSilencePeriods()

Returns

List<SilencePeriod>

A list of all detected silence periods with timing information.

IsAvailable()

Determines whether this media block is available. Checks if the required GStreamer level plugin is installed and accessible.

public static bool IsAvailable()

Returns

bool

true if the level element is available; otherwise, false.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Associates this silence detector block with a pipeline and initializes its internal context. This method is called internally when the block is added to a pipeline.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The MediaBlocksPipeline instance that will manage this block.

OnSilenceEnded

This event occurs when a silence period ends (audio level rises above the threshold). Provides notification with timestamp, audio level, and complete silence period information including start time, end time, and duration for recording or analysis purposes.

public event EventHandler<SilenceDetectionEventArgs> OnSilenceEnded

Event Type

EventHandler<SilenceDetectionEventArgs>

OnSilenceStarted

This event occurs when a silence period starts (audio level drops below the threshold). Provides immediate notification with timestamp and audio level information, enabling applications to respond in real-time to silence detection.

public event EventHandler<SilenceDetectionEventArgs> OnSilenceStarted

Event Type

EventHandler<SilenceDetectionEventArgs>

See Also