【技能开发分享】星座达人


(xxx9991) #1

#星座达人

现在星座运势是热门话题,于是我开发了一个询问星座运势的小技能。和大家简单介绍一下

##技能玩法:

第一步(唤醒技能):

  • 说:若琪,打开星座达人
  • 进入技能的预期:设备会说:欢迎进入星座达人,你可以说白羊座今天运势怎么样,金牛座明天运势怎么样
  • 技能进入错误:设备没有说上述语句

第二步(使用技能):

  • 说:若琪,xx星座xx运势怎么样,例如:若琪,白羊座明天运势怎么样 可以查询今天、本周、下周的运势
  • 进入技能预期:查询今明天运势设备会说:白羊座,幸运色是xx,健康值xx,爱情指数xx,财运指数xxx ;查询本周下周运势设备会说:处女座本周,健康值xx,爱情指数xx,财运指数xx,工作指数xx
  • 技能进入错误哦:设备没有说上述语句,回复了其他模式语句

第三步(技能停止):

  • 说:若琪,停止
  • 预期:正在念的星座运势不再发声;

第四步(退出技能):

  • 说:若琪,我不想听了
  • 预期:技能退出了

##流程图

##语音交互设计:

{
	"intents": [
		{
			"intent": "queryconst",
			"slots": [
				{
					"name": "Constellation",
					"type": "ConsList"
				},
				{
					"name": "QueryTime",
					"type": "TimeList"
				}
			],
			"user_says": [
				"$Constellation$QueryTime的运气怎么样",
				"我想了解$Constellation$QueryTime的运气",
				"$Constellation$QueryTime运势怎么样",
				"$Constellation$QueryTime的运势怎么样",
				"我想了解$Constellation$QueryTime的运势",
				"我想看看$Constellation$QueryTime的运势",
				"$Constellation$QueryTime运气怎么样",
				"我想看看$Constellation$QueryTime的运气"
			]
		},
		{
			"intent": "EXIT_QUERY",
			"slots": [],
			"user_says": [
				"取消",
				"我不想听",
				"拜拜",
				"我听够了",
				"我不想听了",
				"我不听了"
			]
		},
		{
			"intent": "weekqueryconst",
			"slots": [
				{
					"name": "Constellation",
					"type": "ConsList"
				},
				{
					"name": "WeekQueryTime",
					"type": "WeekTimeList"
				}
			],
			"user_says": [
				"我想看看$Constellation$WeekQueryTime的运气",
				"$Constellation$WeekQueryTime的运势怎么样",
				"$Constellation$WeekQueryTime运气怎么样",
				"$Constellation$WeekQueryTime运势怎么样",
				"我想了解$Constellation$WeekQueryTime的运势",
				"$Constellation$WeekQueryTime的运气怎么样",
				"我想了解$Constellation$WeekQueryTime的运气",
				"我想看看$Constellation$WeekQueryTime的运势"
			]
		},
		{
			"intent": "PAUSE_QUERY",
			"slots": [],
			"user_says": [
				"暂停",
				"停下"
			]
		}
	]
}

js-engine相关开发:

需要从语音交互中提取星座和时间,然后使用聚合数据的API(
http://web.juhe.cn:8080/constellation/getAll
),发送get获取数据,并把结果用json解析后,拼接成一句话执行tts

聚合数据查询星座的参照https://www.juhe.cn/docs/api/id/58

var timeVar = "today";
var weekVar = "week";
var d = Rokid.param.request.content.slots.QueryTime; 
var w = Rokid.param.request.content.slots.WeekQueryTime; 
switch (d) 
{ 
  case "今天":timeVar="today"; 
  break; 
  case "明天":timeVar="tomorrow"; 
  break; 
 
}
switch (w) 
{ 
  case "本周":weekVar="week"; 
  break; 
  case "下周":weekVar="nextweek"; 
  break; 
}
var options = { method: 'GET',
  url: 'http://web.juhe.cn:8080/constellation/getAll',
  qs:
   { key: '580ae75367ddb4bda3e98f60c7bc2e59',
     consName: Rokid.param.request.content.slots.Constellation,
     type: timeVar }
    
};

console.log(JSON.stringify(options));



exports.handler = function(event, context, callback) {
    var potato = Rokid.handler(event, context,callback);
    potato.registerHandlers(handlers);
    potato.execute();
};

var handlers = {
    'queryconst': function () {
        Rokid.request(options, (error, response, body) => {
          if (error) throw new Error(error);
          console.log(response.statusCode);
          if (response.statusCode == 200) {
               returnInfo = '发送成功';
               console.log(body);
            }
          var resValue = JSON.parse(body)["name"]+",幸运色是"+JSON.parse(body)["color"]+",健康值"+JSON.parse(body)["health"]+",爱情指数"+ JSON.parse(body)["love"]+ ",财运指数" + JSON.parse(body)["money"] + ",工作指数" + JSON.parse(body)["work"] + ",速配星座" +JSON.parse(body)["QFriend"] + ",总之" + JSON.parse(body)["summary"];
          console.log('returnInfo:'+body);
          this.emit(':tts', {tts:resValue});
          this.callback(null);
        });

    },
    
    'weekqueryconst': function () {
        Rokid.request(options, (error, response, body) => {
          if (error) throw new Error(error);
          console.log(response.statusCode);
          if (response.statusCode == 200) {
               returnInfo = '发送成功';
               console.log(body);
            }
          var resValue = JSON.parse(body)["name"]+ w +",健康值"+JSON.parse(body)["health"]+",爱情指数"+ JSON.parse(body)["love"]+ ",财运指数" + JSON.parse(body)["money"] + ",工作指数" + JSON.parse(body)["work"]  ;
          console.log('returnInfo:'+body);
          this.emit(':tts', {tts:resValue});
          this.callback(null);
        });

    },
    
    "PAUSE_QUERY":function(){
        try{
            this.emit(":tts",{ tts: "",action:"PAUSE" });
            this.callback(null);
        }catch(e){
            this.callback(e);
        }
    },
    "EXIT_QUERY":function(){
        try{
            this.emit(":tts",{ tts: "再见", action:"STOP" });
            this.callback(null);
        }catch(e){
            this.callback(e);
        }
    },

    'ROKID.INTENT.WELCOME':function() {
        this.emit(':tts',{tts:'欢迎进入星座达人,你可以说白羊座今天运势怎么样,金牛座明天运势怎么样'});
        this.callback(null);
    }
};

##遇到的问题:

  • 设备声音识别总不准,入口词很容易识别错,入口词的选择要简短,尽量开口音;

Rokid开发者大赛第一季
技能版块的常见问题
技能开发本周常见问题 18-03-19
开发者社区Pebble(月石)开发测试固件发布
(chao.xuc) #2

很棒