Browse SDKs · iOS
Platform
SDKsiOSEnterprise

Transcribe audio

Transcribe audio to text through OpenIMCore on iOS.

Copy

Use the underlying OpenIMCore C function Open_im_sdkSpeechToText to submit audio data or local audio files to the speech-recognition engine for transcription. On native iOS, passing an accessible file path in filename is preferred over providing Base64 data:

Parameters

Construct a JSON request payload with the following fields:

ParameterTypeRequiredDescription
filenameNSString *ConditionalSandboxed absolute path to the local audio file within the application container (recommended).
dataNSString *ConditionalBase64-encoded audio data string (used when a local file path cannot be provided). filename and data are mutually exclusive.

Code example

NSDictionary *request = @{@"filename": audioFileURL.path};
NSString *requestJSON = [self JSONString:request];
CallbackProxy *callback = [[CallbackProxy alloc]
    initWithOnSuccess:^(NSString * _Nullable data) {
        // Parse transcription JSON and display text
        [self showTranscription:[self textFromResultJSON:data]];
    }
    onFailure:^(NSInteger code, NSString * _Nullable msg) {
        // Handle transcription failure
    }];

Open_im_sdkSpeechToText(callback, @"", requestJSON);

Return value

The onSuccess callback delivers a JSON string containing the transcribed text formatted as {"text": "transcribed text content"}.

State changes after the call

  1. Independent evaluation: Transcription executes text recognition without mutating the original audio message model or triggering local/remote message event listeners.
  2. Local transcript persistence: To persist the recognized text on the local device alongside the message, save it in the message's local extension field. See Save a local transcript.
  3. Capability validation: Prior to submitting audio for transcription, verify format and size limitations via Check speech-recognition support.