From 714d618550d1aa4c75cab0220c1122cc261a24ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 28 Jul 2022 13:54:46 +0800 Subject: [PATCH] 1 --- business/jxstore/event/event_tcp.go | 13 +++--- business/jxstore/event/event_tcp_utils.go | 54 +++++++++++------------ 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index 2725b3940..32255c58a 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -10,6 +10,7 @@ import ( "net" "strings" "time" + "unicode/utf8" ) //入口 @@ -253,13 +254,11 @@ func (t *TcpClient) doPrint(key string) (err error) { //判断音频暂停? //收到打印成功回调后,如果消息中有音频,需要等待一下,等上一个音频播完 //暂停时间就暂时取的sound标签内内容长度/2 - //if sounds := regexpSoundSpan.FindStringSubmatch(printMsg.Content); len(sounds) > 0 { - // globals.SugarLogger.Debug("sound =====================", sounds) - // sound := sounds[1] - // globals.SugarLogger.Debug("sound =====================", sound) - // lenTime := time.Duration(utf8.RuneCountInString(sound)) * time.Second - // time.Sleep(lenTime / 2) - //} + if sounds := regexpSoundSpan.FindStringSubmatch(printMsg.Content); len(sounds) > 0 { + sound := sounds[1] + lenTime := time.Duration(utf8.RuneCountInString(sound)) * time.Second + time.Sleep(lenTime / 2) + } } } } diff --git a/business/jxstore/event/event_tcp_utils.go b/business/jxstore/event/event_tcp_utils.go index 413957ebd..05e4b3b73 100644 --- a/business/jxstore/event/event_tcp_utils.go +++ b/business/jxstore/event/event_tcp_utils.go @@ -479,33 +479,33 @@ func replaceContent(content string, printMsg *model.PrintMsg) (result string) { result = strings.ReplaceAll(result, byteSignQrRightE, hexSignQrEnd) } // 固定模板输出语音 3c736f756e643e 3634 3c2f736f756e643e - //if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { - // soundStr := "" - // for _, v1 := range strings.Split(result, byteSignSoundE) { - // v1 += byteSignSoundE - // if sounds := regexpSound.FindStringSubmatch(v1); len(sounds) > 0 { - // sound := sounds[1] - // //先把结束标签消了 - // resultV1 := strings.ReplaceAll(v1, byteSignSoundE, "") - // // 将语音包转换为十六进制 - // voice := "" - // for _, v := range strings.Split(sound, "2c") { - // voice += hexSignSoundSolidification - // soundNum, _ := hex.DecodeString(v) // 十六进制转字符串 - // intSound, _ := strconv.ParseInt(string(soundNum), 10, 64) - // int16Sound := strconv.FormatInt(intSound, 16) - // if intSound < PrintSoundMaxNumber { // 小于十六补位 - // voice += PlaceFillingParam + int16Sound - // } else { - // voice += int16Sound - // } - // } - // soundParam := strings.ReplaceAll(resultV1, sound, "") - // soundStr += strings.ReplaceAll(soundParam, byteSignSound, voice) - // } - // } - // result = soundStr - //} + if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { + soundStr := "" + for _, v1 := range strings.Split(result, byteSignSoundE) { + v1 += byteSignSoundE + if sounds := regexpSound.FindStringSubmatch(v1); len(sounds) > 0 { + sound := sounds[1] + //先把结束标签消了 + resultV1 := strings.ReplaceAll(v1, byteSignSoundE, "") + // 将语音包转换为十六进制 + voice := "" + for _, v := range strings.Split(sound, "2c") { + voice += hexSignSoundSolidification + soundNum, _ := hex.DecodeString(v) // 十六进制转字符串 + intSound, _ := strconv.ParseInt(string(soundNum), 10, 64) + int16Sound := strconv.FormatInt(intSound, 16) + if intSound < PrintSoundMaxNumber { // 小于十六补位 + voice += PlaceFillingParam + int16Sound + } else { + voice += int16Sound + } + } + soundParam := strings.ReplaceAll(resultV1, sound, "") + soundStr += strings.ReplaceAll(soundParam, byteSignSound, voice) + } + } + result = soundStr + } // 自动合成语音功能 //if strings.Contains(result, byteSignSound) && strings.Contains(result, byteSignSoundE) { // if sounds := regexpSound.FindStringSubmatch(result); len(sounds) > 0 {