1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

fix: tts can't play on ios(#849)

(cherry picked from commit 1ecb1f62dc1d26720298186720b7970b52ee1d5e)

(cherry picked from commit 0487f849bcb887001cb728a21a0ac64c804b7bc3)
This commit is contained in:
wdvxdr 2021-04-22 21:22:30 +08:00
parent 5f247715b9
commit c24a2b327a
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6
5 changed files with 32 additions and 2 deletions

View File

@ -24,9 +24,11 @@ import (
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Mrs4s/MiraiGo/utils"
"github.com/Mrs4s/go-cqhttp/global"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/Mrs4s/go-cqhttp/global"
"github.com/Mrs4s/go-cqhttp/global/codec"
)
/*
@ -667,7 +669,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
if err != nil {
return nil, err
}
return &message.VoiceElement{Data: data}, nil
return &message.VoiceElement{Data: codec.RecodeTo24K(data)}, nil
case "record":
f := d["file"]
data, err := global.FindFile(f, d["cache"], global.VoicePath)

View File

@ -51,3 +51,16 @@ func EncodeToSilk(record []byte, tempName string, useCache bool) (silkWav []byte
}
return
}
// RecodeTo24K 将silk重新编码为 24000 bit rate
func RecodeTo24K(data []byte) []byte {
pcm, err := silk.DecodeSilkBuffToPcm(data, 24000)
if err != nil {
panic(err)
}
data, err = silk.EncodePcmBuffToSilk(pcm, 24000, 24000, true)
if err != nil {
panic(err)
}
return data
}

View File

@ -8,3 +8,8 @@ import "errors"
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
return nil, errors.New("not supported now")
}
// RecodeTo24K 将silk重新编码为 24000 bit rate
func RecodeTo24K(data []byte) []byte {
return data
}

View File

@ -8,3 +8,8 @@ import "errors"
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
return nil, errors.New("not supported now")
}
// RecodeTo24K 将silk重新编码为 24000 bit rate
func RecodeTo24K(data []byte) []byte {
return data
}

View File

@ -6,3 +6,8 @@ import "errors"
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
return nil, errors.New("not supported now")
}
// RecodeTo24K 将silk重新编码为 24000 bit rate
func RecodeTo24K(data []byte) []byte {
return data
}