This commit is contained in:
邹宗楠
2022-07-28 11:59:40 +08:00
parent 2c765f7547
commit 5a75d81980
2 changed files with 24 additions and 19 deletions

View File

@@ -478,28 +478,33 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) {
result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr+hexLenqr+"00") result = strings.ReplaceAll(result, byteSignQrRight, hexSignQrRight+hexSignQr+hexLenqr+"00")
result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd) result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd)
} }
// 固定模板输出语音 // 固定模板输出语音 3c736f756e643e<sound> 3634 </sound>3c2f736f756e643e
if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) {
if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 { soundStr := ""
sound := sounds[1] for _, v1 := range strings.Split(result, byteSignSoundE) {
//先把结束标签消了 v1 += byteSignSoundE
result = strings.ReplaceAll(result, byteSignSoundE, "") // 3c736f756e643e 3230 3c736f756e643e if sounds := regexpSound.FindStringSubmatch(v1); len(sounds) > 0 {
// 将语音包转换为十六进制 sound := sounds[1]
voice := "" //先把结束标签消了
for _, v := range strings.Split(sound, "2c") { resultV1 := strings.ReplaceAll(v1, byteSignSoundE, "")
voice += hexSignSoundSolidification // 将语音包转换为十六进制
soundNum, _ := hex.DecodeString(v) // 十六进制转字符串 voice := ""
intSound, _ := strconv.ParseInt(string(soundNum), 10, 64) for _, v := range strings.Split(sound, "2c") {
int16Sound := strconv.FormatInt(intSound, 16) voice += hexSignSoundSolidification
if intSound < PrintSoundMaxNumber { // 小于十六补位 soundNum, _ := hex.DecodeString(v) // 十六进制转字符串
voice += PlaceFillingParam + int16Sound intSound, _ := strconv.ParseInt(string(soundNum), 10, 64)
} else { int16Sound := strconv.FormatInt(intSound, 16)
voice += int16Sound if intSound < PrintSoundMaxNumber { // 小于十六补位
voice += PlaceFillingParam + int16Sound
} else {
voice += int16Sound
}
} }
soundParam := strings.ReplaceAll(resultV1, sound, "")
soundStr += strings.ReplaceAll(soundParam, byteSignSound, voice)
} }
result = strings.ReplaceAll(result, sound, "")
result = strings.ReplaceAll(result, byteSignSound, voice)
} }
result = soundStr
} }
// 自动合成语音功能 // 自动合成语音功能
//if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { //if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) {

View File

@@ -16,7 +16,7 @@ func TestPrintMsg(t *testing.T) {
msg := &model.PrintMsg{ msg := &model.PrintMsg{
ModelIDCULD: model.ModelIDCULD{}, ModelIDCULD: model.ModelIDCULD{},
PrintNo: "20220707000002", PrintNo: "20220707000002",
Content: "<sound>64,65,66</sound>", Content: "<sound>77</sound>",
OrderNo: 202207261655, OrderNo: 202207261655,
Status: 0, Status: 0,
Comment: "", Comment: "",