StudioSoundSession

@RequiresApi(value = VERSION_CODES.O_MR1)
public interface StudioSoundSession


An active session for processing audio with the Studio Sound API.

A session manages the streaming pipeline for isolating audio components (such as speech, crowd, and background noise) from raw PCM audio. The pipeline uses an asynchronous buffer queue:

  1. Register a StudioSoundCallback with registerCallback to receive processed results.
  2. Call dequeueInputBuffer to obtain an available shared input buffer.
  3. Write raw PCM audio data matching getAudioFormat into the buffer.
  4. Submit the filled buffer for processing via queueInputBuffer.
  5. Receive isolated output tracks asynchronously in onProcessed.
  6. When audio processing is complete, call release to release session resources.

Summary

Public methods

abstract void

Cancels any ongoing audio processing and resets the processing pipeline state.

abstract @Nullable ByteBuffer

Dequeues an input buffer to be populated with audio data.

abstract AudioFormat

Returns the AudioFormat configured for this session.

abstract void

Queues a previously dequeued input buffer filled with audio data for processing.

abstract void

Registers a StudioSoundCallback to receive audio processing results, errors, and cancellation events.

abstract void

Releases this session and frees all underlying native, shared memory, and IPC resources.

abstract void

Unregisters the currently registered StudioSoundCallback.

Public methods

cancel

abstract void cancel()

Cancels any ongoing audio processing and resets the processing pipeline state.

If a StudioSoundCallback is registered, its onCancelled method is invoked with CANCELED.

dequeueInputBuffer

abstract @Nullable ByteBuffer dequeueInputBuffer()

Dequeues an input buffer to be populated with audio data.

Only one buffer may be dequeued at a time. Subsequent calls to dequeueInputBuffer() before calling queueInputBuffer with the previously dequeued buffer will return null.

Once onProcessed is called for the previously queued buffer, this method returns a buffer, so the next buffer can be dequeued from inside that callback.

The buffer capacity is sized to hold up to 2 minutes of PCM audio based on the session's AudioFormat.

Returns
@Nullable ByteBuffer

a ByteBuffer ready to receive input audio data, or null if no buffer is currently available

getAudioFormat

abstract AudioFormat getAudioFormat()

Returns the AudioFormat configured for this session.

Both input and output audio data in this session must adhere to this format.

Returns
AudioFormat

the AudioFormat used for processing in this session

queueInputBuffer

abstract void queueInputBuffer(ByteBuffer buffer)

Queues a previously dequeued input buffer filled with audio data for processing.

This method must be called with the exact ByteBuffer instance returned by the most recent call to dequeueInputBuffer. Once queued, the caller should not modify the buffer contents until it is dequeued again.

Parameters
ByteBuffer buffer

the ByteBuffer containing the audio data to process; must be the instance returned by the previous dequeueInputBuffer call

registerCallback

abstract void registerCallback(Executor executor, StudioSoundCallback callback)

Registers a StudioSoundCallback to receive audio processing results, errors, and cancellation events.

Parameters
Executor executor

the Executor on which the callback methods will be invoked

StudioSoundCallback callback

the StudioSoundCallback to receive processing events

release

abstract void release()

Releases this session and frees all underlying native, shared memory, and IPC resources.

The session cannot be reused after release. Any subsequent calls on a released session will fail.

unregisterCallback

abstract void unregisterCallback()

Unregisters the currently registered StudioSoundCallback.

Subsequent audio processing results will not be dispatched.