修改数据转化
This commit is contained in:
@@ -475,15 +475,61 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
|
||||
result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd)
|
||||
}
|
||||
// 固定模板输出语音
|
||||
if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) {
|
||||
if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 {
|
||||
sound := sounds[1]
|
||||
printer := model.Printer{}
|
||||
printer.Volume = 4
|
||||
printer.Sound = "sounda"
|
||||
//if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil {
|
||||
//先把结束标签消了
|
||||
result = strings.ReplaceAll(result, byteSignSoundE, "")
|
||||
//fd 固定
|
||||
//001a (声音数据长度高八位低八位)
|
||||
//0101 固定
|
||||
soundPrefix := ""
|
||||
if printer.Sound != "" {
|
||||
soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound
|
||||
} else {
|
||||
soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]"
|
||||
}
|
||||
hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix))
|
||||
hexPrefixStr := hex.EncodeToString(hexPrefix)
|
||||
|
||||
// 将语音包转换为十六进制
|
||||
voice := ""
|
||||
for _, v := range strings.Split(sound, "2c") {
|
||||
soundNum, _ := hex.DecodeString(v) // 十六进制转字符串
|
||||
intSound, _ := strconv.ParseInt(string(soundNum), 10, 64)
|
||||
int16Sound := strconv.FormatInt(intSound, 16)
|
||||
voice += int16Sound
|
||||
}
|
||||
voiceDataGBK, _ := jxutils.Utf8ToGbk([]byte(replaceContentOther(voice)))
|
||||
voiceData := hex.EncodeToString(voiceDataGBK)
|
||||
globals.SugarLogger.Debug("voice============", voiceData)
|
||||
|
||||
realSound := hexPrefixStr + voiceData
|
||||
allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2)
|
||||
if len(allLen) < 2 {
|
||||
allLen = "0" + allLen
|
||||
}
|
||||
globals.SugarLogger.Debug("realSound============", realSound)
|
||||
globals.SugarLogger.Debug("allLen============", allLen)
|
||||
|
||||
soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2))
|
||||
globals.SugarLogger.Debug("result1============", result)
|
||||
result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr)
|
||||
globals.SugarLogger.Debug("result2============", result)
|
||||
//}
|
||||
}
|
||||
}
|
||||
// 自动合成语音功能
|
||||
if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) {
|
||||
if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 {
|
||||
sound := sounds[1]
|
||||
if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil {
|
||||
//先把结束标签消了
|
||||
result = strings.ReplaceAll(result, byteSignSoundE, "")
|
||||
//fd 固定
|
||||
//001a (声音数据长度高八位低八位)
|
||||
//0101 固定
|
||||
soundPrefix := ""
|
||||
if printer.Sound != "" {
|
||||
soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound
|
||||
@@ -492,60 +538,16 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
|
||||
}
|
||||
hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix))
|
||||
hexPrefixStr := hex.EncodeToString(hexPrefix)
|
||||
|
||||
// 将语音包转换为十六进制
|
||||
voice := ""
|
||||
for _, v := range strings.Split(sound, "2c") {
|
||||
soundNum, _ := hex.DecodeString(v) // 十六进制转字符串
|
||||
intSound, _ := strconv.ParseInt(string(soundNum), 10, 64)
|
||||
int16Sound := strconv.FormatInt(intSound, 16)
|
||||
voice += int16Sound
|
||||
}
|
||||
globals.SugarLogger.Debug("voice============", voice)
|
||||
|
||||
realSound := hexPrefixStr + voice
|
||||
realSound := hexPrefixStr + sound
|
||||
allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2)
|
||||
if len(allLen) < 2 {
|
||||
allLen = "0" + allLen
|
||||
}
|
||||
globals.SugarLogger.Debug("realSound============", realSound)
|
||||
globals.SugarLogger.Debug("allLen============", allLen)
|
||||
|
||||
soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2))
|
||||
globals.SugarLogger.Debug("result1============", result)
|
||||
result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr)
|
||||
globals.SugarLogger.Debug("result2============", result)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 自动合成语音功能
|
||||
//if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) {
|
||||
// if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 {
|
||||
// sound := sounds[1]
|
||||
// if printer, _ := dao.GetPrinter(dao.GetDB(), printMsg.PrintNo); printer != nil {
|
||||
// //先把结束标签消了
|
||||
// result = strings.ReplaceAll(result, byteSignSoundE, "")
|
||||
// //fd 固定
|
||||
// //001a (声音数据长度高八位低八位)
|
||||
// //0101 固定
|
||||
// soundPrefix := ""
|
||||
// if printer.Sound != "" {
|
||||
// soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]" + printer.Sound
|
||||
// } else {
|
||||
// soundPrefix = "[v" + utils.Int2Str(printer.Volume*2) + "]"
|
||||
// }
|
||||
// hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix))
|
||||
// hexPrefixStr := hex.EncodeToString(hexPrefix)
|
||||
// realSound := hexPrefixStr + sound
|
||||
// allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2)
|
||||
// if len(allLen) < 2 {
|
||||
// allLen = "0" + allLen
|
||||
// }
|
||||
// soundLenH, soundLenX := int2h8l8(int64((len(realSound) + len("0101")) / 2))
|
||||
// result = strings.ReplaceAll(result, byteSignSound, hexSignSound+allLen+"fd"+soundLenH+soundLenX+"0100"+hexPrefixStr)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user