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

简介: 本文介绍 CB5654开发板之读取云端返回值

image.png

上一篇博文讲了如何进行串口的配置

这次讲一下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":"RecognitionCompleted","status":20000000,"message_id":"e7e27fcbbfbb4f8da2df6284bb91d16b","task_id":"18bc5a60da156f7e12b711ad67dea253","status_text":"Gateway:SUCCESS:Success."},"payload":{"result":"我要听周杰伦的青花瓷","confidence":0.45584583282470703}}
>>>>
[   886.899713][D][nlpmit  ]ASR Result:
<<<<我要听周杰伦的青花瓷>>>>

[   886.906879][D][nlptxt  ]Enter aui_nlp_proc_textcmd
[   886.911848][D][nlptxt  ]process_textcmd:0
[   886.915933][W][nlptxt  ]unknown cmd
[   886.979028][D][MIT_ASR ]call mit_asr_event_cb(>>>>event: 14(EventDialogResult)<<<<) [start]
[   886.987847][D][nlpmit  ]Enter aui_nlp_proc_mit 
<<<<
{"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
怎么播放,网络音乐

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

原理就是,确定云端返回动作,然后根据信息来处理动作,播放故事的话,就可以运用播放函数。

文章来源:芯片开放社区
原文链接:https://occ.t-head.cn/community/post/detail?spm=a2cl5.14300636.0.0.1b87180fOJm8Ux&id=3802481971679600640

相关文章
|
6月前
|
传感器 Linux API
如何实现 MCU软件中多个模块初始化函数的优雅调用
如何实现 MCU软件中多个模块初始化函数的优雅调用
|
算法 芯片 异构计算
通过FPGA实现基于RS232串口的指令发送并控制显示器中目标位置
通过FPGA实现基于RS232串口的指令发送并控制显示器中目标位置
|
4月前
|
缓存 运维 Serverless
函数计算产品使用问题之在SD上安装了'inpaint anything'这个插件,但是不显示,是什么原因
函数计算产品作为一种事件驱动的全托管计算服务,让用户能够专注于业务逻辑的编写,而无需关心底层服务器的管理与运维。你可以有效地利用函数计算产品来支撑各类应用场景,从简单的数据处理到复杂的业务逻辑,实现快速、高效、低成本的云上部署与运维。以下是一些关于使用函数计算产品的合集和要点,帮助你更好地理解和应用这一服务。
|
4月前
|
存储 缓存 运维
函数计算产品使用问题之SD上安装了inpaint anything插件,但是不显示,该如何解决
函数计算产品作为一种事件驱动的全托管计算服务,让用户能够专注于业务逻辑的编写,而无需关心底层服务器的管理与运维。你可以有效地利用函数计算产品来支撑各类应用场景,从简单的数据处理到复杂的业务逻辑,实现快速、高效、低成本的云上部署与运维。以下是一些关于使用函数计算产品的合集和要点,帮助你更好地理解和应用这一服务。
349 0
|
6月前
|
测试技术
【ZYNQ】ZYNQ7000 私有定时器及其驱动应用示例
【ZYNQ】ZYNQ7000 私有定时器及其驱动应用示例
142 0
|
6月前
|
安全 测试技术
【ZYNQ】ZYNQ7000 全局定时器及其驱动示例
【ZYNQ】ZYNQ7000 全局定时器及其驱动示例
158 0
|
6月前
|
传感器
imx6ull开发板i2c应用编程读取AP3216c传感器数据
imx6ull开发板i2c应用编程读取AP3216c传感器数据
90 0
|
Serverless API 开发工具
函数计算FC的sd保存日记在哪里查看?
函数计算FC的sd保存日记在哪里查看?
49 1
|
编解码 Shell 内存技术
【沁恒WCH CH32V307V-R1开发板两路ADC读取实验】
【沁恒WCH CH32V307V-R1开发板两路ADC读取实验】
371 0