Commit 614196cc authored by 赵文静's avatar 赵文静

补充domain

parent 14380081
Pipeline #5211 passed with stage
in 0 seconds
......@@ -536,11 +536,12 @@ func (TencentNlu) TencentNluParseStream(stream proto.TencentNlu_TencentNluParseS
}
sessionId := tMetaData.SessionId
vender := tMetaData.Vender
var appKey, auth, dsn, qua, requestId, mid, mac string
var appKey, auth, dsn, qua, requestId, mid, mac, ip string
qua = "QV=3&PL=ADR&PR=chvoice&VE=7.6&VN=3350&PP=com.geli.mtt&DE=SPEAKER&SP=3"
requestId = tMetaData.RequestId
mid = tMetaData.Mid
mac = tMetaData.MacWifi
ip = tMetaData.Ip
// 查询key和secret
//dingDangBot, ok := global.DingDangBot.Get(tMetaData.Mid, tMetaData.Vender)
//if ok {
......@@ -609,7 +610,7 @@ func (TencentNlu) TencentNluParseStream(stream proto.TencentNlu_TencentNluParseS
speechNluWs := speechNlu.SpeechNlpWs{}
var nlpWsConn *websocket.Conn
nlpWsConn, err = speechNluWs.SpeechWs(mac)
nlpWsConn, err = speechNluWs.SpeechWs(mac, ip)
if err != nil {
global.Logger.Errorf("speechWs.SpeechWs error. %v", err)
return err
......
......@@ -68,26 +68,29 @@ const (
CHAT = "闲聊全库"
CALENDAR = "日历"
NEWS = "新闻"
ANCIENTPOEM = "诗词"
SPORTS = "sports"
ASTRO = "星座"
STOCK = "stock"
TRANSLATE = "翻译大全"
ALARM = "提醒"
SCIENCE = "计算器"
CHENGYU = "成语"
BAIKE = "百科"
FM = "网络电台"
CHILDMUSIC = "儿歌"
GLOBALCTRL = "中控"
PlayCTRL = "播放控制"
MUSIC = "音乐"
HELP = "产品形象"
STORY = "故事"
FINANCE = "汇率"
CONVERT = "单位换算"
HOLIDAY = "节假日查询"
NEWS = "新闻"
ANCIENTPOEM = "诗词"
SPORTS = "sports"
ASTRO = "星座"
STOCK = "stock"
TRANSLATE = "翻译大全"
ALARM = "提醒"
SCIENCE = "计算器"
CHENGYU = "成语"
BAIKE = "百科"
FM = "网络电台"
CHILDMUSIC = "儿歌"
GLOBALCTRL = "中控"
PlayCTRL = "播放控制"
MUSIC = "音乐"
HELP = "产品形象"
STORY = "故事"
FINANCE = "汇率"
CONVERT = "单位换算"
HOLIDAY = "节假日查询"
SLEEPMUSIC = "声音博物馆"
RELATION = "亲戚关系计算"
WASTESORTING = "垃圾分类"
SOUND = "sound"
ALMANAC = "almanac"
......
......@@ -376,8 +376,6 @@ func alarmDomain(params *model.SpeechDomainParams) []byte {
UpdateSession(params.Mac, params.SpeechWsResp.SessionId)
return Marshal(params, &result)
}
fmt.Println("1111111111111111111111111")
fmt.Println(params.SpeechWsResp.SessionId)
if !params.CheckDm() || !params.CheckCommandParam() {
return replyWithChat(error_reply, "doudi")
......@@ -791,6 +789,61 @@ func musicDomain(params *model.SpeechDomainParams) []byte {
return Marshal(params, &result)
}
func sleepMusicDomain(params *model.SpeechDomainParams) []byte {
res, err := baseParse(params)
if err != nil {
global.Logger.WithFields(logger.Fields{
"requestId": params.RequestId,
"mac": params.Mac,
"mid": params.Mid,
"vender": params.MidType,
}).Error("fmDomain baseParse error.")
return replyWithChat(error_reply, "doudi")
}
var result model.ResponseBody
result.Header.Semantic.Code = 0
result.Header.Semantic.Domain = "music"
result.Header.Semantic.Intent = "SleepingMusic.control_searchTheme"
result.Header.Semantic.Msg = speech_nlu_parse
result.Header.Semantic.SessionComplete = params.SpeechWsResp.Dm.ShouldEndSession
result.Header.Semantic.SkillId = "SleepingMusic.control_searchTheme"
result.ListItems = make([]map[string]interface{}, 0)
sliceData, isSlice := params.SpeechWsResp.Dm.Widget.Content.([]interface{})
if !isSlice {
global.Logger.WithFields(logger.Fields{
"requestId": params.RequestId,
"mac": params.Mac,
"mid": params.Mid,
"vender": params.MidType,
}).Error("params.SpeechWsResp.Dm.Widget.Content不是数组类型")
if res.ResponseText != "" {
return replyWithChat(res.ResponseText, "doudi")
}
return replyWithChat(error_reply, "doudi")
}
for _, item := range sliceData {
itemBytes, _ := json.Marshal(item)
var con model.Content
if err := json.Unmarshal(itemBytes, &con); err != nil {
global.Logger.WithFields(logger.Fields{
"requestId": params.RequestId,
"mac": params.Mac,
"mid": params.Mid,
"vender": params.MidType,
}).Errorf("json.Unmarshal元素解析失败: %v", err)
return replyWithChat(error_reply, "doudi")
}
res.ListItems = append(res.ListItems, map[string]interface{}{
"url": con.LinkUrl,
"title": con.Title,
})
}
return Marshal(params, &result)
}
func financeDomain(params *model.SpeechDomainParams) []byte {
if !params.CheckDm() {
return replyWithChat(error_reply, "doudi")
......@@ -845,6 +898,24 @@ func holidayDomain(params *model.SpeechDomainParams) []byte {
return Marshal(params, &result)
}
func speechOtherDomain(params *model.SpeechDomainParams) []byte {
if !params.CheckDm() {
return replyWithChat(error_reply, "doudi")
}
var result model.ResponseBody
result.Header.Semantic.Code = 0
result.Header.Semantic.Domain = "chat"
result.Header.Semantic.Intent = "chat"
result.Header.Semantic.Msg = speech_nlu_parse
result.Header.Semantic.SessionComplete = params.SpeechWsResp.Dm.ShouldEndSession //params.SpeechWsResp.Dm.ShouldEndSession
result.Header.Semantic.SkillId = result.Header.Semantic.Domain + "." + result.Header.Semantic.Intent
result.ResponseText = params.SpeechWsResp.Dm.Nlg
result.AsrRecongize = params.SpeechWsResp.Dm.Input
return Marshal(params, &result)
}
func helpDomain(params *model.SpeechDomainParams) []byte {
resultTextStr := "我可以控制空调开机、播放音乐、查询时间天气、调节温度,设置模式,例如您可以对我说,空调开机。"
return replyWithChat(resultTextStr, "chat.chat")
......
......@@ -43,11 +43,14 @@ func register() {
DomainRegister(GLOBALCTRL, globalCtrlDomain)
DomainRegister(PlayCTRL, playCtrlDomain)
DomainRegister(MUSIC, musicDomain)
DomainRegister(SLEEPMUSIC, sleepMusicDomain)
DomainRegister(HELP, helpDomain)
DomainRegister(STORY, fmDomain)
DomainRegister(FINANCE, financeDomain)
DomainRegister(CONVERT, convertDomain)
DomainRegister(HOLIDAY, holidayDomain)
DomainRegister(RELATION, speechOtherDomain)
DomainRegister(WASTESORTING, speechOtherDomain)
//
//DomainRegisterV2(CHAT, chatDomainV2)
......
......@@ -79,7 +79,7 @@ func SpeechNlu(reqStruct *model.SemanticReq) (string, *errCode.Error) {
speechNluWs := SpeechNlpWs{}
var nlpWsConn *websocket.Conn
nlpWsConn, err = speechNluWs.SpeechWs(reqStruct.MacVoice)
nlpWsConn, err = speechNluWs.SpeechWs(reqStruct.MacVoice, reqStruct.Ip)
if err != nil {
global.Logger.WithFields(logger.Fields{
"requestId": reqStruct.RequestId,
......
......@@ -20,7 +20,7 @@ type SpeechNlpWs struct {
mutex sync.Mutex
}
func (s *SpeechNlpWs) SpeechWs(mac string) (*websocket.Conn, error) {
func (s *SpeechNlpWs) SpeechWs(mac, ip string) (*websocket.Conn, error) {
SpeechWs_Url := global.SpeechSetting.Url
SpeechWs_ProductId := global.SpeechSetting.ProductId
SpeechWs_ApiKey := global.SpeechSetting.ApiKey
......@@ -33,6 +33,8 @@ func (s *SpeechNlpWs) SpeechWs(mac string) (*websocket.Conn, error) {
deviceId := util.ComputerMd5(mac)
header := http.Header{}
header.Set("X-Forwarded-For", ip)
SpeechUrl := SpeechWs_Url + "?serviceType=websocket&productId=" + SpeechWs_ProductId +
"&apikey=" + SpeechWs_ApiKey + "&deviceId=" + deviceId
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment