Multimodal, voice, and edge AI systems
Models now read images, audio, and video, and speak back. This guide explains how multimodal pipelines are built, how real-time voice agents stay fast, what changes when a model runs on a phone or a device, and the privacy duties that come with richer data.
Multimodal and real-time in 60 seconds
- Everything becomes tokens. Images, audio, and video cost tokens, often far more than text, so size and resolution are cost decisions.
- Pre-process before the model: resize, extract text or frames, and transcribe, to send less and get better results.
- Voice agents live or die on latency. Stream every stage, detect when the user stops speaking, and let them interrupt.
- Two voice designs: a cascade of speech-to-text, model, and text-to-speech, or one model that handles speech directly.
- Edge and on-device AI trades model size for privacy, offline use, and low latency.
How a model handles images and audio
A multimodal model has a front end for each kind of input. An image is split into small patches and converted into a sequence of tokens. Audio is converted into a sequence of frames, then tokens. After that, the model treats them much like text tokens, so it can answer a question about a picture or follow a spoken instruction. The consequence for system design is simple: every image or second of audio you send consumes part of the context window and the budget.
Part 1: multimodal pipelines
Storage
Files do not belong in the prompt. Store the original in object storage, keep a reference in your database, and send the model only what it needs for the task: a resized image, a cropped region, or a transcript. Keep the original so you can reprocess it with a better model later, and attach metadata (owner, time, source, access rules) as you would for any document.
Pre-processing
Raw media is often wasteful or noisy. A pre-processing step improves cost and quality together.
- Images: resize to the largest size the task needs, fix rotation, and crop to the region of interest. For documents, run text extraction first and send the text, using the image only for charts and layout.
- Audio: remove long silences, normalise volume, and split long recordings into segments with timestamps before transcription.
- Video: sample frames at a sensible rate, detect scene changes, and pair frames with a transcript, instead of sending every frame.
- Scans and PDFs: detect whether a page is text or a picture, and route each to the right path.
# Illustrative: send less, and send it in a useful form.
# open_image(), extract_text() and call_vision_model() are placeholders.
MAX_SIDE = 1024 # the largest side the task needs; larger images cost more tokens
def prepare_image(path):
image = open_image(path)
image = image.fix_orientation()
if max(image.size) > MAX_SIDE:
image = image.resize_to_fit(MAX_SIDE)
return image
def describe_document_page(path):
text = extract_text(path) # text is cheaper and exact
if len(text) > 200:
return call_vision_model(prompt='Summarise this page.', text=text) # no image needed
return call_vision_model(prompt='Describe this page.', image=prepare_image(path))
Token cost
Providers convert media into tokens by their own rules, usually by size for images and by duration for audio, and they publish how. Check the current rules, then estimate cost for typical files. As a general pattern, a single high-resolution image can cost as many tokens as a long paragraph or more, and a minute of audio costs far more than the text it contains. That is why sending a transcript instead of the audio, or a cropped image instead of the whole page, is a standard saving.
Output modalities
Models can also produce images, speech, and sometimes video. These outputs are slower and costlier than text, are usually streamed or delivered as files, and often need extra checks: content policy, watermarking or provenance records, and storage with expiry. Treat generated media as a file with a lifecycle, not as a string.
Multimodal retrieval
To search across images and text, you can embed both into the same vector space with a model trained for it, or you can convert each image into a text description and a set of extracted fields and search those. The first finds visual similarity; the second is easier to inspect, filter, and cite. Many systems store both, using the description for search and the original image for answering.
Part 2: real-time voice agents
A voice agent holds a spoken conversation. People notice a pause of about a second as a break in the conversation, so the design goal is fast first audio and natural turn-taking, not only correct answers.
Two designs
| Design | How it works | Strengths | Weaknesses |
|---|---|---|---|
| Cascade | Speech to text, then a text model, then text to speech | Each part can be chosen and tested separately; easy to log and filter text | Several hops add latency; tone and emotion are lost in the text |
| Speech-to-speech model | One model listens and speaks directly | Lower latency; natural rhythm and tone | Harder to inspect and filter; fewer model choices |
Keeping latency low
- Stream everything. Start transcribing while the user speaks, start the model on partial text where possible, and start speaking the first sentence while the rest is still being generated.
- Detect end of turn well. Voice activity detection decides when the user has finished. Too eager and the agent cuts people off; too slow and every reply lags.
- Allow barge-in. When the user starts speaking over the agent, stop playback at once and listen.
- Keep replies short. Spoken answers should be one or two sentences, with more offered on request.
- Cover waits. If a tool call takes time, say so ('let me check that') instead of leaving silence.
- Choose a low-latency transport. WebRTC and WebSockets keep a connection open and avoid the cost of a new request for each chunk of audio.
# Illustrative: listen, think, and speak as overlapping streams.
# vad, stt, llm and tts are placeholders for streaming components.
import asyncio
async def conversation(mic, speaker):
while True:
utterance = await listen_until_turn_end(mic, vad, stt) # streams partial text
speak_task = asyncio.create_task(speak(llm.stream(utterance), tts, speaker))
barge_in = asyncio.create_task(vad.wait_for_speech(mic)) # the user starts talking
done, _ = await asyncio.wait({speak_task, barge_in}, return_when=asyncio.FIRST_COMPLETED)
if barge_in in done:
speak_task.cancel() # stop talking at once
speaker.flush()
else:
barge_in.cancel()
async def speak(text_stream, tts, speaker):
async for sentence in sentences(text_stream): # speak sentence by sentence
await speaker.play(await tts.synthesise(sentence))
Care points specific to voice
- Recognition errors become action errors. Confirm important details, such as names, numbers, and dates, by repeating them back.
- Accents, noise, and several speakers reduce accuracy. Test with realistic audio.
- No visual space for long answers. Offer a link or a message for details.
- Emergencies and escalation. Provide a quick path to a person.
Part 3: edge and on-device AI
Not every model runs in a data centre. Small models can run on a phone, a laptop, or a device with a modest chip. This is called edge or on-device inference, and it has a different set of trade-offs.
| Benefit | Why | Cost |
|---|---|---|
| Privacy | Data never leaves the device | You cannot see or fix quality problems centrally |
| Low latency | No network round trip | The device chip limits speed |
| Offline use | Works without a connection | Models must be stored and updated on the device |
| Lower serving cost | The user's hardware does the work | Battery, heat, and storage use |
- Model size is the constraint. On-device models are far smaller, and are usually quantised to fit in memory.
- Hybrid designs are common. A small local model handles easy or private requests, and a larger cloud model handles hard ones, with a clear rule for what may leave the device.
- Updates need a plan. Ship new model versions like app updates, with a rollback path, and track the version in feedback.
- Test on real devices. Speed and memory vary widely between models of phone.
Privacy for rich data
Voices, faces, and images are personal in ways that text often is not, and a voice can identify a person. Collect only what the feature needs, tell users clearly what is recorded, keep raw media for as short a time as you can, store derived data (a transcript, a label) instead of the media where that is enough, and restrict access. Rules on recording and on biometric data vary by country and by state, so involve your legal team before launch.
How to choose
- Ask whether text is enough. Extract text from documents and transcribe audio when the model does not need the original.
- Reduce before you send. Resize, crop, and sample.
- For voice, start with a cascade because it is easier to inspect, then consider a speech-to-speech model if latency or naturalness demands it.
- Move to the edge only when privacy, offline use, or latency require it.
- Estimate token cost for typical media files before choosing a model.
What this means for your role
Common mistakes
Further reading
- WebSockets, the connection style behind real-time audio.
- How inference works, for streaming and latency fundamentals.
- Guardrails and privacy, including voice and multimodal privacy controls.
- Types of AI agents, including voice and computer-use agents.
Richer inputs make richer products and heavier systems. Reduce what you send, stream what you can, and handle personal media with care.