44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7+ #include <stdbool.h>
78#include <stdio.h>
89#include <string.h>
910
1011#include "esp_err.h"
1112#include "esp_log.h"
1213#include "soc/soc_caps.h"
14+ #include "esp_console.h"
15+ #include "argtable3/argtable3.h"
1316
1417#include "esp_gmf_io.h"
1518#include "esp_gmf_pipeline.h"
2326#if SOC_SDMMC_HOST_SUPPORTED == 1
2427#define VOICE2FILE (true)
2528#endif /* SOC_SDMMC_HOST_SUPPORTED == 1 */
29+ #ifdef CONFIG_GMF_AI_AUDIO_WAKEUP_ENABLE
2630#define WAKENET_ENABLE (true)
31+ #else
32+ #define WAKENET_ENABLE (false)
33+ #endif /* CONFIG_GMF_AI_AUDIO_WAKEUP_ENABLE */
34+ #ifdef CONFIG_GMF_AI_AUDIO_VOICE_COMMAND_ENABLE
35+ #define VCMD_ENABLE (true)
36+ #else
37+ #define VCMD_ENABLE (false)
38+ #endif /* CONFIG_GMF_AI_AUDIO_VOICE_COMMAND_ENABLE */
2739#define VAD_ENABLE (true)
2840#define QUIT_CMD_FOUND (BIT0)
2941
4759#endif /* defined CONFIG_IDF_TARGET_ESP32S3 */
4860
4961#if AUDIO_BOARD == BOARD_KORVO_2
50- #define AEC_ENABLE (true)
51- #define VCMD_ENABLE (true)
52-
53- #define ADC_I2S_PORT (0)
5462#define ADC_I2S_CH (2)
5563#define ADC_I2S_BITS (32)
5664#define INPUT_CH_NUM (4)
5765#define INPUT_CH_BITS (16) /* For board `ESP32-S3-Korvo-2`, the es7210 is configured as 32-bit,
5866 2-channel mode to accommodate 16-bit, 4-channel data */
5967#define INPUT_CH_ALLOCATION ("RMNM")
6068#elif AUDIO_BOARD == BOARD_LYRAT_MINI
61- #define AEC_ENABLE (false)
62- #define VCMD_ENABLE (false)
63-
64- #define ADC_I2S_PORT (1)
6569#define ADC_I2S_CH (2)
6670#define ADC_I2S_BITS (16)
6771#define INPUT_CH_NUM (ADC_I2S_CH)
6872#define INPUT_CH_BITS (ADC_I2S_BITS)
6973#define INPUT_CH_ALLOCATION ("RM")
7074#elif AUDIO_BOARD == BOARD_XD_AIOT_C3
71- #define AEC_ENABLE (false)
72- #define VCMD_ENABLE (false)
73-
74- #define ADC_I2S_PORT (0)
7575#define ADC_I2S_CH (2)
7676#define ADC_I2S_BITS (16)
7777#define INPUT_CH_NUM (ADC_I2S_CH)
7878#define INPUT_CH_BITS (ADC_I2S_BITS)
7979#define INPUT_CH_ALLOCATION ("MR")
8080#elif AUDIO_BOARD == BOARD_ESP_SPOT
81- #define AEC_ENABLE (false)
82- #define VCMD_ENABLE (false)
83-
84- #define ADC_I2S_PORT (0)
8581#define ADC_I2S_CH (2)
8682#define ADC_I2S_BITS (16)
8783#define INPUT_CH_NUM (ADC_I2S_CH)
@@ -102,6 +98,7 @@ static bool speeching = false;
10298static bool wakeup = false;
10399#endif /* WITH_AFE == true */
104100static EventGroupHandle_t g_event_group = NULL ;
101+ static esp_gmf_element_handle_t g_afe = NULL ;
105102
106103static esp_err_t _pipeline_event (esp_gmf_event_pkt_t * event , void * ctx )
107104{
@@ -158,14 +155,6 @@ void esp_gmf_afe_event_cb(esp_gmf_obj_handle_t obj, esp_gmf_afe_evt_t *event, vo
158155 esp_gmf_afe_vcmd_info_t * info = event -> event_data ;
159156 ESP_LOGW (TAG , "Command %d, phrase_id %d, prob %f, str: %s" ,
160157 event -> type , info -> phrase_id , info -> prob , info -> str );
161- /* Here use the first command to quit this demo
162- * For Chinese model, the first default command is `ba xiao shi hou guan ji`
163- * For English model, the first default command is `tell me a joke`
164- * If user had modified the commands, please refer to the commands setting.
165- */
166- if (event -> type == 1 ) {
167- xEventGroupSetBits (g_event_group , QUIT_CMD_FOUND );
168- }
169158 break ;
170159 }
171160 }
@@ -225,9 +214,58 @@ static esp_gmf_err_io_t outport_release_write(void *handle, esp_gmf_payload_t *l
225214 return ESP_GMF_IO_OK ;
226215}
227216
217+ static struct {
218+ struct arg_int * keep ;
219+ struct arg_end * end ;
220+ } keep_args ;
221+
222+ static int keep_awake (int argc , char * * argv )
223+ {
224+ int nerrors = arg_parse (argc , argv , (void * * )& keep_args );
225+ if (nerrors != 0 ) {
226+ arg_print_errors (stderr , keep_args .end , argv [0 ]);
227+ return ESP_FAIL ;
228+ }
229+ if (g_afe ) {
230+ esp_gmf_afe_keep_awake (g_afe , keep_args .keep -> ival [0 ]);
231+ printf ("Keep awake: %d\n" , keep_args .keep -> ival [0 ]);
232+ } else {
233+ ESP_LOGE (TAG , "AFE not found" );
234+ }
235+ return ESP_OK ;
236+ }
237+
238+ static int quit (int argc , char * * argv )
239+ {
240+ xEventGroupSetBits (g_event_group , QUIT_CMD_FOUND );
241+ return 0 ;
242+ }
243+
244+ static void wwe_cmds_register (void )
245+ {
246+ esp_console_cmd_t cmd_keep = {
247+ .command = "keep" ,
248+ .help = "keep awake" ,
249+ .hint = NULL ,
250+ .func = & keep_awake ,
251+ .argtable = & keep_args ,
252+ };
253+ keep_args .keep = arg_int0 (NULL , NULL , "<0 - 1>" , "Keep awake" );
254+ keep_args .end = arg_end (1 );
255+ esp_console_cmd_register (& cmd_keep );
256+
257+ esp_console_cmd_t cmd_quit = {
258+ .command = "quit" ,
259+ .help = "quit" ,
260+ .hint = NULL ,
261+ .func = & quit ,
262+ .argtable = NULL ,
263+ };
264+ esp_console_cmd_register (& cmd_quit );
265+ }
266+
228267void app_main (void )
229268{
230- int ret = 0 ;
231269 esp_log_level_set ("*" , ESP_LOG_INFO );
232270 esp_gmf_app_codec_info_t codec_info = ESP_GMF_APP_CODEC_INFO_DEFAULT ();
233271 codec_info .record_info .sample_rate = 16000 ;
@@ -255,9 +293,9 @@ void app_main(void)
255293 goto __quit ;
256294 }
257295 esp_gmf_io_codec_dev_set_dev (ESP_GMF_PIPELINE_GET_IN_INSTANCE (pipe ), esp_gmf_app_get_record_handle ());
258- esp_gmf_element_handle_t afe = NULL ;
259- esp_gmf_pipeline_get_el_by_name (pipe , "ai_afe" , & afe );
260- esp_gmf_afe_set_event_cb (afe , esp_gmf_afe_event_cb , NULL );
296+ #if WITH_AFE == true
297+ esp_gmf_pipeline_get_el_by_name (pipe , "ai_afe" , & g_afe );
298+ esp_gmf_afe_set_event_cb (g_afe , esp_gmf_afe_event_cb , NULL );
261299#else
262300 esp_gmf_element_handle_t wn = NULL ;
263301 esp_gmf_pipeline_get_el_by_name (pipe , "ai_wn" , & wn );
@@ -291,7 +329,7 @@ void app_main(void)
291329 esp_gmf_pipeline_set_event (pipe , _pipeline_event , NULL );
292330 esp_gmf_pipeline_run (pipe );
293331
294- esp_gmf_app_cli_init ("Audio >" , NULL );
332+ esp_gmf_app_cli_init ("Audio >" , wwe_cmds_register );
295333
296334 while (1 ) {
297335 EventBits_t bits = xEventGroupWaitBits (g_event_group , QUIT_CMD_FOUND , pdTRUE , pdFALSE , portMAX_DELAY );
0 commit comments