Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Transcribe audio to text

Convert Base64-encoded audio data into recognized text.

Copy

Do not pass local file paths, raw ArrayBuffer instances, or data URLs prefixed with data:*;base64,.

Code example

import sdk, { SpeechToTextReq, SpeechToTextResp } from '@openimsdk/imsdk';

const request: SpeechToTextReq = {
  filename: 'voice.m4a',
  data: audioBase64,
};
const response: SpeechToTextResp = await sdk.speechToText(request);
showTranscript(response.text);

Parameters

ParameterTypeRequiredDescription
filenamestringYesAudio filename including the valid file extension.
datastringYesPure Base64-encoded audio payload string.

Return value

Returns a Promise resolving to SpeechToTextResp:

PropertyTypeDescription
textstringRecognized text content extracted from the audio.

State changes after the call

filename must include an extension corresponding to the real audio format, and data must contain only the raw Base64 string. Before calling this method, validate format, sampling rate, duration, and file size limits against Check speech-to-text capabilities. Transcription results do not modify the original voice message record or trigger message events.