SDKsHarmonyOSEnterprise
Transcribe audio to text
Convert Base64-encoded audio data into recognized text.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
filename | string | Yes | Audio filename including the valid file extension. |
data | string | Yes | Pure Base64-encoded audio payload string. |
Return value
Returns a Promise resolving to SpeechToTextResp:
| Property | Type | Description |
|---|---|---|
text | string | Recognized 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.
Was this page helpful?