1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 12:03:50 +08:00

fix(codec): silk sdk conditional compile

This commit is contained in:
wdvxdr 2021-04-22 21:30:51 +08:00
parent 0487f849bc
commit 1ecb1f62dc
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6
5 changed files with 30 additions and 10 deletions

View File

@ -26,9 +26,9 @@ import (
"github.com/Mrs4s/MiraiGo/utils"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/wdvxdr1123/go-silk"
"github.com/Mrs4s/go-cqhttp/global"
"github.com/Mrs4s/go-cqhttp/global/codec"
)
/*
@ -786,15 +786,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m inte
if err != nil {
return nil, err
}
pcm, err := silk.DecodeSilkBuffToPcm(data, 24000)
if err != nil {
return nil, err
}
data, err = silk.EncodePcmBuffToSilk(pcm, 24000, 24000, true)
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
}