Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d24c8e186a | ||
|
|
53d480c1fd | ||
|
|
0422d754a1 |
@@ -5,6 +5,7 @@
|
|||||||
#include "ql_iic.h"
|
#include "ql_iic.h"
|
||||||
#include "ql_gpio.h"
|
#include "ql_gpio.h"
|
||||||
#include "app_inc.h"
|
#include "app_inc.h"
|
||||||
|
#include "audio_prompt.h"
|
||||||
#include "ql_fs.h"
|
#include "ql_fs.h"
|
||||||
|
|
||||||
#define DEFAULT_VOLUME 6
|
#define DEFAULT_VOLUME 6
|
||||||
@@ -14,7 +15,6 @@
|
|||||||
u8 g_cur_volume = 0;
|
u8 g_cur_volume = 0;
|
||||||
u8 g_pre_volume = 0;
|
u8 g_pre_volume = 0;
|
||||||
|
|
||||||
extern const char *mp3_file[];
|
|
||||||
extern int g_file_valid;
|
extern int g_file_valid;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,9 @@
|
|||||||
#include "sockets.h"
|
#include "sockets.h"
|
||||||
#include "layer3.h"
|
#include "layer3.h"
|
||||||
#include "ql_uart.h"
|
#include "ql_uart.h"
|
||||||
const char *mp3_file[] ={
|
#include "audio_prompt.h"
|
||||||
|
|
||||||
|
const char *mp3_file[AUDIO_PROMPT_FILE_COUNT] ={
|
||||||
"test.mp3",// 0
|
"test.mp3",// 0
|
||||||
"network_connect_zh.mp3",//1 系统启动中,正在等待网络连接
|
"network_connect_zh.mp3",//1 系统启动中,正在等待网络连接
|
||||||
"network_check.mp3",//2 网络不好 请检查网络
|
"network_check.mp3",//2 网络不好 请检查网络
|
||||||
@@ -31,12 +33,19 @@ const char *mp3_file[] ={
|
|||||||
"device_wake_up_zh.mp3",//13 设备已唤醒
|
"device_wake_up_zh.mp3",//13 设备已唤醒
|
||||||
"low_power_zh.mp3",//14 电量低
|
"low_power_zh.mp3",//14 电量低
|
||||||
"low_power_off_zh.mp3",//15 电量严重不足,马上关机
|
"low_power_off_zh.mp3",//15 电量严重不足,马上关机
|
||||||
"volume_up_zh.mp3",//16
|
"volume_up_zh.mp3",//16
|
||||||
"volume_down_zh.mp3",//17
|
"volume_down_zh.mp3",//17
|
||||||
"ai_active_zh.mp3",//18
|
"ai_active_zh.mp3",//18
|
||||||
|
/* 19~24:对话响应超时随机提示音,文件名与资源服务器保持一致 */
|
||||||
|
"tts_error01.mp3",//19
|
||||||
|
"tts_error02.mp3",//20
|
||||||
|
"tts_error03.mp3",//21
|
||||||
|
"tts_error04.mp3",//22
|
||||||
|
"tts_error05.mp3",//23
|
||||||
|
"tts_error06.mp3",//24
|
||||||
};
|
};
|
||||||
|
|
||||||
//http://175.24.73.253/assets/roles/zhuli/zh/tts_error.mp3
|
//http://banban.api.talkingq.com:8080/assets/roles/banban/tts_error.mp3
|
||||||
|
|
||||||
//#define PCM_FILE "http://47.113.99.138:7050/output_16k.pcm"
|
//#define PCM_FILE "http://47.113.99.138:7050/output_16k.pcm"
|
||||||
|
|
||||||
@@ -183,7 +192,8 @@ void app_file_check_download(void)
|
|||||||
char filename_buff[64]={0x00};
|
char filename_buff[64]={0x00};
|
||||||
int ret = 0, cnt = 0;
|
int ret = 0, cnt = 0;
|
||||||
|
|
||||||
for(index=1;index<19;index++){
|
/* 遍历完整资源表,新增提示音不存在时会在联网后自动补下载 */
|
||||||
|
for(index=1;index<AUDIO_PROMPT_FILE_COUNT;index++){
|
||||||
|
|
||||||
if(index==4||index==5||index==6||index==7||index==8){
|
if(index==4||index==5||index==6||index==7||index==8){
|
||||||
continue;
|
continue;
|
||||||
@@ -194,7 +204,7 @@ void app_file_check_download(void)
|
|||||||
if(ql_access(filename_buff, 0)!=0){
|
if(ql_access(filename_buff, 0)!=0){
|
||||||
printf("downing mp3 file %d,%s\r\n", index,filename_buff);
|
printf("downing mp3 file %d,%s\r\n", index,filename_buff);
|
||||||
down_loop:
|
down_loop:
|
||||||
sprintf(url_buff, "http://101.35.224.118:8080/assets/roles/banban/%s", mp3_file[index]);
|
sprintf(url_buff, "http://banban.api.talkingq.com:8080/assets/roles/banban/%s", mp3_file[index]);
|
||||||
|
|
||||||
ret = http_file_download(url_buff);
|
ret = http_file_download(url_buff);
|
||||||
if(ret!=0&&cnt++<3) goto down_loop;
|
if(ret!=0&&cnt++<3) goto down_loop;
|
||||||
@@ -208,7 +218,7 @@ void app_file_check_del(void)
|
|||||||
int index = 1;
|
int index = 1;
|
||||||
char filename_buff[64]={0x00};
|
char filename_buff[64]={0x00};
|
||||||
|
|
||||||
for(index=1;index<19;index++){
|
for(index=1;index<AUDIO_PROMPT_FILE_COUNT;index++){
|
||||||
|
|
||||||
if(index==4||index==5||index==6||index==7||index==8){
|
if(index==4||index==5||index==6||index==7||index==8){
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef _AUDIO_PROMPT_H_
|
||||||
|
#define _AUDIO_PROMPT_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 本地提示音索引约定。
|
||||||
|
* 现有索引保持不变,新增的 6 条对话响应超时音频从 19 开始追加,
|
||||||
|
* 避免影响项目中已经使用的其他提示音索引。
|
||||||
|
*/
|
||||||
|
#define AUDIO_PROMPT_TTS_ERROR_INDEX 9
|
||||||
|
#define AUDIO_PROMPT_TTS_ERROR_FIRST_INDEX 19
|
||||||
|
#define AUDIO_PROMPT_TTS_ERROR_LAST_INDEX 24
|
||||||
|
#define AUDIO_PROMPT_FILE_COUNT 25
|
||||||
|
|
||||||
|
extern const char *mp3_file[AUDIO_PROMPT_FILE_COUNT];
|
||||||
|
|
||||||
|
int app_play_tips_file(int index);
|
||||||
|
int app_play_random_tts_error(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -391,11 +391,12 @@ int parse_event_response(const char *json_str, response_t *resp)
|
|||||||
|
|
||||||
|
|
||||||
/* [FIX] 安全处理 topic 名称,避免越界访问 */
|
/* [FIX] 安全处理 topic 名称,避免越界访问 */
|
||||||
static void messageArrived(MessageData* data)
|
static void messageArrived(MessageData* data)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint32 queue_count = 0;
|
int payload_log_len;
|
||||||
app_work_item *work_item;
|
uint32 queue_count = 0;
|
||||||
|
app_work_item *work_item;
|
||||||
|
|
||||||
// 安全获取 topic 字符串(复制到本地缓冲区)
|
// 安全获取 topic 字符串(复制到本地缓冲区)
|
||||||
char topic_buf[128] = {0};
|
char topic_buf[128] = {0};
|
||||||
@@ -403,10 +404,16 @@ static void messageArrived(MessageData* data)
|
|||||||
if (topic_len >= sizeof(topic_buf)) {
|
if (topic_len >= sizeof(topic_buf)) {
|
||||||
topic_len = sizeof(topic_buf) - 1;
|
topic_len = sizeof(topic_buf) - 1;
|
||||||
}
|
}
|
||||||
memcpy(topic_buf, data->topicName->lenstring.data, topic_len);
|
memcpy(topic_buf, data->topicName->lenstring.data, topic_len);
|
||||||
topic_buf[topic_len] = '\0';
|
topic_buf[topic_len] = '\0';
|
||||||
|
|
||||||
// 比较 topic 类型
|
payload_log_len = data->message->payloadlen > 512 ? 512 : (int)data->message->payloadlen;
|
||||||
|
printf("[MQTT-RX] topic=%s len=%d payload=%.*s%s\r\n",
|
||||||
|
topic_buf, (int)data->message->payloadlen, payload_log_len,
|
||||||
|
(const char *)data->message->payload,
|
||||||
|
data->message->payloadlen > (unsigned int)payload_log_len ? "..." : "");
|
||||||
|
|
||||||
|
// 比较 topic 类型
|
||||||
int is_command = (strstr(topic_buf, "command") != NULL);
|
int is_command = (strstr(topic_buf, "command") != NULL);
|
||||||
int is_event_resp = (strstr(topic_buf, "event_resp") != NULL) || (strstr(topic_buf, imei_buf) != NULL);
|
int is_event_resp = (strstr(topic_buf, "event_resp") != NULL) || (strstr(topic_buf, imei_buf) != NULL);
|
||||||
|
|
||||||
@@ -618,15 +625,33 @@ sub_exit:
|
|||||||
//0:代表respone command
|
//0:代表respone command
|
||||||
//1:代表send event
|
//1:代表send event
|
||||||
/* [FIX] 将连接状态检查和发送放在同一锁保护区内,避免竞争 */
|
/* [FIX] 将连接状态检查和发送放在同一锁保护区内,避免竞争 */
|
||||||
int app_mqtt_publish(char *buf, int len, int type)
|
int app_mqtt_publish(char *buf, int len, int type)
|
||||||
{
|
{
|
||||||
static uint32_t mqtt_pub_cnt_err=0;
|
static uint32_t mqtt_pub_cnt_err=0;
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
MQTTMessage message;
|
int payload_log_len;
|
||||||
int cnt = 0;
|
MQTTMessage message;
|
||||||
static uint8_t publish_error = 0;
|
int cnt = 0;
|
||||||
|
static uint8_t publish_error = 0;
|
||||||
// 锁保护:检查连接状态并发送
|
const char *publish_topic = NULL;
|
||||||
|
|
||||||
|
if (type == 0) {
|
||||||
|
publish_topic = respone_topicName;
|
||||||
|
} else if (type == 1) {
|
||||||
|
publish_topic = event_topicName;
|
||||||
|
} else if (type == 2) {
|
||||||
|
publish_topic = event_register;
|
||||||
|
} else {
|
||||||
|
RLOGE("invalid MQTT publish type=%d", type);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
payload_log_len = len > 512 ? 512 : len;
|
||||||
|
printf("[MQTT-TX] topic=%s len=%d payload=%.*s%s\r\n",
|
||||||
|
publish_topic, len, payload_log_len, buf,
|
||||||
|
len > payload_log_len ? "..." : "");
|
||||||
|
|
||||||
|
// 锁保护:检查连接状态并发送
|
||||||
int lock_ret = ql_rtos_mutex_lock(g_mqtt_public_mutex, 5000);
|
int lock_ret = ql_rtos_mutex_lock(g_mqtt_public_mutex, 5000);
|
||||||
if (lock_ret != 0) {
|
if (lock_ret != 0) {
|
||||||
RLOGE("MQTT mutex lock timeout");
|
RLOGE("MQTT mutex lock timeout");
|
||||||
@@ -643,18 +668,13 @@ int app_mqtt_publish(char *buf, int len, int type)
|
|||||||
message.payload = buf;
|
message.payload = buf;
|
||||||
message.payloadlen = len;
|
message.payloadlen = len;
|
||||||
|
|
||||||
while (cnt++ < 3) {
|
while (cnt++ < 3) {
|
||||||
u32 start = ql_rtos_get_systicks();
|
u32 start = ql_rtos_get_systicks();
|
||||||
if (type == 0) {
|
rc = MQTTPublish(&client, publish_topic, &message);
|
||||||
rc = MQTTPublish(&client, respone_topicName, &message);
|
|
||||||
} else if (type == 1) {
|
RLOGD("Pulish time:%d len: %d\n", (ql_rtos_get_systicks()-start)*5, len);
|
||||||
rc = MQTTPublish(&client, event_topicName, &message);
|
printf("[MQTT-TX] topic=%s attempt=%d rc=%d\r\n", publish_topic, cnt, rc);
|
||||||
} else if (type == 2) {
|
if (rc != 0) {
|
||||||
rc = MQTTPublish(&client, event_register, &message);
|
|
||||||
}
|
|
||||||
|
|
||||||
RLOGD("Pulish time:%d len: %d\n", (ql_rtos_get_systicks()-start)*5, len);
|
|
||||||
if (rc != 0) {
|
|
||||||
mqtt_pub_cnt_err++;
|
mqtt_pub_cnt_err++;
|
||||||
mqtt_public_error = 1;
|
mqtt_public_error = 1;
|
||||||
RLOGE("ERROR Return code from MQTT publish is %d, cnt %d", rc, mqtt_pub_cnt_err);
|
RLOGE("ERROR Return code from MQTT publish is %d, cnt %d", rc, mqtt_pub_cnt_err);
|
||||||
@@ -1250,23 +1270,34 @@ void handle_nfc_trigger(const char *uuid)
|
|||||||
free(json_str);
|
free(json_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_nfc_bind(const char *uuid)
|
void handle_nfc_bind(const char *uuid)
|
||||||
{
|
{
|
||||||
cJSON *root = cJSON_CreateObject();
|
char iccid[QL_SIM_ICCID_LEN * 2 + 1] = {0};
|
||||||
cJSON *data = cJSON_CreateObject();
|
QL_SIM_ERROR_CODE sim_ret;
|
||||||
|
cJSON *root = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(root, "msg_id", "006");
|
cJSON *data = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(root, "status", "success");
|
|
||||||
|
cJSON_AddStringToObject(root, "msg_id", "006");
|
||||||
cJSON_AddStringToObject(data, "uuid", uuid);
|
cJSON_AddStringToObject(root, "status", "success");
|
||||||
cJSON_AddItemToObject(root, "data", data);
|
|
||||||
|
cJSON_AddStringToObject(data, "uuid", uuid);
|
||||||
char *json_str = cJSON_PrintUnformatted(root);
|
|
||||||
cJSON_Delete(root);
|
sim_ret = ql_sim_get_iccid(iccid, sizeof(iccid));
|
||||||
|
if (sim_ret == QL_SIM_SUCCESS && iccid[0] != '\0') {
|
||||||
app_mqtt_publish(json_str, strlen(json_str), 0);
|
printf("NFC bind ICCID:%s\r\n", iccid);
|
||||||
free(json_str);
|
cJSON_AddStringToObject(data, "iccid", iccid);
|
||||||
}
|
} else {
|
||||||
|
printf("NFC bind get ICCID failed, ret:%d\r\n", sim_ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_AddItemToObject(root, "data", data);
|
||||||
|
|
||||||
|
char *json_str = cJSON_PrintUnformatted(root);
|
||||||
|
cJSON_Delete(root);
|
||||||
|
|
||||||
|
app_mqtt_publish(json_str, strlen(json_str), 0);
|
||||||
|
free(json_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "ql_uart.h"
|
#include "ql_uart.h"
|
||||||
#include "hal_api.h"
|
#include "hal_api.h"
|
||||||
#include "fvad.h"
|
#include "fvad.h"
|
||||||
|
#include "audio_prompt.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -779,12 +780,16 @@ void sendRecordingAudioPacket(AudioPacket *packet) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern const char *mp3_file[];
|
|
||||||
|
|
||||||
int app_play_tips_file(int index)
|
int app_play_tips_file(int index)
|
||||||
{
|
{
|
||||||
int file_valid_check = 0;
|
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);
|
printf("xiaoice_play_index:%d\n", index);
|
||||||
|
|
||||||
//正在录音过程中不允许播放
|
//正在录音过程中不允许播放
|
||||||
@@ -820,6 +825,48 @@ int app_play_tips_file(int index)
|
|||||||
return 0;
|
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)
|
void app_player_thread(void *arvg)
|
||||||
{
|
{
|
||||||
ice_work_item *player_item=NULL;
|
ice_work_item *player_item=NULL;
|
||||||
@@ -1023,7 +1070,8 @@ static void check_connect_thread_entry(void *parameter)
|
|||||||
printf("tts_error_set_speech1\n");
|
printf("tts_error_set_speech1\n");
|
||||||
vad_set_speech_timeout_flag(1);
|
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");
|
//talkingq_ws_send_text("REQUEST_PROMPT_SOUND:tts_error");
|
||||||
//改为播放本地音频 听不清 请再说一遍
|
//改为播放本地音频 听不清 请再说一遍
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user