ESP LLM Service
Introduction
esp_llm_service is the unified AI session service. It uses ESP Service as its base class and links media with ESP Media Service. The application creates capture and playback, then links those streams to the LLM (Large Language Model). Uplink frames go to a vendor adapter. Downlink frames go to the application-owned player. The LLM does not create or destroy capture and playback.
For how an application creates an adapter and links capture and playback, see esp_llm_baidu_agent_app, esp_llm_coze_agent_app, esp_llm_tongyi_agent_app, and esp_llm_volc_agent_app.
Features
Four media streams:
ESP_LLM_MEDIA_STREAM_AUDIO_UPcarries the microphone,ESP_LLM_MEDIA_STREAM_VIDEO_UPcarries the camera,ESP_LLM_MEDIA_STREAM_AUDIO_DNgoes to the speaker, andESP_LLM_MEDIA_STREAM_VIDEO_DNgoes to the display. Enable the required streams instreams[]before create, and leave the others disabledLink the media first, then call
esp_service_start()on the player, the LLM, and capture. Stop in the reverse order. Callesp_service_stop()beforeesp_llm_service_destroy()esp_llm_service_send_text()sends text after the session has startedesp_llm_service_send_frame()sends one frame. Do not use it for frames that a linked capture is already sendingesp_llm_service_send_custom_data()sends a backend-native commandesp_llm_service_cancel_response()cancels the current reply and keeps the sessionesp_llm_service_enable_uplink_track()disables audio or video uplink. Frames of that type are dropped, and capture keeps runningOptional audio AI sets
audio_ai_cfg.captureto the application’s capture and enables wake word withfeature_mask. Callesp_llm_service_trigger_wakeup()on press,keep_awake()while held, andtrigger_sleep()on release
Adapters
Adapter |
Protocol |
Capability |
|---|---|---|
Baidu RTC |
Voice chat, with music from the agent during the conversation. Image understanding sends the camera image to the cloud. Image generation displays cloud images. Multimodal does both. Room intercom is separate from the agent scenes |
|
Coze WebSocket |
Audio and text conversation. Talk directly, or send uplink after a wake word. A wake can barge in on the current reply. No camera image is sent, and no cloud image is displayed |
|
Tongyi WebSocket |
Duplex voice conversation. In vision mode the application previews the camera locally and sends one JPEG with |
|
Volcengine RTC |
Voice chat. |
How It Works
Media Streams and Linking
Create the session with the adapter create function. The application creates, starts, and destroys the microphone, speaker, and camera. The service does not create them. Link first, then start the player, the LLM, and capture. Stop in the reverse order.
esp_media_service_link(capture, APP_AUDIO_CAPTURE_STREAM,
llm, ESP_LLM_MEDIA_STREAM_AUDIO_UP);
esp_media_service_link(llm, ESP_LLM_MEDIA_STREAM_AUDIO_DN,
player, APP_AUDIO_PLAYER_STREAM);
esp_service_start(player);
esp_service_start(llm);
esp_service_start(capture);
APP_AUDIO_CAPTURE_STREAM and APP_AUDIO_PLAYER_STREAM are the application’s own stream IDs. After the link, the service reads uplink frames from capture and passes them to the adapter, then writes downlink frames to the player. The application does not send that audio again. Do not enable unused streams in streams[]. esp_llm_service_send_frame() is only for a single frame that has no capture link. Do not call it for frames the linked capture is already sending.
Control Plane
send_text(), send_frame(), send_custom_data(), and cancel_response() run after the service has started, and they must not overlap. cancel_response() stops only the current reply. The session stays up. enable_uplink_track() may run from an event callback: gated frames of that type are dropped, the call still returns success, and local capture and preview keep running.
Audio AI
Set audio_ai_cfg.capture to the audio capture the application already created, and enable wake word and related features with feature_mask. Uplink can stay disabled until a wake, and a wake can cancel the current reply. The button sequence is trigger_wakeup() on press, keep_awake() while held, and trigger_sleep() on release.
Examples
esp_llm_baidu_agent_app selects the scene in menuconfig and links capture and playback to the Baidu adapter. Voice chat includes music URL playback
esp_llm_coze_agent_app connects to Coze with a personal access token and demonstrates direct talk, wake word, and barge-in
esp_llm_tongyi_agent_app selects voice only or vision in menuconfig. In vision mode,
snapsends one image andsnap <prompt>asks about that imageesp_llm_volc_agent_app enables voice chat only. Video stays off