File size: 7,171 Bytes
87337b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# Agora ESP32 Large Model Intelligent Dialogue

*[็ฎ€ไฝ“ไธญๆ–‡](./README.cn.md) | English*

## Overview

This is an RTC Client SDK & Demo running on Espressif ESP32-S3 Korvo V3 development board. This example demonstrates how to make TEN-Agent work with it.

### File Structure
```
โ”œโ”€โ”€ CMakeLists.txt
โ”œโ”€โ”€ components                                  Agora IoT SDK component
โ”‚ย ย  โ”œโ”€โ”€ agora_iot_sdk
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ CMakeLists.txt
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ include                             Agora IoT SDK header files
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ agora_rtc_api.h
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ libs                                Agora IoT SDK libraries                      
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ libagora-cjson.a
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ libahpl.a
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ librtsa.a
โ”œโ”€โ”€ main                                        LLM Demo code
โ”‚ย ย  โ”œโ”€โ”€ ai_agent.h
โ”‚ย ย  โ”œโ”€โ”€ app_config.h
โ”‚ย ย  โ”œโ”€โ”€ common.h
โ”‚ย ย  โ”œโ”€โ”€ audio_proc.h
โ”‚ย ย  โ”œโ”€โ”€ rtc_proc.h
โ”‚ย ย  โ”œโ”€โ”€ CMakeLists.txt
โ”‚ย ย  โ”œโ”€โ”€ Kconfig.projbuild
|   โ”œโ”€โ”€ ai_agent.c
|   โ”œโ”€โ”€ audio_proc.c
|   โ”œโ”€โ”€ rtc_proc.c
โ”‚ย ย  โ””โ”€โ”€ llm_main.c
โ”œโ”€โ”€ partitions.csv                              Partition table
โ”œโ”€โ”€ README.en.md
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ sdkconfig.defaults
โ””โ”€โ”€ sdkconfig.defaults.esp32s3
```

## Environment Setup

### Hardware Requirements

This example currently supports the `ESP32-S3-Korvo-2 V3` development board only.

## Compilation and Download

### Agora IOT SDK

To compile and run this example, you need the Agora IoT SDK.
The SDK can be downloaded at [here](https://rte-store.s3.amazonaws.com/agora_iot_sdk.tar)
Put `agora_iot_sdk.tar` to `esp32-client/components` directory and run the following command:

```bash
cd esp32-client/components
tar -xvf agora_iot_sdk.tar
```

### Linux Operating System

#### Default IDF Branch

This example supports IDF tag v[5.2.3] and later versions, with the default set to IDF tag v[5.2.3] (commit id: c9763f62dd00c887a1a8fafe388db868a7e44069).

To select the correct IDF branch, run the following commands:
```bash
cd $IDF_PATH
git checkout v5.2.3
git pull
git submodule update --init --recursive
```

This example supports ADF v2.7 tag (commit id: 9cf556de500019bb79f3bb84c821fda37668c052).

#### Applying the IDF Patch

A patch must be applied to IDF. Use the following command:
```bash
export ADF_PATH=~/esp/esp-adf
cd $IDF_PATH
git apply $ADF_PATH/idf_patches/idf_v5.2_freertos.patch
```

#### Compiling the Firmware

Copy the example project directory (esp32-client) to the `~/esp` directory and run the following commands:
```bash
$ . $HOME/esp/esp-idf/export.sh
$ cd ~/esp/esp32-client
$ idf.py set-target esp32s3
$ idf.py menuconfig	--> Agora Demo for ESP32 --> (Configure WIFI SSID and Password)
$ idf.py build
```

To configure FreeRTOS backward compatibility:
In `menuconfig`, navigate to `Component config` --> `FreeRTOS` --> `Kernel` and enable `configENABLE_BACKWARD_COMPATIBILITY`.

### Windows Operating System

#### Default IDF Branch

Download IDF, selecting version v5.2.3 (offline version) from the following link:  
[ESP-IDF Windows Setup](https://docs.espressif.com/projects/esp-idf/zh_CN/v5.2.3/esp32/get-started/windows-setup.html)

Download ADF to the `Espressif/frameworks` directory to support ADF v2.7 tag (commit id: 9cf556de500019bb79f3bb84c821fda37668c052):  
[ESP-ADF Setup](https://docs.espressif.com/projects/esp-adf/zh_CN/latest/get-started/index.html#step-2-get-esp-adf)

#### Applying the IDF Patch

Method 1: Add `ADF_PATH` to the environment variables in system settings:
```
E:\esp32s3\Espressif\frameworks\esp-adf
```

Method 2: Add `ADF_PATH` via the command line:
```bash
$ setx ADF_PATH Espressif/frameworks/esp-adf
```

**Note:** After setting the `ADF_PATH` environment variable, restart ESP-IDF 5.2 PowerShell for changes to take effect.

Apply the required patch to IDF using:
```bash
cd $IDF_PATH
git apply $ADF_PATH/idf_patches/idf_v5.2_freertos.patch
```

#### Compiling the Firmware

Copy the example project directory (esp32-client) to the `Espressif/frameworks` directory and run the following commands:
```bash
$ cd ../esp32-client
$ idf.py set-target esp32s3
$ idf.py menuconfig	--> Agora Demo for ESP32 --> (Configure WIFI SSID and Password)
$ idf.py build
```

Configure FreeRTOS backward compatibility:  
In `menuconfig`, navigate to `Component config` --> `FreeRTOS` --> `Kernel` and enable `configENABLE_BACKWARD_COMPATIBILITY`.

### Flashing the Firmware

Run the following command:
```bash
$ idf.py -p /dev/ttyUSB0 flash monitor
```
**Note:** On Linux, you might encounter permission issues with `/dev/ttyUSB0`. Run the following command to fix it:
```bash
sudo usermod -aG dialout $USER
```

Once flashing is complete, the example will run automatically. After the device joins the RTC channel, the serial output will display:  
**"Agora: Press [SET] key to Join the Ai Agent ..."**

## How to Use the Example

### Quick Start in 5 Minutes

**Note:**  
Ensure at least one speaker is connected to the development board.


### Configure your own agent

Let's walk you through creating your own user and device accounts.

#### Update app_config.h

1. Open the `app_config.h` file in the project.
2. Modify `TENAI_AGENT_URL` to the URL of your TEN-Agent server (usually the 8080 port service).
3. Modify `AI_AGENT_CHANNEL_NAME` to a unique channel name.
4. If you have your Ten-Agent configured for `openai_v2v` graph working, you should be good to go.
5. If you want to use other graphs, you can modify how request is constructed in `ai_agent.c` file the `_build_start_json` method.
6. Recompile and flash the firmware.

#### Demo: Real-time Voice Dialogue with Large Model AiAgent

1. Press the `SET` button to start the large model.
2. Press the `MUTE` button to stop the large model.
3. Press the `VOL+` button to increase volume (increments of 10, up to a maximum of 100).
4. Press the `VOL-` button to decrease volume (decrements of 10, down to a minimum of 0).
5. After the device boots up, it will automatically connect to the RTC channel associated with the generated APPID. Press the `SET` button to initiate real-time voice dialogue; press the `MUTE` button to stop it.


## About Agora

Agoraโ€™s audio and video IoT platform leverages its proprietary real-time transmission network, **Agora SD-RTNโ„ข (Software Defined Real-time Network)**, to provide real-time audio and video streaming capabilities for Linux/RTOS devices with networking capabilities. The solution ensures high connectivity, real-time performance, and stability even under uncertain network conditions using advanced techniques such as forward error correction, intelligent retransmission, bandwidth prediction, and stream smoothing. Additionally, it offers a minimal memory footprint, making it ideal for resource-constrained IoT devices, including the entire Espressif ESP32 series.

## Technical Support

For technical support, follow the links below:

- Report bugs and inquiries directly to the community representatives.

We will respond as soon as possible.