zhaowenyu
2025-12-06 fa01232ee9243b592d8f5e8184c38b5603501344
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.ard.work.component.netty.command.speaker;
 
import com.ard.work.domain.dto.speaker.TextSpeakDTO;
import com.ard.work.component.netty.command.BaseCmd;
import io.netty.buffer.ByteBuf;
 
/**
 * 文字喊话指令
 *
 * @author liusuyi
 * @date 2024年10月30日16:20
 **/
public class TextSpeakCmd extends BaseCmd {
 
    private final byte speechRate;
    private final byte voiceType;
    private final String textData;
 
    public TextSpeakCmd(TextSpeakDTO textSpeakDTO) {
        this.speechRate = textSpeakDTO.getSpeechRate();
        this.voiceType = textSpeakDTO.getVoiceType();
        this.textData = textSpeakDTO.getTextData();
        setDataHeader((short) 0x7479);
        setDataLength((short) (20 + this.textData.getBytes().length));
        setBoxSn(textSpeakDTO.getBoxSn().getBytes());
        setCmdCode((byte) 0xD3);
    }
 
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());            // 写入数据头
        out.writeShort(getDataLength());            // 写入数据长度
        out.writeBytes(getBoxSn());                 // 写入盒子SN
        out.writeByte(getCmdCode());                // 写入命令码
        out.writeByte(0x00);                  // 写入加密标志
        out.writeByte(0x04);                  // 写入动作编号
        out.writeByte(this.speechRate);             // 写入语速设置
        out.writeByte(this.voiceType);              // 写入声音
        out.writeBytes(this.textData.getBytes());   // 写入文本数据
    }
}