Nugu Kit for Node.js
SK텔레콤 AI 스피커 NUGU의 play를 만드는 과정에서 직접 정의한 파라미터와 Backend proxy API Reference에서 제공하는 규격에 맞게 HTTP Request/Response의 JSON 파싱과 응답을 손쉽게 하도록 도와줍니다.
설치
아래의 명령어를 통해 nugu-kit를 설치합니다.
npm install nugu-kit
사용 방법 예시
Request sample
{
"version": "2.0",
"action": {
"actionName": "FoodFighter",
"parameters": {
"food": { "type": "korean", "value": "김치" },
"price": { "type": "won", "value": "1000" }
}
},
"event": {
"token": "select_token",
"type": "AudioPlayer.PlaybackStarted",
"offset_in_milli_seconds": 2517
},
"context": {
"session": {
"accessToken": "abc123",
"id": "def456",
"isNew": true,
"isPlayBuilderRequest": false
},
"device": {
"type": "speaker.nugu.nu200",
"state": null
},
"supportedInterfaces": {
"AudioPlayer": {
"playerActivity": "PLAYING",
"token": "select_token",
"offsetInMilliseconds": 100000
}
}
}
}
Request 파싱
const Nugu = ;const express = ;const app = ;app; app
특정 Utterance parameter 얻기
console; // { 'food': { type: 'korean', value: '김치' }, 'price':{ type: 'won', value: '1000'} } const food = nugu; // 김치const price = nugu; // 1000const foodType = nugu; // koreanconst priceType = nugu; // won
Response
기본 응답
app
기본 응답 output
{
"version": "2.0",
"resultCode": "OK",
"output": {
"ment": "김치의 가격은 1000원 이에요."
},
"directives": []
}
예외 상황 응답
app
예외 상황 응답 output
{
"version": "2.0",
"resultCode": "priceExceed",
"output": {},
"directives": []
}
AudioPlayer Interface를 사용하는 경우 응답
app
AudioPlayer Interface를 사용하는 경우 응답 output
{
"version": "2.0",
"resultCode": "OK",
"output": {
"ment": "김치의 가격은 1000원 이에요"
},
"directives": [
{
"type": "AudioPlayer.Stop",
"audioItem": {
"stream": {
"url": "https://www.food.kr/food.mp3",
"offsetInMilliseconds": 10000,
"progressReport": {
"progressReportDelayInMilliseconds": 20000,
"progressReportIntervalInMilliseconds": 30000
},
"token": "search_token",
"expectedPreviousToken": "select_token"
},
"metadata": {}
}
}
]
}
Default directive
nugu;console;/* { "type":"AudioPlayer.Play", "audioItem":{ "stream":{ "url": "", "offsetInMilliseconds":0, "progressReport":{ "progressReportDelayInMilliseconds": 0, "progressReportIntervalInMilliseconds": 0 }, "token":"", "expectedPreviousToken":"" }, "metadata":{} } }*/
참고
이슈
라이센스
Copyright (c) 2020 REVOICE:
MIT 라이센스, 세부사항