Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create voice message from URL

Create a voice audio message from pre-uploaded remote audio resource metadata.

Copy

Creates a voice audio message using pre-uploaded remote audio metadata.

Code example

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

const request: CreateSoundMessageByURLReq = {
  uuid: uploaded.uuid,
  soundPath: '',
  sourceURL: uploaded.url,
  dataSize: uploaded.size,
  duration: 12,
  soundType: 'audio/mp4',
};
const response: CreateSoundMessageResp = await sdk.createSoundMessageByURL(request);
const message = response.message;

Parameters

ParameterTypeRequiredDescription
uuidstringYesUnique identifier for the audio asset.
soundPathstringYesLocal file path if retained, or empty string "" for remote files.
sourceURLstringYesRemote audio download URL.
dataSizenumberYesAudio payload size in bytes.
durationnumberYesAudio playback duration in seconds.
soundTypestringYesAudio MIME type (for example, audio/mp4).

Return value

Returns a Promise resolving to CreateSoundMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated voice message object referencing remote URLs.

State changes after the call

All fields are required. dataSize is in bytes, duration is in seconds, and soundType represents the true MIME type. Do not supply short-lived temporary URLs that receiving clients cannot access. This method creates the message object locally; call Send message to dispatch it.