文章目录

  • 前言
  • 一、学习简介
  • 二、代码快速开发
  • 三、官网配置
  • 3.1 百度云CFC配置
  • 3.2 小度官网配置
  • 四、测试
  • 4.1连接技能
  • 4.2 意图测试
  • 4.3 断开技能


前言

主要是为了记录下学习小度自定义技能的过程

一、学习简介

参考官网解释 自定义技能简介

二、代码快速开发

快速开发java

我的代码架构

小度技能 python 小度技能的_小度技能 python

Bot.java这个类是需要去继承,然后重写的,但是官网没有给出,需要自己去探索
下面给出我测试的代码

public class Bot extends BaseBot {

    public Bot(String request) throws IOException {
        super(request);
    }


    protected Response onLaunch(LaunchRequest launchRequest) {
        System.out.println("onLaunch收到消息啦啦啦~~~~~~launchRequest" + JSON.toJSONString(launchRequest));
        // 新建文本卡片
        TextCard textCard = new TextCard("山盟海誓卡片~");
        // 设置链接地址
        textCard.setUrl("www.ooxx.com");
        // 设置链接内容
        textCard.setAnchorText("爱我就点我……^_^¥¥¥");
        // 添加引导话术
        textCard.addCueWord("我想找个女朋友");
        // 新建返回的语音内容
        OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "欢迎吃爱情面包。。。。。。");
        // 构造返回的Response
        Response response = new Response(outputSpeech, textCard);
        System.out.println("onLaunch 返回数据response:" + JSON.toJSONString(response));
        return response;
    }

    @Override
    protected Response onInent(IntentRequest intentRequest) {
        System.out.println("onInent 收到消息intentRequest:" + JSON.toJSONString(intentRequest));
        // 判断NLU解析的意图名称是否匹配 inquiry_tax
        if ("inquiry_tax".equals(intentRequest.getIntentName())) {
            // 判断NLU解析解析后是否存在这个槽位
            if (getSlot("ssys.date") == null) {
                // 询问月薪槽位
                System.out.println("日期是多少");
            } else if (getSlot("sys.city") == null) {
                // 询问城市槽位
                System.out.println("城市是哪个");
            } else {
                // 计算个税缴纳情况
                System.out.println("未知的槽位");
            }
        }
        TextCard textCard = new TextCard("意图卡片");
        OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "爱情意图666");
        Response response = new Response(outputSpeech, textCard);
        System.out.println("onInent 返回数据response:" + JSON.toJSONString(response));
        return response;
    }

    @Override
    protected Response onSessionEnded(SessionEndedRequest sessionEndedRequest) {
        System.out.println("onSessionEnded 收到消息:" + JSON.toJSONString(sessionEndedRequest));

        // 构造TextCard
        TextCard textCard = new TextCard("爱您么么哒");
        textCard.setAnchorText("setAnchorText");
        textCard.addCueWord("");
        // 构造OutputSpeech
        OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "爱您么么哒88");
        // 构造Response
        Response response = new Response(outputSpeech, textCard);

        System.out.println("onSessionEnded 返回数据response:" + JSON.toJSONString(response));
        return response;

    }
}

三、官网配置

3.1 百度云CFC配置

官网地址

推荐使用华北-北京

小度技能 python 小度技能的_语音识别_02

小度技能 python 小度技能的_语音识别_03


将自己的包打成zip包,参考代码快速开发官网地址

找到如下命令,在自己的工程中执行如下:

mvn package
cd target
zip java-bot.zip demo-1.0-jar-with-dependencies.jar

小度技能 python 小度技能的_语音识别_04


触发器一定要选择这个

小度技能 python 小度技能的_语音识别_05

3.2 小度官网配置

小度控制台配置

小度技能 python 小度技能的_System_06


小度技能 python 小度技能的_小度技能 python_07


小度技能 python 小度技能的_JSON_08

小度技能 python 小度技能的_语音识别_09


小度技能 python 小度技能的_JSON_10


小度技能 python 小度技能的_官网_11


小度技能 python 小度技能的_System_12


小度技能 python 小度技能的_语音识别_13


小度技能 python 小度技能的_官网_14

四、测试

4.1连接技能

小度技能 python 小度技能的_JSON_15

激活技能成功

小度技能 python 小度技能的_JSON_16


查看日志成功

小度技能 python 小度技能的_System_17

4.2 意图测试

在上面技能打开的前提下,测试意图

小度技能 python 小度技能的_官网_18

小度技能 python 小度技能的_小度技能 python_19


查看日志

小度技能 python 小度技能的_小度技能 python_20


意图测试ok

4.3 断开技能

输入退出,小度会说代码指定爱你么么哒语音

小度技能 python 小度技能的_JSON_21

小度技能 python 小度技能的_小度技能 python_22

测试ok