Create an audio message from a local file
Create a pending audio message from an accessible local sound file path and duration.
Invoke createSoundMessageFromFullPath() to construct a pending audio/voice message from a local audio file and its playback duration. File size and headers are resolved automatically by the SDK during the upload process.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
soundPath | string | Yes | Absolute POSIX file path or unifile:// URI accessible to the native runtime. |
duration | number | Yes | Audio playback duration in seconds (do not pass milliseconds). |
Code example
import {
createSoundMessageFromFullPath,
} from '@/uni_modules/unix-openim-sdk'
const message = await createSoundMessageFromFullPath({
soundPath: `${uni.env.USER_DATA_PATH}/voice.m4a`,
duration: 12,
})
if (message == null) returnTemporary recording paths returned by capture APIs may be cleared by the OS. When deferring transmission or caching recordings, persist the file into uni.env.USER_DATA_PATH before supplying the path to the SDK.
Return value
The Promise resolves with an OpenIMMessageItem | null object.
State changes after the call
Pass the returned message object to Send a message. The SDK uploads the audio file, transmits the message, and triggers progress events tracked by clientMsgID.
Was this page helpful?