CB5654开发板之读取云端返回值

适用于平头哥CB5654智能语音开发板

文章目录

  • 一、读取云端的返回值
  • 二、原理
  • 三、操作


一、读取云端的返回值

CB5654开发板如何读取云端的返回值

我们最开始拿到的官网提供的例程,绑定了几个云端的功能

二、原理

首先是整体看一下云端返回参数:

[   981.520858][D][nlpmit  ]Enter aui_nlp_proc_mit 
<<<<
{"header":{"namespace":"VirtualAssistant","name":"RecognitionCompleted","status":20000000,"message_id":"dad4c26b55ab4bd790c44db1c2229d84","task_id":"18bc5a60da15b863a38471dc3adb80bc","status_text":"Gateway:SUCCESS:Success."},"payload":{"result":"声音调小一点","confidence":0.43344905972480774}}
>>>>
[   981.552902][D][nlpmit  ]ASR Result:
<<<<声音调小一点>>>>
[   981.559788][D][nlptxt  ]Enter aui_nlp_proc_textcmd
[   981.564669][D][nlptxt  ]process_textcmd:0
[   981.568755][W][nlptxt  ]unknown cmd
[   981.592052][D][MIT_ASR ]call mit_asr_event_cb(>>>>event: 14(EventDialogResult)<<<<) [start]
[   981.601274][D][nlpmit  ]Enter aui_nlp_proc_mit 
<<<<
{"header":{"namespace":"VirtualAssistant","name":"DialogResultGenerated","status":20000000,"message_id":"cc3b3fdc84ec485bbd95bfa95c39ba25","task_id":"18bc5a60da15b863a38471dc3adb80bc","status_text":"Gateway:SUCCESS:Success."},
"payload":{"display_text":"好的","spoken_text":"好的",
"action":"Action://audio/set_volumn","action_params":[{"name":"sound","value":"down"}],"semantics":[{"score":1,"slots":{"degree":[{"raw_value":"调小","norm_value":"down",
"score":0.0,"offset":2,"count":2}]},"domain":"general_command","source":"jsgf","intent":"set_volumn"}]}}
>>>>
[   981.655911][D][nlpmit  ]NLP Action:
<<<<Action://audio/set_volumn>>>>
[   981.662667][D][nlpmit  ]NLP Result:
<<<<好的>>>>
[   981.667751][D][MIT_TTS ]Enter aui_cloud_req_tts
[   981.685123][D][MIT_TTS ]TTSStart
[   981.738402][D][media   ]set vol:80 type:0
[   981.742422][I][sc5654  ]i2s o1 pdev=0x246d244
[   981.746909][D][media   ]set vol:80 type:1
[   981.806021][D][MIT_ASR ]consumig thread end
[   981.951292][D][media   ]media1 stop
[   981.959359][D][media   ]state:1 type:1
[   981.963339][D][media   ]set vol:80 type:1
[   981.967386][D][media   ]play1 vol:80 vol_ret:0 url:fifo://mittts
[   981.973452][I][player  ]player_new, 132 enter.
[   981.978019][I][player  ]player_new, 171 leave. player = 0x260376c
[   981.984272][I][player  ]player_play, 501 enter. player = 0x260376c
[   981.993930][I][player  ]player_play, 518 leave. player = 0x260376c
[   982.062094][D][MIT_TTS ]TTSEnd

可以看到重要的两个指令是:

{"header":{"namespace":"VirtualAssistant","name":"RecognitionCompleted","status":20000000,"message_id":"dad4c26b55ab4bd790c44db1c2229d84","task_id":"18bc5a60da15b863a38471dc3adb80bc","status_text":"Gateway:SUCCESS:Success."},"payload":{"result":"声音调小一点","confidence":0.43344905972480774}}
{"header":{"namespace":"VirtualAssistant","name":"DialogResultGenerated","status":20000000,"message_id":"cc3b3fdc84ec485bbd95bfa95c39ba25","task_id":"18bc5a60da15b863a38471dc3adb80bc","status_text":"Gateway:SUCCESS:Success."}, "payload":{"display_text":"好的","spoken_text":"好的","action":"Action://audio/set_volumn","action_params":[{"name":"sound","value":"down"}],"semantics":[{"score":1,"slots":{"degree":[{"raw_value":"调小","norm_value":"down","score":0.0,"offset":2,"count":2}]},"domain":"general_command","source":"jsgf","intent":"set_volumn"}]}}

一次交互会有asr和nlp两次事件,但两次事件的task id相同,如果asr处理是对该值赋值,说明要忽略后续的nlp处理。根据代码,我们可以看到,声音调整已经绑定了TTS后的执行动作 。

cJSON *action = cJSON_GetObjectItemByPath(js, "payload.action");
    if (cJSON_IsString(action)) {
            if (strcmp(action->valuestring, "Action://audio/set_volumn") == 0) {    //判断字符串
                app_aui_cloud_tts_wait_finish();           //等待
                ret = aui_nlp_action_set_volume(js);        //执行
                if (ret == 0) {
                    done = 1;
                }
}

三、操作

我们需要完成的就是判断、等待 和执行 那如何让开发版唱歌呢? 对开发版说,我想听青花瓷,云端返回数据如下

<<<<
{"header":{"namespace":"VirtualAssistant","name":"DialogResultGenerated","status":20000000,"message_id":"84038aa745ad4aa2a8c885ba340868c2","task_id":"18bc5a60da156f7e12b711ad67dea253","status_text":"Gateway:SUCCESS:Success."},
"payload":{"spoken_text":"我要开始唱周杰伦的青花瓷了。",
"action_params":[{"name":"listenFile","value":"http://iot-cdn.tuling123.com/202005141738/54b8c0fa8fb682ec06c33ef6c998dbdb/media/audio/20180524/dd55dcb5a8ab432a82db85ad2207eb3d.mp3"}]}}
>>>>
[   887.035706][D][nlpmit  ]NLP Result:
<<<<我要开始唱周杰伦的青花瓷了。>>>>

关键还是如何对相应的指令绑定TTS后的执行动作。 可以看到唱歌返回的参数是

"action_params":[{"name":"listenFile","value":"http://iot-cdn.tuling123.com/202005141738/54b8c0fa8fb682ec06c33ef6c998dbdb/media/audio/20180524/dd55dcb5a8ab432a82db85ad2207eb3d.mp3"}]}}

那我们就要对动作进行判断,为listenFile,并且要播放青花瓷的URL (http://iot-cdn.tuling123.com/202005141738/54b8c0fa8fb682ec06c33ef6c998dbdb/media/audio/20180524/dd55dcb5a8ab432a82db85ad2207eb3d.mp3)

怎么播放,网络音乐

aui_player_play(MEDIA_MUSIC, "http://cop-image-prod.oss-cnhangzhou.aliyuncs.com/resource/undefined1577166283488/AudioTest1.mp3/", 1);

你可能感兴趣的:(语音识别)