vc_cfg.dev_type = DEV_FX1_H;//产品
//vc_cfg.dev_type = DEV_ADS;//奥德赛
vc_cfg.dev_type = DEV_JSWM;//金山完美
+ //vc_cfg.dev_type = DEV_ALY;//阿里云
//strcpy(vc_cfg.server_ip,"amp.raisound.com");//服务器地址
strcpy(vc_cfg.server_ip,"115.190.94.208:22080");//服务器地址
vc_cfg.VC_mode =0;//对话模式
if(vc_cfg.dev_type == DEV_ADS)
{
cJSON_AddStringToObject(dialog_attributes, "provider", "ads_coze");
- }else
+ }else if(vc_cfg.dev_type == DEV_ALY)
+ {
+ cJSON_AddStringToObject(dialog_attributes, "provider", "bailian");
+ }
+ else
cJSON_AddStringToObject(dialog_attributes, "provider", "coze");
cJSON_AddStringToObject(bot_option, "workflow_id", "7508598451564150820");
}
cJSON_AddItemToObject(dialog_cfg, "bot_option", bot_option);
-
+ if(vc_cfg.dev_type == DEV_ALY)
+ {
+ // 创建 dialog_attributes对象下cfg对象下 greeting 对象
+ cJSON *bailian_option = cJSON_CreateObject();
+ cJSON_AddStringToObject(bailian_option, "app_id", "0988bd1a381145a8ad1026641c790685");
+ cJSON_AddItemToObject(dialog_cfg, "bailian_option", bailian_option);
+ }
cJSON_AddItemToObject(dialog_attributes, "cfg", dialog_cfg);
cJSON_AddItemToObject(payload, "dialog_attributes", dialog_attributes);
if(vc_cfg.dev_type == DEV_ADS)
{
cJSON_AddStringToObject(outbound_attributes, "provider", "ads_coze");
+ }else if(vc_cfg.dev_type == DEV_ALY)
+ {
+ cJSON_AddStringToObject(outbound_attributes, "provider", "CosyVoice");
}else
cJSON_AddStringToObject(outbound_attributes, "provider", "volcengine");
// 创建 outbound_attributes 下的 cfg 对象
if(vc_cfg.dev_type == DEV_ADS)
cJSON_AddStringToObject(outbound_cfg, "voice", "7511638457475710987");
+ else if(vc_cfg.dev_type == DEV_ALY)
+ {
+ cJSON_AddStringToObject(outbound_cfg, "voice", "longcheng");
+ }
else
cJSON_AddStringToObject(outbound_cfg, "voice", "zh_female_meituojieer_moon_bigtts");
// 创建 inbound_attributes 对象
cJSON *inbound_attributes = cJSON_CreateObject();
- cJSON_AddStringToObject(inbound_attributes, "provider", "volcengine");
+ if(vc_cfg.dev_type == DEV_ALY)
+ {
+ cJSON_AddStringToObject(inbound_attributes, "provider", "aliyun");
+ }else
+ cJSON_AddStringToObject(inbound_attributes, "provider", "volcengine");
if(vc_cfg.VC_mode == 0 && vc_cfg.is_VAD == 0)//连续对话模式,开在线vad
cJSON_AddBoolToObject(inbound_attributes, "disable_vad", 0);
else
VC_state = VC_State_End;//
//AI_AMP_MSG_put(0,0,VC_RECORD_START);//打开录音
- }else if(strstr(recv_buff,"\"event\":\"failed\""))//æ\89£å\90æ\8a¥é\94\99
+ }else if(strstr(recv_buff,"\"event\":\"failed\""))//æ\8e¥å\8f£æ\8a¥é\94\99äº\86
{
char *str_tmp = NULL;
- str_tmp = strstr(recv_buff,"\"message\":\"");
+ str_tmp = strstr(recv_buff,"\"concurrency_limit_exceeded\"");
if(str_tmp)
{
- str_tmp+=strlen("\"message\":\"");
- int count = str_count(str_tmp,'\"');
- AI_AMP_MSG_put(str_tmp,count,VC_CONNECT_ERROR);
+ AI_AMP_MSG_put(NULL,0,VC_CLOSE);
+ play_audio_file("C:/chaobingfatis.mp3");
+ }else
+ {
+ str_tmp = strstr(recv_buff,"\"message\":\"");
+ if(str_tmp)
+ {
+ // str_tmp+=strlen("\"message\":\"");
+ // int count = strlen(str_tmp);
+ AI_AMP_MSG_put("服务异常了,请重试",strlen("服务异常了,请重试"),VC_CONNECT_ERROR);
+ }
}
+
}
}
conf.rule1_min_tailing_silence = 480;
conf.rule2_min_tailing_silence = vc_cfg.vad_silence ;
conf.rule3_min_tailing_silence = vc_cfg.vad_silence;
- conf.vad_log_level = 2;
- int init_vad_ret = init_vad(&conf);
+ conf.vad_log_level = 0;
+ int init_vad_ret = 0;
+ strcpy(conf.auth_info.dmp_token, get_token());
+ init_vad_ret = init_vad(&conf);
+
+
bk_printf("VAD init_vad:ret = %d",init_vad_ret);
bk_printf("VAD init_vad:ret = %d",init_vad_ret);
bk_printf("VAD init_vad:ret = %d",init_vad_ret);
//每小时更新登录一次的更新定时器
static void sys_10S_timeout(void *param)
+{
+ AI_AMP_MSG_put(NULL,0,AI_TIMER_EVENT);
+}
+static void sys_10S_timeout_even(void)
{
// if (sizeof(dev_pass) == 0)
// aut_active();//没有密钥走激活
aic_srv_tele_sim_get_iccid_sync(current_card_id,vc_cfg.ICCID);
bk_printf("vc_cfg.ICCID:%s",vc_cfg.ICCID);
dev_authentication_init();
+ count =50;
+ while(count --)
+ {
+ if(strlen(get_token()) > 5)
+ {
+ break;
+ }
+ bk_printf("AI_AMP_2_5_init 等待鉴权..... \n");
+ aos_sleep(200);
+ }
if(sys_10S_timer == NULL)
{
sys_10S_timer = aos_create_timer("AI_VC_1S_timer",
case PLAY_FILE_STREAM_DATA:
play_file_stream_data_event(AI_AMP_msg.data);
break;
+ case AI_TIMER_EVENT:
+ sys_10S_timeout_even();
+ break;
case AI_PRINTF:
if(AI_AMP_msg.data)
"AI_AMP_2_5",
AI_AMP_2_5_task,
&AI_AMP_task_id,
- 4096u,
+ 4096*2,
0,
NULL,
ai_VC_task_priority,
bk_ring_buf_t *OPUS_decoder_rb_data = NULL;
static struct opus_enc_init_param *opus_encoder_h = NULL;
static struct opus_dec_init_param *opus_decoder_h = NULL;
+static char ogg_hend[27+256] ={0};
+static int ogg_hend_len = 0;
int opus_init(void)
{
#if SUPPORT_OPUS
{
bk_rb_clear(OPUS_encoder_rb_data);
}
+ ogg_hend_len = 0;
}
int opus_encode_data(char *PCM_data,int data_len,int one_pack_len,char *opus_data,int opus_data_max_len)
{
int frame_length;
struct opus_dec_param dec_inparam;
int ret = 0;
- static char ogg_hend[27+256] ={0};
- static int ogg_hend_len = 0;
+ int input_tmp_len = 0,ooutput_tmp_len = 0;
int seg_num =0;
//fread(page_buffer, 1, 27 + seg_num, fin);
if(!in_ogg_data)
return -1;
}
data_count = 0;
- u64 timer_ms = aos_get_tickcount();
+ u32 timer_ms = aos_get_tickcount();
while(1)
{
ogg_hend_len+=bk_rb_read(OPUS_decoder_rb_data,ogg_hend+27,seg_num);//读页的段数据
}
seg_size = ogg_calc_total_segment_data_size(ogg_hend, ogg_hend_len);//算这一页有多少数据
- //bk_printf("整页数据大小:%d",seg_size);
+ if(seg_size <=0)//数据出错了
+ {
+ int len_tmp = 0;
+ while(1)
+ {
+ len_tmp = bk_rb_read(OPUS_decoder_rb_data,ogg_hend,1);
+ if(ogg_hend[0] == 'O')
+ {
+ len_tmp = bk_rb_read(OPUS_decoder_rb_data,ogg_hend+1,1);
+ if(ogg_hend[1] == 'g')
+ {
+ len_tmp = bk_rb_read(OPUS_decoder_rb_data,ogg_hend+2,1);
+ if(ogg_hend[2] == 'g')//是OggS开头
+ {
+ bk_rb_read(OPUS_decoder_rb_data,ogg_hend+3,27-3);
+ ogg_hend_len=27;//读页头
+ break;
+ }
+ }
+ }
+ if(len_tmp <= 0)
+ break;
+ }
+ break;
+ }
+ bk_printf("整页数据大小:%d",seg_size);
/************3阶段读完整包****************** */
if(bk_rb_data_len(OPUS_decoder_rb_data)< seg_size)//判断可读数据够不够
{
}
else if (3 == page_type) {
ogg_demux_context demux_context = { 0, 0 };
+ input_tmp_len = 0;ooutput_tmp_len = 0;
while (1) {
p_audio = ogg_get_next_audio_frame(ogg_buf, &demux_context, &frame_length);
if (p_audio == NULL || frame_length == 0)
if(pcm_buf)
{
+
dec_inparam.input = p_audio;
dec_inparam.inputfrm_count = 1;
dec_inparam.input_len_array[0] = frame_length;
dec_inparam.outbuffer_size = 4096;
ret = aic_opus_decode(&dec_inparam);
- // bk_printf("opus解码 result:%d,outsize:%d", ret,dec_inparam.outputfrms_size);
+ //bk_printf("opus解码 输入大小:%d,输出大小:%d", frame_length,dec_inparam.outputfrms_size);
if (ret == OPUS_RESULT_ERROR) {
- //bk_printf("opus解码 error:%d", ret);
+ bk_printf("opus解码 error:%d", ret);
//bk_printf("ogg data:");
bk_print_hex(ogg_buf,27+seg_num+seg_size);
aic_free(pcm_buf);
break;
}
+ input_tmp_len+=frame_length;
+ ooutput_tmp_len += dec_inparam.outputfrms_size;
AI_VC_put_play_data(pcm_buf,dec_inparam.outputfrms_size);//发送数据到音频队列
//aos_sleep(1);
aic_free(pcm_buf);
}
}
+ bk_printf("ogg-opus解码 输入数据大小:%d,输出数据大小:%d,耗时:%d ms",input_tmp_len,ooutput_tmp_len,aos_get_tickcount()-timer_ms );
}else if(2 == page_type)//标签
{
bk_printf("opus标签 :%s", ogg_buf+27+seg_num);
//aos_sleep(1);
}
- bk_printf("ogg-opus解码 数据大小:%d,耗时:%d ms",in_ogg_data_len,aos_get_tickcount()-timer_ms );
+
#endif
return 0;
}
\ No newline at end of file