SDKsHarmonyOSEnterprise
Create voice message from local file
Create a voice message from local audio file paths accessible to the application.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
soundPath | string | Yes | Local filesystem path to the audio file readable by the native SDK. |
duration | number | Yes | Audio duration in seconds. |
Return value
Returns a Promise resolving to CreateSoundMessageResp:
| Property | Type | Description |
|---|---|---|
message | IMMessage | Locally 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.
Was this page helpful?