Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create voice message from local file

Create a voice message from local audio file paths accessible to the application.

Copy

Creates a voice audio message using a local audio recording path.

Code example

import sdk, { CreateSoundMessageReq, CreateSoundMessageResp } from '@openimsdk/imsdk';

const request: CreateSoundMessageReq = {
  soundPath: audioPath,
  duration: 12,
};
const response: CreateSoundMessageResp = await sdk.createSoundMessage(request);
const message = response.message;

Parameters

ParameterTypeRequiredDescription
soundPathstringYesLocal filesystem path to the audio file readable by the native SDK.
durationnumberYesAudio duration in seconds.

Return value

Returns a Promise resolving to CreateSoundMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated voice message object.

State changes after the call

soundPath must be accessible to the native SDK, and duration is expressed in seconds. Temporary paths returned by recorder components may be deleted by the operating system; copy audio files into a persistent sandbox path if sending is delayed. Promise resolution confirms local creation; call Send message to initiate upload and dispatch.