Skip to content

Commit 917126a

Browse files
authored
Example to support blog post for using LiveKit on custom hardware (#82)
1 parent 1ed3aa4 commit 917126a

16 files changed

Lines changed: 783 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ One of the best ways to get started with LiveKit is by reviewing the [examples](
3939
- [**Voice AI Agent**](./components/livekit/examples/voice_agent/README.md): Conversational AI voice agent that interacts with hardware based on user requests.
4040
- [**Minimal**](./components/livekit/examples/minimal/README.md): Basic example of connecting to a LiveKit room with bidirectional audio.
4141
- [**Minimal Video**](./components/livekit/examples/minimal_video/README.md): Equivalent to the minimal example with video publishing.
42+
- [**Custom Hardware**](./components/livekit/examples/custom_hardware/README.md): Bidirectional audio on custom ESP32-S3 hardware with manual codec initialization (ES8311 + ES7210).
4243

4344
Once you have chosen an example to be your starting point, create a fresh project from it locally using the following command:
4445

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# IDF
2+
**/sdkconfig
3+
**/sdkconfig.old
4+
**/build
5+
**/managed_components
6+
**/dependencies.lock
7+
**/dist
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
set(COMPONENTS main)
3+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
4+
project(lk_custom_hardware)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Custom Hardware
2+
3+
Example of connecting to a LiveKit room with bidirectional audio on custom ESP32-S3 hardware. Unlike the `minimal` example (which uses the `codec_board` abstraction), this example manually initializes I2C, I2S, and audio codecs (ES8311 + ES7210) using pin assignments extracted from the board schematic. Use this as a starting point when your board isn't supported by `codec_board`.
4+
5+
The [Waveshare ESP32-S3-Touch-LCD-1.83](https://www.waveshare.com/esp32-s3-touch-lcd-1.83.htm) is used as a concrete example, but the approach works for any ESP32-S3 board with I2S audio codecs — just update the pin definitions and codec configuration in `board.c`.
6+
7+
For a step-by-step walkthrough of this example, see the companion blog post: [Building a voice agent frontend on custom ESP32 hardware](https://livekit.io/blog/esp32-custom-hardware-quickstart).
8+
9+
## Configuration
10+
11+
> [!TIP]
12+
> Options can either be set through *menuconfig* or added to *sdkconfig* as shown below.
13+
14+
### Credentials
15+
16+
**Option A**: Use a LiveKit Sandbox to get up and running quickly. Setup a LiveKit Sandbox from your [Cloud Project](https://cloud.livekit.io/projects/p_/sandbox), and use its ID in your configuration:
17+
18+
```ini
19+
CONFIG_LK_EXAMPLE_USE_SANDBOX=y
20+
CONFIG_LK_EXAMPLE_SANDBOX_ID="my-project-xxxxxx"
21+
```
22+
23+
**Option B**: Specify a server URL and pregenerated token:
24+
25+
```ini
26+
CONFIG_LK_EXAMPLE_USE_PREGENERATED=y
27+
CONFIG_LK_EXAMPLE_TOKEN="your-jwt-token"
28+
CONFIG_LK_EXAMPLE_SERVER_URL="ws://localhost:7880"
29+
```
30+
31+
### Network
32+
33+
Connect using WiFi as follows:
34+
35+
```ini
36+
CONFIG_LK_EXAMPLE_USE_WIFI=y
37+
CONFIG_LK_EXAMPLE_WIFI_SSID="<your SSID>"
38+
CONFIG_LK_EXAMPLE_WIFI_PASSWORD="<your password>"
39+
```
40+
41+
> **Note:** The ESP32-S3 only supports 2.4 GHz WiFi.
42+
43+
### Board adaptation
44+
45+
This example is configured for the Waveshare ESP32-S3-Touch-LCD-1.83. To adapt it to your own board:
46+
47+
1. Update the pin definitions at the top of `main/board.c` (I2C, I2S, PA enable).
48+
2. Update the codec I2C addresses if your board uses different address strapping.
49+
3. If your board has no PMU, remove the `init_pmu()` call from `board_init()`.
50+
4. If your board uses different codecs, replace the ES8311/ES7210 initialization with the appropriate driver calls.
51+
52+
## Build & Flash
53+
54+
Navigate to this directory in your terminal. Run the following command to build your application, flash it to your board, and monitor serial output:
55+
56+
```sh
57+
idf.py flash monitor
58+
```
59+
60+
Once running, the example will establish a network connection, connect to a LiveKit room, and print the following message:
61+
62+
```txt
63+
I (3200) livekit_example: Room state changed: CONNECTED
64+
```
65+
66+
## Next Steps
67+
68+
With a room connection established, you can connect another client (another ESP32, [LiveKit Meet](https://meet.livekit.io), etc.) or dispatch an [agent](https://docs.livekit.io/agents/) to talk with.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
idf_component_register(SRCS "main.c" "example.c" "board.c" "media.c"
2+
INCLUDE_DIRS ".")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
menu "LiveKit Example"
2+
3+
choice LK_EXAMPLE_CONNECTION_METHOD
4+
prompt "Choose room connection method"
5+
config LK_EXAMPLE_USE_SANDBOX
6+
bool "Sandbox token"
7+
config LK_EXAMPLE_USE_PREGENERATED
8+
bool "Pre-generated token"
9+
endchoice
10+
11+
config LK_EXAMPLE_SERVER_URL
12+
depends on LK_EXAMPLE_USE_PREGENERATED
13+
string "Server URL"
14+
default "ws://localhost:7880"
15+
16+
config LK_EXAMPLE_TOKEN
17+
depends on LK_EXAMPLE_USE_PREGENERATED
18+
string "Token"
19+
20+
config LK_EXAMPLE_SANDBOX_ID
21+
depends on LK_EXAMPLE_USE_SANDBOX
22+
string "Sandbox ID"
23+
24+
config LK_EXAMPLE_ROOM_NAME
25+
depends on LK_EXAMPLE_USE_SANDBOX
26+
string "Room name (optional)"
27+
28+
config LK_EXAMPLE_PARTICIPANT_NAME
29+
depends on LK_EXAMPLE_USE_SANDBOX
30+
string "Participant name (optional)"
31+
32+
config LK_EXAMPLE_SPEAKER_VOLUME
33+
int "Default speaker volume (0-100%)"
34+
default 85
35+
range 0 100
36+
37+
endmenu

0 commit comments

Comments
 (0)