SDKsHarmonyOSEnterprise
Create voice message from URL
Create a voice audio message from pre-uploaded remote audio resource metadata.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
uuid | string | Yes | Unique identifier for the audio asset. |
soundPath | string | Yes | Local file path if retained, or empty string "" for remote files. |
sourceURL | string | Yes | Remote audio download URL. |
dataSize | number | Yes | Audio payload size in bytes. |
duration | number | Yes | Audio playback duration in seconds. |
soundType | string | Yes | Audio MIME type (for example, audio/mp4). |
Return value
Returns a Promise resolving to CreateSoundMessageResp:
| Property | Type | Description |
|---|---|---|
message | IMMessage | Locally 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.
Was this page helpful?