fix: ensure OTA prompt plays before upgrade
This commit is contained in:
@@ -49,7 +49,7 @@ static int16 *ppbuff=mp3_buff;
|
||||
static int onmessage_status = -1;
|
||||
volatile int tts_playing = 0;
|
||||
unsigned char wss_connect_start = 0;
|
||||
static int player_mq_couter = 0;
|
||||
static volatile int player_mq_couter = 0;
|
||||
static unsigned char audio_in_task_cancel = 0;
|
||||
|
||||
static unsigned char xiaoice_wss_connect_status = 0;
|
||||
@@ -105,6 +105,11 @@ static librws_app_t app = &_app;
|
||||
static ql_sem_t ws_connect_sem = NULL;
|
||||
extern int fota_start;
|
||||
|
||||
#define OTA_AUDIO_STOP_TIMEOUT_MS 3000
|
||||
#define OTA_AUDIO_STOP_POLL_MS 20
|
||||
|
||||
void xiaoice_clear_player_mq(void);
|
||||
|
||||
|
||||
static int tts_play_status = 0;//1播放中 2播放完成
|
||||
|
||||
@@ -234,8 +239,13 @@ void add_file_to_play_player_queue(char *path, int type)
|
||||
|
||||
|
||||
//如果录音后 超过10s 还没有收到信息 提示本轮对话结束
|
||||
static void onmessage_text(rws_socket socket, const char *text, const unsigned int len)
|
||||
{
|
||||
static void onmessage_text(rws_socket socket, const char *text, const unsigned int len)
|
||||
{
|
||||
if (fota_start == 1) {
|
||||
printf("ignore websocket audio during OTA\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// printf("message(txt), %d(byte): %s ", len, text);
|
||||
|
||||
char url_buff[128]={0x00};
|
||||
@@ -820,6 +830,49 @@ int app_play_tips_file(int index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_play_ota_tips_file(void)
|
||||
{
|
||||
char filename_buff[64] = {0};
|
||||
uint32_t timeout;
|
||||
|
||||
/* OTA owns the audio path from this point on. Stop the active conversation
|
||||
* before queuing the prompt, otherwise recording/TTS rejects or masks it. */
|
||||
if (vad_audio_is_recording()) {
|
||||
vad_audio_stop_record();
|
||||
}
|
||||
|
||||
if (get_xiaoice_connected_status() == 2) {
|
||||
talkingq_ws_disconnect();
|
||||
}
|
||||
|
||||
tts_playing = 2;
|
||||
xiaoice_clear_player_mq();
|
||||
|
||||
timeout = hal_os_up_time_ms();
|
||||
while (player_mq_couter > 0) {
|
||||
ql_rtos_task_sleep_ms(OTA_AUDIO_STOP_POLL_MS);
|
||||
if (hal_os_up_time_ms() - timeout > OTA_AUDIO_STOP_TIMEOUT_MS) {
|
||||
printf("OTA wait previous audio timeout, counter:%d\r\n",
|
||||
player_mq_couter);
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
tts_play_status = 0;
|
||||
tts_playing = 0;
|
||||
|
||||
/* Normal prompts are blocked while fota_start is set. Queue the dedicated
|
||||
* OTA prompt directly after the old conversation has fully stopped. */
|
||||
snprintf(filename_buff, sizeof(filename_buff), "U:/%s", mp3_file[3]);
|
||||
printf("xiaoice_play_index:3\n");
|
||||
if (ql_access(filename_buff, 0) != 0) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
add_file_to_play_player_queue(filename_buff, 0);
|
||||
return player_mq_couter > 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
void app_player_thread(void *arvg)
|
||||
{
|
||||
ice_work_item *player_item=NULL;
|
||||
@@ -1044,12 +1097,12 @@ void xiaoice_clear_player_mq(void)
|
||||
free(player_item->data);
|
||||
player_item->data = NULL;
|
||||
}
|
||||
if(player_mq_couter>0) player_mq_couter--;
|
||||
free(player_item);
|
||||
player_item = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
player_mq_couter=0;
|
||||
}
|
||||
|
||||
void xiaoice_close_all_audio(void)
|
||||
|
||||
Reference in New Issue
Block a user