8000 Optimize ai audio state and Organize code by yingtao450 · Pull Request #150 · tuya/TuyaOpen · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Optimize ai audio state and Organize code #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

There are no files selected for viewing

21 changes: 1 addition & 20 deletions apps/tuya.ai/your_chat_bot/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config ENABLE_CHAT_BOT

choice
prompt "choose chat mode"
default ENABLE_CHAT_MODE_KEY_TRIG_VAD_FREE
default ENABLE_CHAT_MODE_ASR_WAKEUP_FREE

config ENABLE_CHAT_MODE_KEY_PRESS_HOLD_SINGEL
bool "press and hold button to start a single conversation."
Expand Down Expand Up @@ -46,25 +46,6 @@ if(ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL || ENABLE_CHAT_MODE_ASR_WAKEUP_FREE)
endchoice
endif

config ENABLE_AEC
bool "support AEC"
default n

config SPEAKER_EN_PIN
int "the pin for enabling the voice module"
range 0 64
default 28

config CHAT_BUTTON_PIN
int "the pin of the dialogue button"
range 0 64
default 12

config CHAT_INDICATE_LED_PIN
int "the pin of the led, indicate whether it is in the process of a dialogue."
range 0 64
default 1

config ENABLE_CHAT_DISPLAY
bool "enable the display module"
default n
Expand Down
2 changes: 0 additions & 2 deletions apps/tuya.ai/your_chat_bot/app_default.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_ENABLE_CHAT_DISPLAY=y
CONFIG_ENABLE_GUI_STREAM_AI_TEXT=y
CONFIG_BOARD_CHOICE_T5AI=y
Expand All @@ -20,4 +19,3 @@ CONFIG_LWIP_NETIF_STATUS_CALLBACK=1
CONFIG_LWIP_TIMEVAL_PRIVATE=0
CONFIG_IN_ADDR_T_DEFINED=y
CONFIG_ENABLE_LIBLVGL=y
CONFIG_ENABLE_DISPLAY_LCD_RGB=y
6 changes: 1 addition & 5 deletions apps/tuya.ai/your_chat_bot/config/DNESP32S3.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_ENABLE_WAKEUP_KEYWORD_NIHAO_XIAOZHI=y
CONFIG_CHAT_BUTTON_PIN=0
CONFIG_CHAT_INDICATE_LED_PIN=1
CONFIG_ENABLE_CHAT_DISPLAY=n
CONFIG_BOARD_CHOICE_ESP32=y
CONFIG_MODULE_CHOICE_DNESP32S3=y
# CONFIG_ENABLE_LIBLWIP is not set
CONFIG_BOARD_CHOICE_DNESP32S3=y
9 changes: 2 additions & 7 deletions apps/tuya.ai/your_chat_bot/config/DNESP32S3_BOX.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_ENABLE_WAKEUP_KEYWORD_NIHAO_XIAOZHI=y
CONFIG_SPEAKER_EN_PIN=64
CONFIG_CHAT_BUTTON_PIN=0
CONFIG_CHAT_INDICATE_LED_PIN=48
CONFIG_ENABLE_CHAT_DISPLAY=y
CONFIG_ENABLE_GUI_CHATBOT=y
CONFIG_BOARD_CHOICE_ESP32=y
CONFIG_MODULE_CHOICE_DNESP32S3_BOX=y
CONFIG_ENABLE_LIBLVGL=y
CONFIG_ENABLE_PLATFORM_LVGL=y
CONFIG_BOARD_CHOICE_DNESP32S3_BOX=y
CONFIG_ENABLE_LIBLVGL=y
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_ENABLE_WAKEUP_KEYWORD_NIHAO_XIAOZHI=y
CONFIG_SPEAKER_EN_PIN=64
CONFIG_CHAT_BUTTON_PIN=0
CONFIG_CHAT_INDICATE_LED_PIN=48
CONFIG_ENABLE_CHAT_DISPLAY=y
CONFIG_ENABLE_GUI_OLED=y
CONFIG_BOARD_CHOICE_ESP32=y
CONFIG_BOARD_CHOICE_BREAD_COMPACT_WIFI=y
CONFIG_ENABLE_LIBLVGL=y
CONFIG_ENABLE_PLATFORM_LVGL=y
CONFIG_ENABLE_LIBLVGL=y
4 changes: 0 additions & 4 deletions apps/tuya.ai/your_chat_bot/config/T5AI_MOJI_1.28.config
< 6D4E td class="blob-num blob-num-deletion empty-cell">
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_SPEAKER_EN_PIN=7
CONFIG_CHAT_BUTTON_PIN=17
CONFIG_CHAT_INDICATE_LED_PIN=18
CONFIG_ENABLE_CHAT_DISPLAY=y
CONFIG_ENABLE_GUI_CHATBOT=y
CONFIG_BOARD_CHOICE_T5AI=y
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_ENABLE_CHAT_DISPLAY=y
CONFIG_ENABLE_GUI_STREAM_AI_TEXT=y
CONFIG_BOARD_CHOICE_T5AI=y
Expand All @@ -20,4 +19,4 @@ CONFIG_LWIP_NETIF_STATUS_CALLBACK=1
CONFIG_LWIP_TIMEVAL_PRIVATE=0
CONFIG_IN_ADDR_T_DEFINED=y
CONFIG_ENABLE_LIBLVGL=y
CONFIG_ENABLE_DISPLAY_LCD_RGB=y
CONFIG_ENABLE_DISPLAY_LCD_RGB=y
7 changes: 1 addition & 6 deletions apps/tuya.ai/your_chat_bot/config/TUYA_T5AI_EVB.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_ENABLE_AEC=y
CONFIG_SPEAKER_EN_PIN=19
CONFIG_CHAT_BUTTON_PIN=4
CONFIG_CHAT_INDICATE_LED_PIN=8
CONFIG_ENABLE_CHAT_DISPLAY=y
CONFIG_ENABLE_GUI_CHATBOT=y
CONFIG_BOARD_CHOICE_T5AI=y
Expand Down Expand Up @@ -32,4 +27,4 @@ CONFIG_ENABLE_LCD_POWER_CTRL=y
CONFIG_DISPLAY_LCD_BL_PIN=5
CONFIG_LCD_SPI_CS_PIN=15
CONFIG_LCD_SPI_DC_PIN=17
CONFIG_LCD_SPI_RST_PIN=6
CONFIG_LCD_SPI_RST_PIN=6
2 changes: 0 additions & 2 deletions apps/tuya.ai/your_chat_bot/config/TUYA_T5AI_MINI.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_SPEAKER_EN_PIN=27
CONFIG_CHAT_BUTTON_PIN=33
CONFIG_BOARD_CHOICE_T5AI=y
CONFIG_BOARD_CHOICE_TUYA_T5AI_MINI=y
CONFIG_MEM_SIZE=51200
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_ENABLE_WAKEUP_KEYWORD_NIHAO_XIAOZHI=y
CONFIG_SPEAKER_EN_PIN=64
CONFIG_CHAT_BUTTON_PIN=0
CONFIG_CHAT_INDICATE_LED_PIN=48
CONFIG_ENABLE_CHAT_DISPLAY=y
CONFIG_ENABLE_GUI_CHATBOT=y
CONFIG_BOARD_CHOICE_ESP32=y
CONFIG_BOARD_CHOICE_WAVESHARE_ESP32_S3_TOUCH_AMOLED_1_8=y
CONFIG_ENABLE_LIBLVGL=y
CONFIG_ENABLE_PLATFORM_LVGL=y
CONFIG_ENABLE_LIBLVGL=y
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
CONFIG_ENABLE_CHAT_MODE_ASR_WAKEUP_SINGEL=y
CONFIG_ENABLE_WAKEUP_KEYWORD_NIHAO_XIAOZHI=y
CONFIG_SPEAKER_EN_PIN=64
CONFIG_CHAT_BUTTON_PIN=0
CONFIG_CHAT_INDICATE_LED_PIN=48
CONFIG_ENABLE_CHAT_DISPLAY=y
CONFIG_ENABLE_GUI_OLED=y
CONFIG_OLED_SSD1306_128X64=y
CONFIG_BOARD_CHOICE_ESP32=y
CONFIG_BOARD_CHOICE_XINGZHI_CUBE_0_96_OLED_WIFI=y
CONFIG_ENABLE_LIBLVGL=y
CONFIG_ENABLE_PLATFORM_LVGL=y
CONFIG_ENABLE_LIBLVGL=y
23 changes: 18 additions & 5 deletions apps/tuya.ai/your_chat_bot/include/ai_audio/ai_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,31 @@ typedef enum {
AI_AUDIO_EVT_AI_REPLIES_TEXT_END,
AI_AUDIO_EVT_AI_REPLIES_EMO,
AI_AUDIO_EVT_ASR_WAKEUP,
AI_AUDIO_EVT_ASR_WAKEUP_END,
} AI_AUDIO_EVENT_E;

typedef enum {
AI_AUDIO_STATE_STANDBY,
AI_AUDIO_STATE_LISTEN,
AI_AUDIO_STATE_UPLOAD,
AI_AUDIO_STATE_AI_SPEAK,
} AI_AUDIO_STATE_E;

typedef struct {
char *name;
char *text;
} AI_AUDIO_EMOTION_T;

typedef void (*AI_AUDIO_INFORM_CB)(AI_AUDIO_EVENT_E event, uint8_t *data, uint32_t len, void *arg);
typedef void (*AI_AUDIO_EVT_INFORM_CB)(AI_AUDIO_EVENT_E event, uint8_t *data, uint32_t len, void *arg);
typedef void (*AI_AUDIO_STATE_INFORM_CB)(AI_AUDIO_STATE_E state);

/***********************************************************
***********************typedef define***********************
***********************************************************/

typedef struct {
AI_AUDIO_WORK_MODE_E work_mode;
AI_AUDIO_INFORM_CB inform_cb;
AI_AUDIO_WORK_MODE_E work_mode;
AI_AUDIO_EVT_INFORM_CB evt_inform_cb;
AI_AUDIO_STATE_INFORM_CB state_inform_cb;
} AI_AUDIO_CONFIG_T;

/***********************************************************
Expand Down Expand Up @@ -87,4 +96,8 @@ OPERATE_RET ai_audio_set_open(bool is_open);

OPERATE_RET ai_audio_manual_start_single_talk(void);

OPERATE_RET ai_audio_manual_stop_single_talk(void);
OPERATE_RET ai_audio_manual_stop_single_talk(void);

OPERATE_RET ai_audio_set_wakeup(void);

AI_AUDIO_STATE_E ai_audio_get_state(void);
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ OPERATE_RET ai_audio_cloud_asr_init(void);

/**
* @brief Starts the audio cloud ASR process.
* @param None
* @param none
* @return OPERATE_RET - OPRT_OK if the start operation is successful, otherwise an error code.
*/
OPERATE_RET ai_audio_cloud_asr_start(void);
Expand Down
7 changes: 6 additions & 1 deletion apps/tuya.ai/your_chat_bot/include/app_chat_bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ extern "C" {
***********************typedef define***********************
***********************************************************/





/***********************************************************
********************function declaration********************
***********************************************************/

OPERATE_RET app_chat_bot_init(void);



uint8_t app_chat_bot_get_enable(void);

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion apps/tuya.ai/your_chat_bot/include/app_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ OPERATE_RET app_display_init(void);
* @param len Length of the message data
* @return OPERATE_RET Result of sending the message, OPRT_OK indicates success
*/
OPERATE_RET app_display_send_msg(TY_DISPLAY_TYPE_E tp, char *data, int len);
OPERATE_RET app_display_send_msg(TY_DISPLAY_TYPE_E tp, uint8_t *data, int len);

#ifdef __cplusplus
}
Expand Down
2 changes: 0 additions & 2 deletions apps/tuya.ai/your_chat_bot/src/ai_audio/ai_audio_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ static OPERATE_RET __ai_agent_txt_recv(AI_BIZ_ATTR_INFO_T *attr, AI_BIZ_HEAD_INF
return OPRT_OK;
}

// PR_DEBUG("content: %s", data);

// parse bizType
node = cJSON_GetObjectItem(json, "bizType");
const char *bizType = cJSON_GetStringValue(node);
Expand Down
17 changes: 6 additions & 11 deletions apps/tuya.ai/your_chat_bot/src/ai_audio/ai_audio_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "tkl_thread.h"
#include "tkl_mutex.h"

#include "app_board_api.h"
#include "tdl_audio_manage.h"

#include "tal_api.h"
Expand Down Expand Up @@ -369,7 +368,7 @@ AI_AUDIO_INPUT_EVENT_E __ai_audio_input_get_event(AI_AUDIO_INPUT_STATE_E curr_st
static void __ai_audio_get_input_frame(TDL_AUDIO_FRAME_FORMAT_E type, TDL_AUDIO_STATUS_E status, uint8_t *data,
uint32_t len)
{
#if defined(ENABLE_AEC) && (ENABLE_AEC == 1)
#if defined(ENABLE_AUDIO_AEC) && (ENABLE_AUDIO_AEC == 1)

#else
if (true == ai_audio_player_is_playing()) {
Expand Down Expand Up @@ -434,14 +433,13 @@ static void __ai_audio_handle_frame_task(void *arg)
}
}

static OPERATE_RET __ai_audio_input_hardware_init(void)
static OPERATE_RET __ai_audio_input_open(void)
{
OPERATE_RET rt = OPRT_OK;

TDL_AUDIO_HANDLE_T audio_hdl = NULL;

app_audio_driver_init(AUDIO_DRIVER_NAME);
TUYA_CALL_ERR_RETURN(tdl_audio_find(AUDIO_DRIVER_NAME, &audio_hdl));
TUYA_CALL_ERR_RETURN(tdl_audio_find(AUDIO_CODEC_NAME, &audio_hdl));
TUYA_CALL_ERR_RETURN(tdl_audio_open(audio_hdl, __ai_audio_get_input_frame));

PR_DEBUG("__ai_audio_input_hardware_init success");
Expand Down Expand Up @@ -496,7 +494,7 @@ OPERATE_RET ai_audio_input_init(AI_AUDIO_INPUT_CFG_T *cfg, AI_AUDIO_INOUT_INFORM

TUYA_CALL_ERR_RETURN(__ai_audio_input_set_method(cfg->get_valid_data_method));

TUYA_CALL_ERR_RETURN(__ai_audio_input_hardware_init());
TUYA_CALL_ERR_RETURN(__ai_audio_input_open());

sg_audio_input_inform_cb = cb;

Expand Down Expand Up @@ -594,13 +592,10 @@ OPERATE_RET ai_audio_input_restart_asr_awake_timer(void)
return OPRT_NOT_SUPPORTED;
}

if (false == sg_audio_input.asr.is_wakeup) {
PR_ERR("asr wakeup is already timeout");
return OPRT_COM_ERROR;
}

tal_sw_timer_start(sg_audio_input.asr.wakeup_timer_id, ASR_WAKEUP_TIMEOUT_MS, TAL_TIMER_ONCE);

sg_audio_input.asr.is_wakeup = true;

return OPRT_OK;
}

Expand Down
Loading
0