Skip to main content

Documentation Index

Fetch the complete documentation index at: https://liquidai-fix-android-sdk-qa-issues.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

ChatMessage and ChatMessageContent mirror the OpenAI chat-completions message schema. Both are declared once in commonMain (data class ChatMessage, sealed class ChatMessageContent) and Kotlin/Native + SKIE bridge the Kotlin types into Swift β€” there are no separate β€œnative” Swift declarations.

ChatMessage

The Swift class is generated from the Kotlin data class. Kotlin parameter defaults don’t propagate, so the primary init requires all four arguments explicitly:
public class ChatMessage {
  public var role: ChatMessage.Role
  public var content: [ChatMessageContent]
  public var reasoningContent: String?
  public var functionCalls: [LeapFunctionCall]?

  // Primary init β€” pass `reasoningContent: nil, functionCalls: nil` for ordinary messages.
  public init(
    role: ChatMessage.Role,
    content: [ChatMessageContent],
    reasoningContent: String?,
    functionCalls: [LeapFunctionCall]?
  )

  // Secondary inits (from Kotlin secondary constructors):
  public init(role: ChatMessage.Role, content: ChatMessageContent)  // single content
  public init(role: ChatMessage.Role, textContent: String)          // plain text

  public enum Role {
    case system, user, assistant, tool
  }
}

Fields

  • role β€” the speaker (user, system, assistant, or tool). Use tool when appending function-call results back into the history.
  • content β€” ordered fragments. Supported part types: Text, Image (JPEG bytes wrapped in a data URL), Audio (WAV bytes or input_audio payload), and on Kotlin AudioPcmF32 for raw float samples.
  • reasoningContent β€” text emitted by reasoning models inside <think> / </think> tags. null for non-reasoning responses.
  • functionCalls β€” calls returned by MessageResponse.FunctionCalls on the previous turn, included when appending tool-call results to history.

Serialization

Round-trip the message through kotlinx.serialization β€” there is no separate β€œfrom [String: Any]” initializer on either platform.
Encode with LeapJson.encodeToString (or your own JSONEncoder against the OpenAI shape) and decode with the matching Kotlin serializer. See Utilities β†’ Serialization for examples that route through LeapJson.

ChatMessageContent

ChatMessageContent is the Kotlin sealed class bridged to Swift β€” switch on its subclasses with SKIE’s onEnum(of:) helper. There is no native Swift enum, no positional .image(_:) / .audio(_:) factory, and no init(from json:). Use the static factories on the Swift overlay:
// Text (cross-platform):
ChatMessageContent.text(_ text: String) -> ChatMessageContent

// Image:
ChatMessageContent.fromJPEGData(_ jpegData: Data) -> ChatMessageContent.Image
ChatMessageContent.image(url: String) -> ChatMessageContent.Image           // data URL or remote URL

// Audio:
ChatMessageContent.fromWAVData(_ wavData: Data) -> ChatMessageContent.Audio
ChatMessageContent.audio(data: Data, format: String = "wav") -> ChatMessageContent.Audio
ChatMessageContent.fromFloatSamples(_ samples: [Float], sampleRate: Int, channelCount: Int = 1)
    -> ChatMessageContent.AudioPcmF32

// iOS only β€” UIKit:
public static func fromUIImage(_ image: UIImage) throws -> ChatMessageContent
// (JPEG quality is fixed at 0.85; no compressionQuality parameter is exposed.)
fromUIImage is iOS-only and takes only the image β€” JPEG compression quality is hard-coded to 0.85 in the overlay (leap-sdk/src/iosMain/.../ChatMessageContentExtensionsIos.kt). There is no fromNSImage factory; on macOS, convert your NSImage to JPEG Data yourself and pass it through fromJPEGData(_:).On the wire, image parts are encoded as OpenAI-style image_url payloads (with a data:image/jpeg;base64,... URL) and audio parts as input_audio arrays with Base64 data.
  • Text β€” plain text fragment.
  • Image β€” JPEG-encoded image bytes. Only vision-capable models can interpret image parts.
  • Audio β€” WAV-encoded audio bytes (see audio format requirements below).
  • AudioPcmF32 (Kotlin) / fromFloatSamples(...) (Swift) β€” raw float32 mono PCM in memory. Avoids re-encoding when you already have samples.

Audio format requirements

The LEAP inference engine expects WAV-encoded audio with these specifications:
PropertyRequired valueNotes
ContainerWAV (RIFF)Only WAV is supported
Sample rate16000 Hz recommendedOther rates auto-resampled to 16 kHz
EncodingPCMFloat32, Int16, Int24, or Int32
ChannelsMono (1)Stereo is rejected
Byte orderLittle-endianStandard WAV
Supported PCM encodings
  • Float32 β€” 32-bit floating point, normalized to [-1.0, 1.0]
  • Int16 β€” 16-bit signed integer (recommended)
  • Int24 β€” 24-bit signed integer
  • Int32 β€” 32-bit signed integer
The engine only accepts WAV. M4A, MP3, AAC, OGG, and other compressed formats are rejected. Convert to WAV before sending.
Mono required. Stereo or multi-channel WAVs are rejected with an error. Downmix to mono first.
Automatic resampling. The engine resamples to 16 kHz when needed, but providing 16 kHz audio directly avoids the resampling overhead. For best quality, record at 16 kHz mono.

Creating audio content

From a WAV file

let wavURL = Bundle.main.url(forResource: "audio", withExtension: "wav")!
let wavData = try Data(contentsOf: wavURL)

let message = ChatMessage(
    role: .user,
    content: [
        .text("What is being said in this audio?"),
        ChatMessageContent.fromWAVData(wavData)
    ],
    reasoningContent: nil,
    functionCalls: nil
)

From raw PCM samples

// Float samples normalized to [-1.0, 1.0]
let samples: [Float] = [0.1, 0.2, 0.15, -0.3 /* ... */]

let audioContent = ChatMessageContent.fromFloatSamples(
    samples,
    sampleRate: 16000,
    channelCount: 1
)

let message = ChatMessage(
    role: .user,
    content: [.text("Transcribe this audio"), audioContent],
    reasoningContent: nil,
    functionCalls: nil
)

Recording from the microphone

Configure AVAudioRecorder with WAV-compatible settings:
import AVFoundation

let audioURL = FileManager.default.temporaryDirectory
    .appendingPathComponent("recording.wav")

let settings: [String: Any] = [
    AVFormatIDKey: kAudioFormatLinearPCM,
    AVSampleRateKey: 16000.0,        // 16 kHz
    AVNumberOfChannelsKey: 1,        // Mono
    AVLinearPCMBitDepthKey: 16,      // 16-bit
    AVLinearPCMIsFloatKey: false,
    AVLinearPCMIsBigEndianKey: false
]

let recorder = try AVAudioRecorder(url: audioURL, settings: settings)
recorder.record()
// ...
recorder.stop()

let wavData = try Data(contentsOf: audioURL)
let audioContent: ChatMessageContent = ChatMessageContent.fromWAVData(wavData)

Audio duration

  • Minimum β€” at least 1 second of audio for reliable speech recognition.
  • Maximum β€” bounded by the model’s context window (typically several minutes).
  • Silence β€” trim excessive silence from the start and end for better results.

Audio output from models

Audio-capable models like LFM2.5-Audio-1.5B emit float32 PCM frames via MessageResponse.AudioSample. Output sample rate is typically 24 kHz (vs. 16 kHz for input).
for try await response in conversation.generateResponse(message: userMessage) {
    if case .audioSample(let audio) = onEnum(of: response) {
        // audio.samples: [Float] in [-1.0, 1.0]
        // audio.sampleRate: Int (typically 24000 for audio-gen models)
        audioPlayer.enqueue(samples: audio.samples, sampleRate: Int(audio.sampleRate))
    }
}
Audio input should be 16 kHz; audio output from generation models is typically 24 kHz. Configure your playback pipeline accordingly.