Browse SDKs · Android
Platform
SDKsAndroid

Create an audio message

Create an audio message from a path relative to the SDK data directory.

Copy

Construct a voice or audio message object from a relative path within the SDK initialization data directory. When sending via Send a message, the SDK automatically uploads the audio file.

Code example

String soundPath = "sounds/voice_001.m4a";
long durationSeconds = 12L; // Duration: 12 seconds

Message message = OpenIMClient.getInstance().messageManager.createSoundMessage(
    soundPath,
    durationSeconds
);

Parameters

ParameterTypeRequiredDescription
soundPathStringYesAudio file path relative to the SDK initialization data directory.
durationlongYesAudio playback duration in seconds.

Return value

Returns the created Message object with contentType set to MessageType.VOICE.

State changes after the call

  1. Local initialization: Initializes the local Message structure without starting network uploads.
  2. Transmission: Call Send a message to deliver the audio message. For absolute local filesystem paths, see Create an audio message from a local path.