本文主要是介绍基于小爱平台的语音技能开发,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
基于小爱平台的语音技能开发
小爱开放平台基于小米的硬件生态和海量数据,提供全球领先的语音识别、NLP等多项人工智能技术,为开发者提供一站式的人工智能服务,用户可以在该平台上开发自己的语音技能。
比如交互式问询:
from xiaoai import *# helper function to response to XiaoAI
def outputJson(toSpeakText, is_session_end, openMic=True): xiaoAIResponse=XiaoAIResponse(to_speak=XiaoAIToSpeak(type_=0, text=toSpeakText), open_mic=openMic) response = xiaoai_response(XiaoAIOpenResponse(version="1.0", is_session_end=is_session_end, response=xiaoAIResponse)) return response def main(event): req = xiaoai_request(event)# if it's start request, we should welcome userif req.request.type == 0:return outputJson("欢迎使用小儿助手,您可以对我说XX怎么办", False) # if it's intent request, we can write normal logic here: mapping intents to response elif req.request.type==1:if ((not hasattr(req.request, "slot_info")) or (not hasattr(req.request.slot_info, "intent_name"))): return outputJson("抱歉,我没有听懂", False)else:if req.request.slot_info.intent_name=="risktest":slotsList = req.request.slot_info.slotsjointestlist = [item for item in slotsList if item['name'] == 'jointest']agelist = [item for item in slotsList if item['name'] == 'age']genderlist = [item for item in slotsList if item['name'] == 'gender']heightlist = [item for item in slotsList if item['name'] == 'height']weightlist = [item for item in slotsList if item['name'] == 'weight']isnoiselist = [item for item in slotsList if item['name'] == 'isnoise']if(not 'value' in slotsList[0].keys() ):return outputJson("请您给出合理的回复,请说打开小儿助手后再试",True)else:jointest=jointestlist[0].get('value','')age=agelist[0].get('value','')gender=genderlist[0].get('value','')height = heightlist[0].get('value','')weight = weightlist[0].get('value','')isnoise = isnoiselist[0].get('value','')bmi=0if (int(weight) / ((float(height)/100) * (float(height)/100)) > 35):bmi=1older = 0if(int(age)>50):older=1score = int(isnoise)fullscore = score+int(older)+int(gender)+int(bmi)if(score>=2 or fullscore>=3):return outputJson("测试结果:您的风险高,建议XXX。",False)else:return outputJson("测试结果:您的风险低。建议XXX",False)else:return outputJson("抱歉,请说打开小儿助手后再试",False)
执行结果:
该应用是语音交互,暂未留截图。
这篇关于基于小爱平台的语音技能开发的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!