From d5c2b9ed5b07333a48e070186fd8201c0b284c9c Mon Sep 17 00:00:00 2001 From: jiangyong Date: Fri, 9 Oct 2026 20:59:22 +0800 Subject: [PATCH] ljt --- device/device.go | 3 +++ device/ljt_voice.go | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 device/ljt_voice.go diff --git a/device/device.go b/device/device.go index ee9eb99..d60b66b 100644 --- a/device/device.go +++ b/device/device.go @@ -9,6 +9,7 @@ var ( BrandZhiheng = "zhiheng" BrandUsr = "usr" BrandVzenith = "vzenith" + BrandLjt = "ljt" ) type Message struct { @@ -37,6 +38,8 @@ func NewVoice(brand, model, deviceId string, client mqtt.Client, callback Callba return NewZhihengVoice(deviceId, client, callback) } else if brand == BrandFushua { return NewFushuaVoice(deviceId, client, callback) + } else if brand == BrandLjt { + return NewLJTVoice(deviceId, client, callback) } return nil } diff --git a/device/ljt_voice.go b/device/ljt_voice.go new file mode 100644 index 0000000..c4807d6 --- /dev/null +++ b/device/ljt_voice.go @@ -0,0 +1,48 @@ +package device + +import ( + "fmt" + + "git.u8t.cn/open/goutil" + mqtt "github.com/eclipse/paho.mqtt.golang" + log "github.com/sirupsen/logrus" + "github.com/spf13/cast" +) + +type LJTVoice struct { + deviceId string + client mqtt.Client + callback Callback + brand string + model string +} + +func NewLJTVoice(deviceId string, client mqtt.Client, callback Callback) Voice { + return &LJTVoice{ + deviceId: deviceId, + client: client, + callback: callback, + brand: "ljt", + model: "zkb01", + } +} + +func (v *LJTVoice) KeepAlive() error { + return nil +} + +func (v *LJTVoice) Operate(string) error { + return nil +} + +func (v *LJTVoice) Play(content string) error { + volume := cast.ToInt(100) + params := make(map[string]interface{}) + params["action"] = "PlayTTS" + params["content"] = content + params["vol"] = int(goutil.If(volume > 100 || volume < 0, 50, volume) / 10) + topic := fmt.Sprintf("cmd/%s/%s/%s", v.brand, v.model, v.deviceId) + v.client.Publish(topic, 2, false, goutil.EncodeJSON(params)) + log.Infof("LJT topic[%s] message[%s]", topic, goutil.EncodeJSON(params)) + return nil +}