🔖 1.4.0-beta6

This commit is contained in:
源文雨
2022-05-10 23:22:57 +08:00
parent e9fac38c1b
commit e993f93cf4
4 changed files with 20 additions and 15 deletions

View File

@@ -60,9 +60,13 @@ func init() {
Handle(func(ctx *zero.Ctx) {
msg := ctx.ExtractPlainText()
r := aireply.NewAIReply(getReplyMode(ctx))
tts := t.new(t.getSoundMode(ctx))
tts, err := t.new(t.getSoundMode(ctx))
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
if tts != nil {
ctx.SendChain(message.Record(tts.Speak(ctx.Event.UserID, func() string {
rec, err := tts.Speak(ctx.Event.UserID, func() string {
reply := r.TalkPlain(msg, zero.BotConfig.NickName[0])
reply = re.ReplaceAllStringFunc(reply, func(s string) string {
f, err := strconv.ParseFloat(s, 64)
@@ -74,7 +78,10 @@ func init() {
})
log.Debugln("[tts]:", reply)
return reply
})))
})
if err == nil {
ctx.SendChain(message.Record(rec))
}
}
})
engine.OnRegex(`^设置语音模式(.*)$`, ctxext.FirstValueInList(t)).SetBlock(true).
@@ -96,7 +103,7 @@ func init() {
}
// new 语音简单工厂
func (t *ttsInstances) new(name string) (ts tts.TTS) {
func (t *ttsInstances) new(name string) (ts tts.TTS, err error) {
t.RLock()
ts = t.m[name]
t.RUnlock()
@@ -104,11 +111,11 @@ func (t *ttsInstances) new(name string) (ts tts.TTS) {
switch name {
case "拟声鸟阿梓":
t.Lock()
ts, _ = mockingbird.NewMockingBirdTTS(0)
ts, err = mockingbird.NewMockingBirdTTS(0)
t.Unlock()
case "拟声鸟药水哥":
t.Lock()
ts, _ = mockingbird.NewMockingBirdTTS(1)
ts, err = mockingbird.NewMockingBirdTTS(1)
t.Unlock()
}
}