Skip to content

Commit e8df6dc

Browse files
committed
Merge branch 'feature/afe_manual_trigger_main' into 'main'
feat(gmf_ai_audio): Added interfaces to manual trigger wakeup and sleep state See merge request adf/multimedia/esp-gmf!169
2 parents a3a002f + 0c69d85 commit e8df6dc

File tree

5 files changed

+220
-26
lines changed

5 files changed

+220
-26
lines changed

elements/gmf_ai_audio/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v0.7.2
4+
5+
### Features
6+
7+
- Added `esp_gmf_afe_trigger_wakeup` and `esp_gmf_afe_trigger_sleep` APIs to trigger wakeup and sleep events manually
8+
39
## v0.7.1
410

511
### Features

elements/gmf_ai_audio/examples/wwe/main/main.c

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#else
3737
#define VCMD_ENABLE (false)
3838
#endif /* CONFIG_GMF_AI_AUDIO_VOICE_COMMAND_ENABLE */
39-
#define VAD_ENABLE (true)
4039
#define QUIT_CMD_FOUND (BIT0)
4140

4241
#define BOARD_LYRAT_MINI (0)
@@ -64,25 +63,21 @@
6463
#define INPUT_CH_NUM (4)
6564
#define INPUT_CH_BITS (16) /* For board `ESP32-S3-Korvo-2`, the es7210 is configured as 32-bit,
6665
2-channel mode to accommodate 16-bit, 4-channel data */
67-
#define INPUT_CH_ALLOCATION ("RMNM")
6866
#elif AUDIO_BOARD == BOARD_LYRAT_MINI
6967
#define ADC_I2S_CH (2)
7068
#define ADC_I2S_BITS (16)
7169
#define INPUT_CH_NUM (ADC_I2S_CH)
7270
#define INPUT_CH_BITS (ADC_I2S_BITS)
73-
#define INPUT_CH_ALLOCATION ("RM")
7471
#elif AUDIO_BOARD == BOARD_XD_AIOT_C3
7572
#define ADC_I2S_CH (2)
7673
#define ADC_I2S_BITS (16)
7774
#define INPUT_CH_NUM (ADC_I2S_CH)
7875
#define INPUT_CH_BITS (ADC_I2S_BITS)
79-
#define INPUT_CH_ALLOCATION ("MR")
8076
#elif AUDIO_BOARD == BOARD_ESP_SPOT
8177
#define ADC_I2S_CH (2)
8278
#define ADC_I2S_BITS (16)
8379
#define INPUT_CH_NUM (ADC_I2S_CH)
8480
#define INPUT_CH_BITS (ADC_I2S_BITS)
85-
#define INPUT_CH_ALLOCATION ("MR")
8681
#endif /* AUDIO_BOARD == BOARD_KORVO_2 */
8782

8883
#if WITH_AFE == true
@@ -98,7 +93,9 @@ static bool speeching = false;
9893
static bool wakeup = false;
9994
#endif /* WITH_AFE == true */
10095
static EventGroupHandle_t g_event_group = NULL;
96+
#if WITH_AFE == true
10197
static esp_gmf_element_handle_t g_afe = NULL;
98+
#endif /* WITH_AFE == true */
10299

103100
static esp_err_t _pipeline_event(esp_gmf_event_pkt_t *event, void *ctx)
104101
{
@@ -118,8 +115,12 @@ void esp_gmf_afe_event_cb(esp_gmf_obj_handle_t obj, esp_gmf_afe_evt_t *event, vo
118115
esp_gmf_afe_vcmd_detection_cancel(obj);
119116
esp_gmf_afe_vcmd_detection_begin(obj);
120117
#endif /* WAKENET_ENABLE == true && VCMD_ENABLE == true */
121-
esp_gmf_afe_wakeup_info_t *info = event->event_data;
122-
ESP_LOGI(TAG, "WAKEUP_START [%d : %d]", info->wake_word_index, info->wakenet_model_index);
118+
if (event->event_data) {
119+
esp_gmf_afe_wakeup_info_t *info = event->event_data;
120+
ESP_LOGI(TAG, "WAKEUP_START [%d : %d]", info->wake_word_index, info->wakenet_model_index);
121+
} else {
122+
ESP_LOGI(TAG, "WAKEUP_START");
123+
}
123124
break;
124125
}
125126
case ESP_GMF_AFE_EVT_WAKEUP_END: {
@@ -172,7 +173,7 @@ static void esp_gmf_wn_event_cb(esp_gmf_obj_handle_t obj, int32_t trigger_ch, vo
172173

173174
static void voice_2_file(uint8_t *buffer, int len)
174175
{
175-
#if VOICE2FILE == true
176+
#if VOICE2FILE == true && WITH_AFE == true
176177
#define MAX_FNAME_LEN (50)
177178

178179
static FILE *fp = NULL;
@@ -198,7 +199,7 @@ static void voice_2_file(uint8_t *buffer, int len)
198199
fp = NULL;
199200
}
200201
}
201-
#endif /* VOICE2FILE == true */
202+
#endif /* VOICE2FILE == true && WITH_AFE == true */
202203
}
203204

204205
static esp_gmf_err_io_t outport_acquire_write(void *handle, esp_gmf_payload_t *load, int wanted_size, int block_ticks)
@@ -214,6 +215,7 @@ static esp_gmf_err_io_t outport_release_write(void *handle, esp_gmf_payload_t *l
214215
return ESP_GMF_IO_OK;
215216
}
216217

218+
#if WITH_AFE == true
217219
static struct {
218220
struct arg_int *keep;
219221
struct arg_end *end;
@@ -235,6 +237,29 @@ static int keep_awake(int argc, char **argv)
235237
return ESP_OK;
236238
}
237239

240+
static struct {
241+
struct arg_str *cmd;
242+
struct arg_end *end;
243+
} trigger_args;
244+
245+
static int trigger(int argc, char **argv)
246+
{
247+
int nerrors = arg_parse(argc, argv, (void **)&trigger_args);
248+
if (nerrors != 0) {
249+
arg_print_errors(stderr, trigger_args.end, argv[0]);
250+
return ESP_FAIL;
251+
}
252+
if (g_afe) {
253+
if (strcmp(trigger_args.cmd->sval[0], "wakeup") == 0) {
254+
esp_gmf_afe_trigger_wakeup(g_afe);
255+
} else if (strcmp(trigger_args.cmd->sval[0], "sleep") == 0) {
256+
esp_gmf_afe_trigger_sleep(g_afe);
257+
}
258+
}
259+
return 0;
260+
}
261+
#endif /* WITH_AFE == true */
262+
238263
static int quit(int argc, char **argv)
239264
{
240265
xEventGroupSetBits(g_event_group, QUIT_CMD_FOUND);
@@ -243,6 +268,7 @@ static int quit(int argc, char **argv)
243268

244269
static void wwe_cmds_register(void)
245270
{
271+
#if WITH_AFE == true
246272
esp_console_cmd_t cmd_keep = {
247273
.command = "keep",
248274
.help = "keep awake",
@@ -254,6 +280,18 @@ static void wwe_cmds_register(void)
254280
keep_args.end = arg_end(1);
255281
esp_console_cmd_register(&cmd_keep);
256282

283+
esp_console_cmd_t cmd_trigger_wakeup = {
284+
.command = "trigger",
285+
.help = "trigger wakeup or sleep",
286+
.hint = NULL,
287+
.func = &trigger,
288+
.argtable = &trigger_args,
289+
};
290+
trigger_args.cmd = arg_str0(NULL, NULL, "<wakeup|sleep>", "Trigger wakeup or sleep");
291+
trigger_args.end = arg_end(1);
292+
esp_console_cmd_register(&cmd_trigger_wakeup);
293+
#endif /* WITH_AFE == true */
294+
257295
esp_console_cmd_t cmd_quit = {
258296
.command = "quit",
259297
.help = "quit",

elements/gmf_ai_audio/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.7.1"
1+
version: "0.7.2"
22
description: Espressif GMF AI Audio Elements Module
33
url: https://github.com/espressif/esp-gmf/tree/main/elements/gmf_ai_audio
44
documentation: "https://github.com/espressif/esp-gmf/blob/main/elements/gmf_ai_audio/README.md"

elements/gmf_ai_audio/include/esp_gmf_afe.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,49 @@ esp_gmf_err_t esp_gmf_afe_set_event_cb(esp_gmf_element_handle_t handle, esp_gmf_
175175
* - ESP_GMF_ERR_OK Success
176176
* - ESP_GMF_ERR_INVALID_ARG Invalid argument
177177
* - ESP_GMF_ERR_INVALID_STATE Config not exist
178+
* - ESP_GMF_ERR_TIMEOUT Command send timeout
178179
*/
179180
esp_gmf_err_t esp_gmf_afe_keep_awake(esp_gmf_element_handle_t handle, bool enable);
180181

182+
/**
183+
* @brief Manually trigger wakeup state
184+
*
185+
* This function allows manual activation of the wakeup state without waiting
186+
* for automatic wakeword detection. It is useful in the following scenarios:
187+
*
188+
* 1. **Button-triggered activation**: When users press a physical button to
189+
* activate voice interaction, bypassing the need for wakewords
190+
* 2. **External event-driven activation**: When the system needs to enter
191+
* wakeup state based on external triggers (sensors, timers, network events)
192+
*
193+
* After calling this function, the AFE will enter wakeup state and begin
194+
* listening for voice commands (if voice command detection is enabled).
195+
* The system will generate ESP_GMF_AFE_EVT_WAKEUP_START event and remain
196+
* active according to the configured wakeup_time duration.
197+
*
198+
* @param[in] handle Handle to the GMF object
199+
*
200+
* @return
201+
* - ESP_GMF_ERR_OK Success
202+
* - ESP_GMF_ERR_INVALID_ARG Invalid argument
203+
* - ESP_GMF_ERR_INVALID_STATE Element not opened
204+
* - ESP_GMF_ERR_TIMEOUT Command send timeout
205+
*/
206+
esp_gmf_err_t esp_gmf_afe_trigger_wakeup(esp_gmf_element_handle_t handle);
207+
208+
/**
209+
* @brief Manually trigger sleep of wakeup state
210+
*
211+
* @param[in] handle Handle to the GMF object
212+
*
213+
* @return
214+
* - ESP_GMF_ERR_OK Success
215+
* - ESP_GMF_ERR_INVALID_ARG Invalid argument
216+
* - ESP_GMF_ERR_INVALID_STATE Element not opened
217+
* - ESP_GMF_ERR_TIMEOUT Command send timeout
218+
*/
219+
esp_gmf_err_t esp_gmf_afe_trigger_sleep(esp_gmf_element_handle_t handle);
220+
181221
#ifdef __cplusplus
182222
}
183223
#endif /* __cplusplus */

0 commit comments

Comments
 (0)