This commit is contained in:
jiangyong 2026-10-09 20:59:22 +08:00
parent 30e7a7d5d0
commit d5c2b9ed5b
2 changed files with 51 additions and 0 deletions

View File

@ -9,6 +9,7 @@ var (
BrandZhiheng = "zhiheng" BrandZhiheng = "zhiheng"
BrandUsr = "usr" BrandUsr = "usr"
BrandVzenith = "vzenith" BrandVzenith = "vzenith"
BrandLjt = "ljt"
) )
type Message struct { type Message struct {
@ -37,6 +38,8 @@ func NewVoice(brand, model, deviceId string, client mqtt.Client, callback Callba
return NewZhihengVoice(deviceId, client, callback) return NewZhihengVoice(deviceId, client, callback)
} else if brand == BrandFushua { } else if brand == BrandFushua {
return NewFushuaVoice(deviceId, client, callback) return NewFushuaVoice(deviceId, client, callback)
} else if brand == BrandLjt {
return NewLJTVoice(deviceId, client, callback)
} }
return nil return nil
} }

48
device/ljt_voice.go Normal file
View File

@ -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
}