Commit 2a5f7849 authored by wdvxdr's avatar wdvxdr

feature support silk encoder

parent b1672317
......@@ -369,6 +369,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
return nil, errors.New("private voice unsupported now")
}
data, err := bot.Client.GetTts(d["text"])
ioutil.WriteFile("tts.silk", data, 777)
if err != nil {
return nil, err
}
......@@ -383,7 +384,10 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
return nil, err
}
if !global.IsAMRorSILK(data) {
return nil, errors.New("unsupported voice file format (please use AMR file for now)")
data, err = global.Encoder(data)
if err != nil {
return nil, err
}
}
return &message.VoiceElement{Data: data}, nil
case "face":
......
package global
import (
"crypto/md5"
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/wdvxdr1123/go-silk/silk"
"io/ioutil"
"path"
"sync"
)
var codec silk.Encoder
var useCodec = true
var once sync.Once
func InitCodec() {
once.Do(func() {
log.Info("正在加载silk编码器...")
err := codec.Init("data/cache", "codec")
if err != nil {
log.Error(err)
useCodec = false
}
})
}
func Encoder(data []byte) ([]byte, error) {
if useCodec == false {
return nil, errors.New("no silk encoder")
}
h := md5.New()
h.Write(data)
tempName := fmt.Sprintf("%x", h.Sum(nil))
if silkPath := path.Join("data/cache", tempName+".silk"); PathExists(silkPath) {
return ioutil.ReadFile(silkPath)
}
slk, err := codec.EncodeToSilk(data, tempName, true)
if err != nil {
return nil, err
}
return slk, nil
}
......@@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-20201003051902-8a968656c116
github.com/Mrs4s/MiraiGo v0.0.0-20201005155759-f9b3c399e5e0
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.4.0 // indirect
......@@ -22,10 +22,13 @@ require (
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tebeka/strftime v0.1.5 // indirect
github.com/tidwall/gjson v1.6.1
github.com/ugorji/go v1.1.10 // indirect
github.com/wdvxdr1123/go-silk v0.0.0-20201006020916-0398076200ea
github.com/xujiajun/nutsdb v0.5.0
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
golang.org/x/net v0.0.0-20200930145003-4acb6c075d10 // indirect
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c // indirect
golang.org/x/sys v0.0.0-20201005172224-997123666555 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
gopkg.in/yaml.v2 v2.3.0 // indirect
)
This diff is collapsed.
......@@ -157,6 +157,7 @@ func (s *webServer) Dologin() {
}
log.Info("正在加载事件过滤器.")
global.BootFilter()
global.InitCodec()
coolq.IgnoreInvalidCQCode = conf.IgnoreInvalidCQCode
coolq.ForceFragmented = conf.ForceFragmented
log.Info("资源初始化完成, 开始处理信息.")
......
......@@ -81,9 +81,9 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
go func() {
log.Infof("CQ HTTP 服务器已启动: %v", addr)
s.Http=&http.Server{
Addr:addr,
Handler:s.engine,
s.Http = &http.Server{
Addr: addr,
Handler: s.engine,
}
if err := s.Http.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Error(err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment