Skip to content
OneSay Developers

Guides

Your first voice task on an ESP32 board

In this tutorial you send speech from an ESP32 board to OneSay and read back the text. It uses the SDK's voice_button example. It is a Task voice path only: it does not open an RTC session and it starts no Agent.

In this tutorial you send speech from an ESP32 board to OneSay and read back the text. It uses the SDK's voice_button example. It is a Task voice path only: it does not open an RTC session and it starts no Agent.

Where this stands. On one ESP32-S3-BOX-3, on the pre-production environment, we have run a voice task from recorded speech to the final result, through the Task phase of the SDK's rtc_smoke example. We have built voice_button, and have not run it on a board as written here. Two steps have no public tool yet: writing the Device credential to the board, and answering the board's Consent and Delegation requests. You need your own tooling for both.

What you need

  • An ESP32-S3 board, a 2.4 GHz Wi-Fi network and a serial console.
  • ESP-IDF 6.0.2 exactly. Other versions are refused at build time.
  • A OneSay account and a Project on the pre-production environment.

1. Create the Device and its resources

In the OneSay Cloud Console or through the API, create a Device, a Source for its microphone and a Room. Device Provisioning explains the one-time provisioning code you get: it works once and expires after five minutes. Your firmware exchanges it for the board's own Device credential with onesay_esp32_control_exchange_provisioning; the example does not contain this step.

Keep that credential only in protected storage, for example encrypted NVS. Never put it in source code or firmware, and never print it.

2. Create the project

An example is a template. The SDK's repository is private: to ask for access, write to sdk@onesay.com. Copy examples/voice_button to a new directory, and put the SDK at components/onesay in it. Keep the SDK's dependency pins: the ESP-IDF component manager downloads what is missing at the first idf.py set-target. Use idf-component-manager 3.1.2, and append the addresses to sdkconfig.defaults as CONFIG_ONESAY_CUSTOM_CONTROL_API_URL and CONFIG_ONESAY_CUSTOM_REALTIME_URL, both before idf.py set-target.

Text
idf.py set-target esp32s3
idf.py build

Building needs no board.

3. Connect the example to your firmware

The example contains no Wi-Fi, NVS, clock or audio code. You provide one function, onesay_voice_button_configure. Until you do, its default returns ONESAY_ERR_AUTH before connecting, so the unmodified example does not connect.

Your function suppliesWhy
Device credential callbacks, on your secure storageThe SDK exchanges the credential for a short-lived token
Device, Project, Environment, Application, Source and Room IDsThey name what the request is about. The server still checks every one
The environment ONESAY_ENVIRONMENT_CUSTOMThe addresses you appended to sdkconfig.defaults are its addresses
A network, trusted UTC and a verified certificate bundleThe SDK never disables certificate checks and does not set the clock
A PCM producer: 16 kHz, mono, signed 16-bit little-endianCapture, I2S, codec and tuning are your firmware's
A language, optionallyLeave it empty for automatic detection, or set a code such as zh-CN

The example needs a 20 KiB main task stack, in its sdkconfig.defaults, as the Device's capability report is sent from this task. Keep that in your project.

4. Allow the board's steps

A device acts for a person. Opening the board's audio needs a Delegation from your account, which names the participant the board gets when it joins the Room, so it is created during the run. The example waits for your event loop to select it. OneSay never grants a Delegation or Consent for you.

5. Run it

Text
idf.py -p <PORT> flash monitor

Flashing writes the application only, not the Device credential. Keep the log level at WARN, which keeps the SDK's and ESP-IDF's logs quiet.

Your event loop calls onesay_voice_button_init, then onesay_voice_button_connect, then bounded onesay_voice_button_step calls. The SDK handles sequence, acknowledgement, backpressure, replay and resume. When your producer reports that it has finished, the example ends the input once every frame is acknowledged. onesay_voice_button_close releases the transport.

Use real speech. Synthetic audio gets no final result on the pre-production environment.

What a good run looks like

You read delta results while audio is sent, then one final result. A successful cancel send is not a final Task result.

If something goes wrong

What you seeWhat it means
ONESAY_ERR_AUTH before any networkYour onesay_voice_button_configure is not in use, or did not return ONESAY_OK
The connection succeeds and audio is refusedThe capability report is missing or more than 300 seconds old, or the Delegation was not selected
No final resultThe input held no speech, or the input was not ended

Next