修改语音播报

This commit is contained in:
邹宗楠
2022-07-26 11:37:22 +08:00
parent 2b3349127d
commit fa903fe325
2 changed files with 58 additions and 6 deletions

View File

@@ -54,7 +54,7 @@ const (
signSound, signSoundEnd = "<sound>", "</sound>" // 声音结束标签
// GPRS通讯说明打印机识别二进制码
hexSignBROrEXE = "0a"
hexSignBROrEXE = "0a" // 换行
hexSignCenter = "1b6101" // 居中打印
hexSignLeft = "1b6100" // 恢复居左打印
hexSignRight = "1b6102" // 居右打印
@@ -368,8 +368,8 @@ func buildMsg(printMsg *model.PrintMsg) (data []byte, err error) {
)
//写入数据
orderNoHexH, orderNoHexL = int2h8l8(int64(orderNo))
// 将数据与模板组装
// 将数据与模板组装
printDataGBK, _ := jxutils.Utf8ToGbk([]byte(replaceContentOther(content)))
printData = hex.EncodeToString(printDataGBK)
printData = replaceContent(printData, printMsg)
@@ -474,7 +474,7 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr+hexLenqr+"00")
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]
@@ -492,7 +492,17 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
}
hexPrefix, _ := jxutils.Utf8ToGbk([]byte(soundPrefix))
hexPrefixStr := hex.EncodeToString(hexPrefix)
realSound := hexPrefixStr + sound
// 将语音包转换为十六进制
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
}
realSound := hexPrefixStr + voice
allLen := fmt.Sprintf("%x", (len("fd001a0101")+len(realSound))/2)
if len(allLen) < 2 {
allLen = "0" + allLen
@@ -502,6 +512,34 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
}
}
}
// 自动合成语音功能
//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
}