Chat Messages
Roles
.tool messages when you append function-call results back into the conversation.
Message Structure
content: Ordered fragments of the message. The SDK supports.text,.image, and.audioparts.reasoningContent: Optional text produced inside<think>tags by eligible models.functionCalls: Attach the calls returned byMessageResponse.functionCallwhen you include tool execution results in the history.
Message Content
.image and WAV data for .audio. Helper initializers such as ChatMessageContent.fromUIImage, ChatMessageContent.fromNSImage, ChatMessageContent.fromWAVData, and ChatMessageContent.fromFloatSamples(_:sampleRate:channelCount:) simplify interop with platform-native buffers. On the wire, image parts are encoded as OpenAI-style image_url payloads and audio parts as input_audio arrays with Base64 data.
Audio Format Requirements
The LEAP inference engine requires WAV-encoded audio with specific format requirements:
Supported PCM Encodings:
- Float32: 32-bit floating point, normalized to [-1.0, 1.0]
- Int16: 16-bit signed integer, range [-32768, 32767] (recommended)
- Int24: 24-bit signed integer, range [-8388608, 8388607]
- Int32: 32-bit signed integer, range [-2147483648, 2147483647]
Automatic Resampling: The inference engine automatically resamples audio to 16 kHz if provided at a different sample rate. However, for best performance and quality, provide audio at 16 kHz to avoid resampling overhead.
Creating Audio Content from WAV Files
Creating Audio Content from Raw PCM Samples
Use thefromFloatSamples helper to create WAV-encoded data from raw audio samples:
Recording Audio on iOS
When recording audio from the device microphone, configureAVAudioRecorder with the correct settings:
Audio Duration Considerations
- Minimum duration: At least 1 second of audio is recommended for reliable speech recognition
- Maximum duration: Limited by the modelβs context window (typically several minutes)
- Silence: Trim excessive silence from the beginning and end for better results
Audio Output from Models
When generating audio responses (e.g., withLFM2.5-Audio-1.5B), the model outputs audio at 24 kHz sample rate:
Note: Audio input should be 16 kHz, but audio output from generation models is typically 24 kHz. Make sure your audio playback code supports the correct sample rate.