feat: add local random timeout prompts
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "ql_uart.h"
|
||||
#include "hal_api.h"
|
||||
#include "fvad.h"
|
||||
#include "audio_prompt.h"
|
||||
|
||||
|
||||
|
||||
@@ -779,12 +780,16 @@ void sendRecordingAudioPacket(AudioPacket *packet) {
|
||||
}
|
||||
#endif
|
||||
|
||||
extern const char *mp3_file[];
|
||||
|
||||
int app_play_tips_file(int index)
|
||||
{
|
||||
int file_valid_check = 0;
|
||||
|
||||
|
||||
/* 防止提示音索引越界访问文件名数组 */
|
||||
if(index < 0 || index >= AUDIO_PROMPT_FILE_COUNT){
|
||||
printf("invalid prompt index:%d\n", index);
|
||||
return -3;
|
||||
}
|
||||
|
||||
printf("xiaoice_play_index:%d\n", index);
|
||||
|
||||
//正在录音过程中不允许播放
|
||||
@@ -820,6 +825,48 @@ int app_play_tips_file(int index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 随机播放一条对话响应超时提示音。
|
||||
* 只把 LittleFS 中实际存在的文件加入候选列表,新增音频尚未下载完成时,
|
||||
* 仍可回退播放原来的 tts_error.mp3,不会随机到不存在的文件。
|
||||
*/
|
||||
int app_play_random_tts_error(void)
|
||||
{
|
||||
static const int timeout_prompt_indices[] = {
|
||||
AUDIO_PROMPT_TTS_ERROR_INDEX,
|
||||
AUDIO_PROMPT_TTS_ERROR_FIRST_INDEX,
|
||||
AUDIO_PROMPT_TTS_ERROR_FIRST_INDEX + 1,
|
||||
AUDIO_PROMPT_TTS_ERROR_FIRST_INDEX + 2,
|
||||
AUDIO_PROMPT_TTS_ERROR_FIRST_INDEX + 3,
|
||||
AUDIO_PROMPT_TTS_ERROR_FIRST_INDEX + 4,
|
||||
AUDIO_PROMPT_TTS_ERROR_LAST_INDEX
|
||||
};
|
||||
int valid_indices[sizeof(timeout_prompt_indices) / sizeof(timeout_prompt_indices[0])];
|
||||
int valid_count = 0;
|
||||
int selected_index;
|
||||
int i;
|
||||
char filename_buff[64] = {0x00};
|
||||
|
||||
for(i = 0; i < (int)(sizeof(timeout_prompt_indices) / sizeof(timeout_prompt_indices[0])); i++){
|
||||
int prompt_index = timeout_prompt_indices[i];
|
||||
sprintf(filename_buff, "U:/%s", mp3_file[prompt_index]);
|
||||
if(ql_access(filename_buff, 0) == 0){ //检查filename_buff指向的文件是否存在
|
||||
valid_indices[valid_count++] = prompt_index;
|
||||
}
|
||||
}
|
||||
|
||||
if(valid_count == 0){
|
||||
printf("no local tts error prompt file\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
selected_index = valid_indices[hal_os_get_rand() % valid_count];
|
||||
printf("random tts_error prompt index:%d, file:%s\n",
|
||||
selected_index, mp3_file[selected_index]);
|
||||
|
||||
return app_play_tips_file(selected_index);
|
||||
}
|
||||
|
||||
void app_player_thread(void *arvg)
|
||||
{
|
||||
ice_work_item *player_item=NULL;
|
||||
@@ -1023,7 +1070,8 @@ static void check_connect_thread_entry(void *parameter)
|
||||
printf("tts_error_set_speech1\n");
|
||||
vad_set_speech_timeout_flag(1);
|
||||
|
||||
app_play_tips_file(9);
|
||||
/* 对话响应超时后,从本地已有的 7 条提示音中随机播放一条 */
|
||||
app_play_random_tts_error();
|
||||
//talkingq_ws_send_text("REQUEST_PROMPT_SOUND:tts_error");
|
||||
//改为播放本地音频 听不清 请再说一遍
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user