SilenceSkippingAudioProcessor


@UnstableApi
class SilenceSkippingAudioProcessor : BaseAudioProcessor


An AudioProcessor that skips silence in the input stream. Input and output are 16-bit PCM.

Summary

Constants

const Long

Default maximum silence to keep in microseconds.

const Long

Default minimum duration of audio that must be below silenceThresholdLevel before silence starts being trimmed.

const Int

Default volume percentage to keep.

const Long

This property is deprecated.

Specify silence behaviour via silenceRetentionRatio instead.

const Float

Default fraction of the original silence to keep.

const Short

Default absolute level below which an individual PCM sample is classified as silent.

Public constructors

Creates a new silence skipping audio processor.

SilenceSkippingAudioProcessor(
    minimumSilenceDurationUs: Long,
    paddingSilenceUs: Long,
    silenceThresholdLevel: Short
)

This function is deprecated.

Use SilenceSkippingAudioProcessor instead.

SilenceSkippingAudioProcessor(
    minimumSilenceDurationUs: Long,
    silenceRetentionRatio: Float,
    maxSilenceToKeepDurationUs: Long,
    minVolumeToKeepPercentageWhenMuting: Int,
    silenceThresholdLevel: Short
)

Creates a new silence trimming audio processor.

Public functions

Boolean

Returns whether the processor is configured and will process input buffers.

Unit

Called when the processor is flushed, directly or as part of resetting.

Unit

Called when the end-of-stream is queued to the processor.

Unit

Called when the processor is reset.

Unit
queueInput(inputBuffer: ByteBuffer!)

Queues audio data between the position and limit of the inputBuffer for processing.

Unit
setEnabled(enabled: Boolean)

Sets whether to shorten silence in the input.

Protected functions

AudioProcessor.AudioFormat!

Called when the processor is configured for a new input format.

Public properties

Long

Inherited Constants

From androidx.media3.common.audio.AudioProcessor
const ByteBuffer!

An empty, direct ByteBuffer.

Inherited functions

From androidx.media3.common.audio.AudioProcessor
Long

Returns the expected duration of the output stream when the processor is applied given a input durationUs.

From androidx.media3.common.audio.BaseAudioProcessor
AudioProcessor.AudioFormat!

Configures the processor to process input audio with the specified format.

Unit

Clears any buffered data and pending output.

ByteBuffer!

Returns a buffer containing processed output data between its position and limit.

Boolean

Returns whether the current output buffer has any data remaining.

Boolean

Returns whether this processor will return no more output from getOutput until flush has been called and more input has been queued.

Unit

Queues an end of stream signal.

ByteBuffer!

Replaces the current output buffer with a buffer of at least size bytes and returns it.

Unit

Resets the processor to its unconfigured state, releasing any resources.

Inherited properties

From androidx.media3.common.audio.BaseAudioProcessor
AudioProcessor.AudioFormat!

The current input audio format.

AudioProcessor.AudioFormat!

The current output audio format.

Constants

DEFAULT_MAX_SILENCE_TO_KEEP_DURATION_US

const val DEFAULT_MAX_SILENCE_TO_KEEP_DURATION_US = 2000000: Long

Default maximum silence to keep in microseconds. This maximum is applied after silenceRetentionRatio.

DEFAULT_MINIMUM_SILENCE_DURATION_US

const val DEFAULT_MINIMUM_SILENCE_DURATION_US = 100000: Long

Default minimum duration of audio that must be below silenceThresholdLevel before silence starts being trimmed. Specified in microseconds.

DEFAULT_MIN_VOLUME_TO_KEEP_PERCENTAGE

const val DEFAULT_MIN_VOLUME_TO_KEEP_PERCENTAGE = 10: Int

Default volume percentage to keep.

Even when modifying the volume to a mute state, it is ideal to decrease the volume instead of making the volume zero. Completely silent audio sounds like playback has stopped. While decreased volume sounds like very light background noise at a recording studio.

DEFAULT_PADDING_SILENCE_US

const val DEFAULT_PADDING_SILENCE_US = 20000: Long

DEFAULT_SILENCE_RETENTION_RATIO

const val DEFAULT_SILENCE_RETENTION_RATIO = 0.2f: Float

Default fraction of the original silence to keep. Between [0, 1]. 1 means keep all silence. 0 means remove all silence.

DEFAULT_SILENCE_THRESHOLD_LEVEL

const val DEFAULT_SILENCE_THRESHOLD_LEVEL = 1024: Short

Default absolute level below which an individual PCM sample is classified as silent.

Public constructors

SilenceSkippingAudioProcessor

SilenceSkippingAudioProcessor()

Creates a new silence skipping audio processor.

SilenceSkippingAudioProcessor

SilenceSkippingAudioProcessor(
    minimumSilenceDurationUs: Long,
    paddingSilenceUs: Long,
    silenceThresholdLevel: Short
)

SilenceSkippingAudioProcessor

SilenceSkippingAudioProcessor(
    minimumSilenceDurationUs: Long,
    silenceRetentionRatio: Float,
    maxSilenceToKeepDurationUs: Long,
    minVolumeToKeepPercentageWhenMuting: Int,
    silenceThresholdLevel: Short
)

Creates a new silence trimming audio processor.

Parameters
minimumSilenceDurationUs: Long

Duration of audio that must be below silenceThresholdLevel before silence starts being trimmed, in microseconds.

silenceRetentionRatio: Float

Fraction of the original silence to keep. Between [0, 1]. 1 means keep all silence. 0 means remove all silence.

maxSilenceToKeepDurationUs: Long

Maximum silence to keep in microseconds. This maximum is applied after silenceRetentionRatio.

minVolumeToKeepPercentageWhenMuting: Int

Volume percentage to keep. Even when modifying the volume to a mute state, it is ideal to decrease the volume instead of making the volume zero. Completely silent audio sounds like playback has stopped. While decreased volume sounds like very light background noise from a recording studio.

silenceThresholdLevel: Short

Absolute level below which an individual PCM sample is classified as silent.

Public functions

isActive

fun isActive(): Boolean

Returns whether the processor is configured and will process input buffers.

onFlush

fun onFlush(): Unit

Called when the processor is flushed, directly or as part of resetting.

onQueueEndOfStream

fun onQueueEndOfStream(): Unit

Called when the end-of-stream is queued to the processor.

onReset

fun onReset(): Unit

Called when the processor is reset.

queueInput

fun queueInput(inputBuffer: ByteBuffer!): Unit

Queues audio data between the position and limit of the inputBuffer for processing. After calling this method, processed output may be available via getOutput. Calling queueInput(ByteBuffer) again invalidates any pending output.

Parameters
inputBuffer: ByteBuffer!

The input buffer to process. It must be a direct byte buffer with native byte order. Its contents are treated as read-only. Its position will be advanced by the number of bytes consumed (which may be zero). The caller retains ownership of the provided buffer.

setEnabled

fun setEnabled(enabled: Boolean): Unit

Sets whether to shorten silence in the input. This method may only be called after draining data through the processor. The value returned by isActive may change, and the processor must be flushed before queueing more data.

Parameters
enabled: Boolean

Whether to shorten silence in the input.

Protected functions

onConfigure

protected fun onConfigure(inputAudioFormat: AudioProcessor.AudioFormat!): AudioProcessor.AudioFormat!

Called when the processor is configured for a new input format.

Public properties

skippedFrames

val skippedFramesLong