SDKsWASM
Create an audio message from a file
Create an audio message from a browser File with the WASM SDK.
createSoundMessageByFile() creates a message from a browser audio file and its metadata.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
file | File | Yes | Original audio file from the browser. |
uuid | string | Yes | Unique identifier for the audio resource. |
soundPath | string | Yes | Local filename or application-defined path of the audio file. |
sourceUrl | string | Yes | Audio URL. Pass an empty string when creating from a file; the SDK uploads the audio during sending. |
dataSize | number | Yes | Audio size in bytes. |
duration | number | Yes | Audio duration in seconds. |
soundType | string | No | Audio MIME type. |
const { data: message } = await openimsdk.createSoundMessageByFile({
file,
uuid: crypto.randomUUID(),
soundPath: file.name,
sourceUrl: '',
dataSize: file.size,
duration,
soundType: file.type,
});Derive the audio size, type, and duration from the actual file. If the browser reports the duration in milliseconds, convert it to seconds before passing it. When the Promise resolves, it has created only a pending message object. Use sendMessage() afterward to upload and send it.
Was this page helpful?