Skip to content
OneSay Developers

Quick Start

ESP32 Quickstart

Choose Task Voice for a Task-only application or Realtime RTC for live audio in a Room. OneSay OS is not required. The SDK is in preview; use it as an ESP-IDF component in your project.

Choose Task Voice for a Task-only application or Realtime RTC for live audio in a Room. OneSay OS is not required. The SDK is in preview; use it as an ESP-IDF component in your project. It is not on the ESP Component Registry. Access. Before you start, OneSay gives your GitHub account read-only access to the SDK's private repository; to ask for it, write to sdk@onesay.com with your GitHub account name. Account. You also need a OneSay account enrolled in the trial: the Console, Device provisioning and every access token depend on it. Sign up in OneSay Cloud: each Project you create in the Organization OneSay Cloud makes for you gets its Test Environment enrolled in the trial when it is created. All server permissions remain authoritative even if the client binary or local capability flags change.

The SDK ships four examples: voice_button (one voice task), rtc_smoke (a diagnostic: a voice task, then one RTC audio session), agent_call (the device side of a conversation with an AI Agent, with no board code) and box3_agent_call (agent_call with an ESP32-S3-BOX-3 board layer).

ESP32 + Task Voice

Start from examples/voice_button, a standalone Task-only ESP-IDF application in the SDK's repository. Copy it into a new project directory, and put the SDK at components/onesay; the example expects it there. Keep the component's dependency pins in idf_component.yml; the ESP-IDF component manager downloads missing dependencies at the first idf.py set-target. With the access OneSay gave you, the Quick start section of the repository's README shows the commands that create such a project from the release named v0.1.10; your Git credentials need that access. If Git answers Repository not found, your GitHub account does not have the access yet, or your Git credentials are not those of that account. Run the README's commands only up to entering your new project directory, and stop before idf.py set-target: do the next paragraph's step first. idf.py set-target writes the project's sdkconfig from sdkconfig.defaults, so settings appended after it are not used; if you already ran it, run idf.py set-target esp32s3 again after appending them.

Use idf-component-manager 3.1.2, the version we tested: an older one can fail to solve the RTC dependencies. Before idf.py set-target, in ESP-IDF's Python environment, run python -m pip install idf-component-manager==3.1.2. Set your configuration's environment to ONESAY_ENVIRONMENT_PRODUCTION in each example, the Task one included: the SDK then uses its built-in Production addresses and needs no address setting. Then append CONFIG_ONESAY_CUSTOM_ENDPOINTS_CHECK=n to the project's sdkconfig.defaults, also before idf.py set-target: the component's build check for the ONESAY_ENVIRONMENT_CUSTOM addresses is on by default and no example's defaults turn it off, so without this line idf.py build stops with ONESAY_ENVIRONMENT_CUSTOM needs an https CONFIG_ONESAY_CUSTOM_CONTROL_API_URL and a wss CONFIG_ONESAY_CUSTOM_REALTIME_URL. To reach another regional node instead, use ONESAY_ENVIRONMENT_CUSTOM, leave the check on and append that node's addresses from your configuration to the project's sdkconfig.defaults as CONFIG_ONESAY_CUSTOM_CONTROL_API_URL and CONFIG_ONESAY_CUSTOM_REALTIME_URL before idf.py set-target.

Do not use the README Quick start's two address lines, which take ONESAY_CONTROL_API_URL and ONESAY_REALTIME_URL and write them as CONFIG_ONESAY_CUSTOM_CONTROL_API_URL and CONFIG_ONESAY_CUSTOM_REALTIME_URL: Production does not use them, and the shell stops at them when those two variables are not exported. For Production, run these lines in your new project directory instead:

Terminal
python -m pip install idf-component-manager==3.1.2
echo 'CONFIG_ONESAY_CUSTOM_ENDPOINTS_CHECK=n' >> sdkconfig.defaults

In that project, use ESP-IDF 6.0.2 to build, then flash your board and watch its serial output:

Text
idf.py set-target esp32s3
idf.py build
idf.py -p <PORT> flash monitor

Building needs no board. Flashing writes the application only; it does not provision Device credentials.

Follow examples/voice_button/README.md and the example-local main/voice_button.h. Supply onesay_voice_button_configure with secure Device credential storage, existing authorized Project/Environment/Application and Source/Room bindings, network access, trusted UTC/certificates and a bounded 16 kHz mono PCM s16le producer. Its default hook returns ONESAY_ERR_AUTH before connecting, so the unmodified example does not connect. How a Device and its credential are created is in Device Provisioning. Capture, GPIO, I2S, codec and board tuning belong to your board code.

Before it opens audio, the example publishes the Device's capability report with onesay_esp32_control_publish_capabilities, in its connect and again on each reconnect. The server admits audio from a Device only while a report that declares its audio input is at most 300 s old. The report is sent from the calling task, so all four examples set a 20480-byte main task stack; keep it in your project.

Without such a report, opening audio answers 409 with a code that says why: device_capability_report_missing (no report yet), device_capability_report_stale (the newest report is 300 s old or older) or device_capability_unavailable (the report does not declare the audio input present). In the SDK these are ONESAY_ERR_CAPABILITY_REPORT_MISSING, ONESAY_ERR_CAPABILITY_REPORT_STALE and ONESAY_ERR_CAPABILITY_UNAVAILABLE. The SDK does not reconnect on them, and retrying unchanged does not help: publish a fresh report or fix the audio input, then try again.

The caller serializes onesay_voice_button_init, onesay_voice_button_connect and bounded onesay_voice_button_step calls. The SDK owns WSS/OSAF, sequence/ACK, backpressure, replay/resume and cancellation. Keep retained PCM until ACK release; a successful cancel send is not a terminal Task result. onesay_voice_button_close must release the transport before its storage and dependencies can be freed. This path does not open an RTC session.

The Task language (task_input.language) is optional. Leave it empty or set "auto" and the speech Provider detects the language; the results then report the language as "auto". Set a language code such as "zh-CN" to fix the language.

ESP32 + Realtime RTC

onesay_esp32_rtc.h is always in the component's include folder; its implementation is built only when CONFIG_ONESAY_RTC_ENABLED is selected. RTC is built on the LiveKit ESP32 SDK; idf_component.yml pins the tested version. Use ESP-IDF 6.0.2 and keep the component's dependency graph as it is. The component's sdkconfig.rtc.defaults is the RTC configuration fragment, loaded before application defaults; it is not a board configuration. Enabling RTC in the Task example does not turn it into an RTC application; start from the RTC project below.

An Agent call can start two ways. Its owner, a Human, starts the Agent under the Human's own app session, with the Device's microphone as input. Or the Device starts the call itself (onesay_esp32_device_agent_call_start, from v0.1.9) under a standing Delegation its owner created, on an Environment where OneSay has enabled device-started calls; use this way; with a released SDK it has not been verified on a device yet. On OneSay's service today, the Agent does not hear the board in a call that a person starts (ESP32 SDK 0.1.9 and earlier). In both, a paired Device is the Agent's microphone and hears its answer (a preview). In the call its owner starts, the Device publishes its microphone, the Agent takes that publication as input, and the Device subscribes to the Agent's output. The Device needs the permission livekit.subscribe, so create the credential of an older Device again. See A Device as the Agent's microphone and speaker.

On the reference board, Talk to an AI Agent on an ESP32-S3-BOX-3 walks through one call, and Bringing up your own board lists the settings it needed.

To start an RTC call on a device, use agent_call: the device side of a conversation with an AI Agent, to which you add your board layer. box3_agent_call is agent_call with the ESP32-S3-BOX-3 board layer. OneSay has run box3_agent_call on its own ESP32-S3-BOX-3; what passed, and what has not been verified yet, is in the BOX-3 guide.

agent_call has no board code: you provide onesay_agent_call_configure, whose default returns ONESAY_ERR_AUTH before any network activity. It must give a microphone with echo cancellation (capture.echo_cancelled), confirm that the Room holds only the device and the Agent (room_device_and_agent_only), give a short-lived Device bearer and, for a call its owner starts, the Agent's output publication or a way to read it; the example refuses to start otherwise. Its README lists every field. RTC needs PSRAM: rtc_smoke and agent_call build without it and do not run until your board's defaults enable it.

Every example project, rtc_smoke, agent_call and box3_agent_call included, takes the Task example's step before idf.py set-target: install idf-component-manager 3.1.2 in ESP-IDF's Python environment, and append CONFIG_ONESAY_CUSTOM_ENDPOINTS_CHECK=n to sdkconfig.defaults for Production (for another regional node, its two addresses instead). For box3_agent_call, also delete the environment line from your copy of nvs.example.csv: it writes 0, which the board reads as ONESAY_ENVIRONMENT_CUSTOM, and with the check off the board then refuses to start, the custom addresses being unset. Or build it the ESP32-S3-BOX-3 guide's way, which exports the built-in addresses instead of the check line. Each example README's quick start installs it too, from v0.1.10; it also writes the two addresses, which Production does not use. Without 3.1.2, idf.py set-target stops with idf-component-manager 3.0.3 is too old for the OneSay SDK (ESP-IDF's image carries 3.0.3). For box3_agent_call, run it before python setup_codec_board.py, which needs the network and the patch tool (on Windows it comes with Git for Windows, in C:\Program Files\Git\usr\bin).

Diagnostic project: rtc_smoke

The board-agnostic project examples/rtc_smoke is a diagnostic: it checks each step of an RTC connection without a microphone or speaker. It is an independent ESP-IDF application that uses only the OneSay component and the voice_button Task flow. It has no GPIO, I2S, codec, BSP, AEC, Wi-Fi or NVS code, and it does not depend on OneSay OS. One run streams a Task (with the audio of your Task audio source, task_audio, if you supply one), then connects RTC with synthetic capture, sends one packet, releases everything and prints one content-free summary line on the serial console.

Create the project the same way as the Task example: copy rtc_smoke into a new directory, add the component as components/onesay, and copy main/voice_button.c and main/voice_button.h from the voice_button example into its main/. Then build and flash it with the idf.py commands above.

Provide a strong onesay_rtc_smoke_configure. Its weak default returns ONESAY_ERR_AUTH before any network activity. Before it returns ONESAY_OK, your firmware brings up the network, sets trusted UTC and fills the configuration from your secure store. The project's README lists every field. Board settings (flash size, PSRAM, console) go in a third defaults file: run idf.py set-target esp32s3 with -D SDKCONFIG_DEFAULTS and the whole list, the SDK's sdkconfig.rtc.defaults (in components/onesay) first, then sdkconfig.defaults, then your sdkconfig.board (RTC needs PSRAM).

Expected result today. The summary line ends FAIL at rtc_packet_policy with error 1, because OneSay's server does not offer packets yet; that is the expected end of a run, not a fault in your setup. Every step before it, up to and including rtc_capture, should pass: together they show that the Task and the RTC audio connection work on your board. task_terminal passes only with real speech from your Task audio source (task_audio), and rtc_render shows SKIPPED without a peer. A failure at an earlier step is the one to diagnose. For an RTC run that ends with a pass, use agent_call or box3_agent_call: its README lists when a call passes (it connected and subscribed, the Agent's voice played for more than 2 s, a barge-in stopped the Agent within 4 s unless barge_in_optional is set, nothing failed and the release was clean).

Device credential to RTC bearer

The RTC owner takes a caller bearer and never exchanges a Device secret. To go from the Device credential to RTC with public calls only, set rtc_bearer_from_device_credential = true in the smoke configuration. The chain is:

  1. Owner authority, before the device runs. The owner creates the Delegation and decides the Consent requests. The Device creates its AppSession under that Delegation with createAppSession. The device receives the Room, AppSession, Source and delegation IDs. IDs grant nothing; the server checks the actual Grant, Delegation and Consent on every request.
  2. Device secret to short-lived token. The rtc_bearer step loads the Device secret once through your existing secure-store callback (task.credentials.load). It sends the secret only as the Authorization of one exchangeDeviceAccessToken request (POST /v1/device-access-tokens, body {}) through the public onesay_esp32_control_request. The RTC Control configuration must name the same environment, Device, Project and Environment as the Task one, or the step fails before the secret is loaded. The secret is erased whatever happens. Only the access_token of the {"data":{"access_token","token_type":"Bearer","expires_at"}} response envelope is kept. The store's erase, a factory reset, is never called.
  3. Token to RTC. onesay_esp32_rtc_prepare, onesay_esp32_rtc_connect_audio and the packet policy receive only that short-lived Device access token, on the same Control owner. The smoke erases its copy after release.

The SDK gives every exchangeDeviceAccessToken and exchangeDeviceProvisioningCode exchange its own fresh Idempotency-Key, reused only for that exchange's one transport retry, and does not call your idempotency-key callback for them. A provisioning code is single-use: if a provisioning exchange still fails with ONESAY_ERR_WIFI_UNAVAILABLE after its retry, the code may already be consumed, and the Device then needs a new code. Your callback returns the original Consent-bound key for each RTC operation. Every Control call logs one info line (tag onesay_control) with the operation, HTTP status, response request ID and SDK result, and never a key, token, body or credential. The RTC smoke example keeps serial output at the content-free WARN level, which compiles that line out. To see it, set CONFIG_LOG_MAXIMUM_LEVEL_INFO=y and raise only that tag with esp_log_level_set("onesay_control", ESP_LOG_INFO); every other tag stays at WARN. To use a bearer from another established flow instead, supply the load_rtc_bearer callback. Exactly one of the two sources is accepted. Never put a long-lived Device secret, Platform key, Provider key or LiveKit secret in firmware sources, logs or documentation.

Prepare the application inputs

Initialize the onesay_esp32_control_context_t using onesay_esp32_control_init and your onesay_esp32_control_config_t. Supply the expected Device/Project/Environment/Application bindings, certificate or verified certificate bundle, bounded request timeout and next_idempotency_key callback. The shared Control initializer requires a valid device_id even when the separate RTC bearer is a Human; that configured ID does not change the bearer's identity or authorize RTC. Set environment to the SDK enum value for the environment you are authorized to use: ONESAY_ENVIRONMENT_PRODUCTION, with CONFIG_ONESAY_CUSTOM_ENDPOINTS_CHECK=n in sdkconfig.defaults (the ESP32-S3-BOX-3 guide selects it when the NVS environment key is left out), or ONESAY_ENVIRONMENT_CUSTOM with the addresses in sdkconfig.defaults for another regional node. Network setup, trusted UTC and certificate storage remain application responsibilities. Do not disable TLS hostname or date validation.

The audio sequence below needs these caller-owned inputs:

InputPublic contract
controlInitialized Control owner; retain its certificate and key-callback dependencies while using it.
bearer / bearer_lengthCurrent short-lived Human or delegated Device/AppSession bearer, for example the Device access token from the Device credential chain. RTC prepare does not exchange a Device secret or create an AppSession. Do not embed Platform, Provider or LiveKit long-term secrets.
inputonesay_action_rtc_connection_create_input_t containing the existing room_id and app_session_id, with terminated strings. Resources must already exist and be authorized.
connection_delegationThe selected connection operation's delegation_id, or NULL when omitted. It is request metadata, not permission.
audioonesay_rtc_audio_config_t: authorized source_id, that publication operation's separate delegation_id (empty omits it), capture/render callbacks and now_unix_ms with its context.
ownerA caller-retained pointer initialized to NULL; never pass a slot already owning a session to prepare.

The key callback must return the original key for each logical operation: createRTCConnection and createRTCPublication are separate operations. When Consent/Delegation applies, each key must match its own confirmed action. The connection's selector is not inherited by publication. Server checks remain authoritative; a valid local selector or callback cannot grant access.

Prepare, connect, observe and release

This is application code using the public header, not another SDK export or a complete board application. It requires the inputs above.

C
#include "onesay_esp32_rtc.h"

onesay_err_t example_begin_rtc_audio(
    onesay_esp32_control_context_t *control,
    const uint8_t *bearer, size_t bearer_length,
    const onesay_action_rtc_connection_create_input_t *input,
    const char *connection_delegation,
    const onesay_rtc_audio_config_t *audio,
    onesay_esp32_rtc_t **owner) {
    if (owner == NULL || *owner != NULL) return ONESAY_ERR_INVALID_ARG;
    onesay_err_t result = onesay_esp32_rtc_prepare(
        control, bearer, bearer_length, input, connection_delegation, owner);
    if (result != ONESAY_OK) return result;
    /* Keep *owner even on failure: the caller still owns cleanup. */
    return onesay_esp32_rtc_connect_audio(
        *owner, control, bearer, bearer_length, audio);
}

Serialize these public calls on the application thread, outside all media, network and clock callbacks. Keep the pointer and callback contexts alive after the function returns. Failed prepare leaves the initially empty pointer NULL, but an ambiguous HTTP outcome still needs server reconciliation. After successful prepare, even failed connect leaves an owned pointer requiring close. ONESAY_OK from connect means that the connection attempt was accepted; it does not mean connected, published, heard or effectively revoked.

Next call, where owner is the retained session pointerMeaning and required handling
onesay_esp32_rtc_read_binding(owner, &connection) with onesay_rtc_binding_t connection = {0}Copies original OneSay IDs, generation, deadline and observed state. Keep PREPARED/CONNECTING/CONNECTED/RECONNECTING/FAILED/CLOSED distinct; none replaces server authority.
onesay_esp32_rtc_read_failure(owner, &failure) with onesay_rtc_failure_t failure = {0}After the binding reports FAILED, copies why: failure.reason is LiveKit's own reason text (for example Unauthorized or Ping Timeout) and failure.final is true. While connecting, connected or reconnecting the reason is empty and final is false. LiveKit reports FAILED only when it will not retry, so a new connection needs a new preparation. It is a diagnosis, not server authority.
onesay_esp32_rtc_read_audio_binding(owner, &publication) with onesay_rtc_audio_binding_t publication = {0}Copies content-free publication IDs when available, including after a connection failure. Check the return value: unavailable publication returns ONESAY_ERR_INVALID_ARG and cleared output, not a fabricated ID.
onesay_esp32_rtc_close(&owner) when owner != NULLCancels board I/O, stops the RTC session and releases media owners. Only ONESAY_OK clears the pointer. On failure retain the pointer and all callback contexts for an explicit later cleanup attempt; do not free or reinitialize them.

Read and retain any IDs needed for server reconciliation before successful close. The CLOSED observation alone does not prove cleanup: a failed close can leave an owned pointer. Local close does not execute endRTCPublication or revokeRTCConnection; server cleanup uses those public operations with their own current authorization and idempotency/Consent bindings.

Capture must supply exactly the requested 16 kHz mono s16le samples, at most 640 per read. Render must accept the actual decoded s16le format: 8/12/16/24/48 kHz, mono or stereo, at most 120 ms per callback (5,760 frames at 48 kHz). All callbacks borrow their buffers until return and have a 40 ms budget. The idempotent cancel callback may run concurrently and must wake I/O without freeing its context. Callbacks must not invoke SDK lifecycle functions. GPIO, codec, resampling and board tuning are not supplied by this application code; the SDK's media pipeline handles encoding and format conversion.

On denied authorization, inspect onesay_esp32_control_last_error(control) for the error code, request ID and retryability; do not dump tokens, connection material or transport bodies. Expired first-use material cannot be rescued by a longer business deadline or a changed client clock. A failed or ambiguous publication/connect attempt must not be retried by calling connect again or minting a replacement key. Preserve the original IDs/key, release local owners and reconcile through the application's explicit authorization flow.

A temporary server failure answers HTTP 503 service_unavailable with retryable: true; nothing is wrong with your request. A Control call, including onesay_esp32_rtc_prepare, returns ONESAY_ERR_SERVICE_UNAVAILABLE to you and does not retry it: the SDK retries this error only in onesay_client_reconnect, the Task session's reconnect, within that function's limit. So wait a few seconds and make the same call again, with your next_idempotency_key callback returning the same key (the Device credential exchanges make their own key). onesay_esp32_rtc_connect_audio stays under the rule above: do not call it again for this error.

capability_authority_unavailable, also HTTP 503 with retryable: true, can answer any Control call, including the Device token exchange, when the server could not complete it just now. It says nothing against your Device secret, so keep it. The call returns ONESAY_ERR_SERVICE_UNAVAILABLE, and the code in onesay_esp32_control_last_error tells you which of the two it was. The paragraph above applies: wait a few seconds, repeat the call with the same key, and do not call onesay_esp32_rtc_connect_audio again. This case does not answer token_invalid.

provider_unavailable, provider_rate_limited and usage_pipeline_unavailable are also HTTP 503 with retryable: true, and the call returns ONESAY_ERR_SERVICE_UNAVAILABLE for them too. So does a 502, 503 or 504 that does not come from Control itself, for example from the proxy in front of it while Control restarts; such a 429 returns ONESAY_ERR_RATE_LIMITED. These answers have no OneSay error body, so the code in onesay_esp32_control_last_error is empty and only the status is set. Handle all of them as above: wait, then repeat the call with the same key. Such a 401 returns ONESAY_ERR_AUTH and such a 403 ONESAY_ERR_GRANT; do not repeat those unchanged.

For the full interface, see docs/COMPONENT.md in the SDK's repository.

The rtc_smoke project uses synthetic capture and a counting render sink. It does not supply microphone, speaker, AEC or audio-quality tuning; those belong to your board. The Task-only voice_button example does not use RTC, and Task or JavaScript support does not imply ESP32 RTC support for a feature.

Credentials on your board

Provision each device with its own Device credential and keep it in protected storage, for example encrypted NVS. Never compile a Project API key or Device credential into firmware, and never print it to the serial log. Supply certificates and trusted UTC before the first connection. Device Provisioning shows how a Device gets its credential.