浏览 SDKs · HarmonyOS
平台
SDKsHarmonyOS商业版

使用本地音频创建消息

根据应用可访问的本地音频路径创建待发送消息。

复制
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;

soundPath 必须可由原生 SDK 读取;duration 的单位为秒。录音组件返回的临时路径可能被清理,需要延后发送时先复制到应用沙箱中的持久位置。Promise 成功只创建消息对象,后续由 SDK 上传并发送。