mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-21 23:50:09 +08:00
🔥 🎨 tts
This commit is contained in:
parent
6932643788
commit
48deaf3aca
@ -20,12 +20,20 @@ import (
|
|||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const ttsServiceName = "tts"
|
||||||
ttsServiceName = "tts"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
t *ttsInstances
|
t = &ttsInstances{
|
||||||
|
m: map[string]tts.TTS{
|
||||||
|
"百度女声": baidutts.NewBaiduTTS(0),
|
||||||
|
"百度男声": baidutts.NewBaiduTTS(1),
|
||||||
|
"百度度逍遥": baidutts.NewBaiduTTS(3),
|
||||||
|
"百度度丫丫": baidutts.NewBaiduTTS(4),
|
||||||
|
"拟声鸟阿梓": mockingbird.NewMockingBirdTTS(0),
|
||||||
|
"拟声鸟药水哥": mockingbird.NewMockingBirdTTS(1),
|
||||||
|
},
|
||||||
|
l: []string{"拟声鸟阿梓", "拟声鸟药水哥", "百度女声", "百度男声", "百度度逍遥", "百度度丫丫"},
|
||||||
|
}
|
||||||
re = regexp.MustCompile(`(\-|\+)?\d+(\.\d+)?`)
|
re = regexp.MustCompile(`(\-|\+)?\d+(\.\d+)?`)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,17 +47,6 @@ func (t *ttsInstances) List() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
t = &ttsInstances{
|
|
||||||
m: map[string]tts.TTS{
|
|
||||||
"百度女声": baidutts.NewBaiduTTS(0),
|
|
||||||
"百度男声": baidutts.NewBaiduTTS(1),
|
|
||||||
"百度度逍遥": baidutts.NewBaiduTTS(3),
|
|
||||||
"百度度丫丫": baidutts.NewBaiduTTS(4),
|
|
||||||
"拟声鸟阿梓": mockingbird.NewMockingBirdTTS(0),
|
|
||||||
"拟声鸟药水哥": mockingbird.NewMockingBirdTTS(1),
|
|
||||||
},
|
|
||||||
l: []string{"拟声鸟阿梓", "拟声鸟药水哥", "百度女声", "百度男声", "百度度逍遥", "百度度丫丫"},
|
|
||||||
}
|
|
||||||
engine := control.Register(ttsServiceName, order.AcquirePrio(), &control.Options{
|
engine := control.Register(ttsServiceName, order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "语音回复(包括拟声鸟和百度)\n- @Bot 任意文本(任意一句话回复)\n- 设置语音模式拟声鸟阿梓 | 设置语音模式拟声鸟药水哥 | 设置语音模式百度女声 | 设置语音模式百度男声| 设置语音模式百度度逍遥 | 设置语音模式百度度丫丫",
|
Help: "语音回复(包括拟声鸟和百度)\n- @Bot 任意文本(任意一句话回复)\n- 设置语音模式拟声鸟阿梓 | 设置语音模式拟声鸟药水哥 | 设置语音模式百度女声 | 设置语音模式百度男声| 设置语音模式百度度逍遥 | 设置语音模式百度度丫丫",
|
||||||
@ -58,7 +55,7 @@ func init() {
|
|||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
msg := ctx.ExtractPlainText()
|
msg := ctx.ExtractPlainText()
|
||||||
r := aireply.NewAIReply(getReplyMode(ctx))
|
r := aireply.NewAIReply(getReplyMode(ctx))
|
||||||
tts := newTTS(getSoundMode(ctx))
|
tts := t.new(t.getSoundMode(ctx))
|
||||||
ctx.SendChain(message.Record(tts.Speak(ctx.Event.UserID, func() string {
|
ctx.SendChain(message.Record(tts.Speak(ctx.Event.UserID, func() string {
|
||||||
reply := r.TalkPlain(msg, zero.BotConfig.NickName[0])
|
reply := r.TalkPlain(msg, zero.BotConfig.NickName[0])
|
||||||
reply = re.ReplaceAllStringFunc(reply, func(s string) string {
|
reply = re.ReplaceAllStringFunc(reply, func(s string) string {
|
||||||
@ -76,7 +73,7 @@ func init() {
|
|||||||
engine.OnRegex(`^设置语音模式(.*)$`, ctxext.FirstValueInList(t)).SetBlock(true).
|
engine.OnRegex(`^设置语音模式(.*)$`, ctxext.FirstValueInList(t)).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
param := ctx.State["regex_matched"].([]string)[1]
|
param := ctx.State["regex_matched"].([]string)[1]
|
||||||
err := setSoundMode(ctx, param)
|
err := t.setSoundMode(ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(err))
|
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(err))
|
||||||
return
|
return
|
||||||
@ -85,12 +82,12 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// newTTS 语音简单工厂
|
// new 语音简单工厂
|
||||||
func newTTS(name string) tts.TTS {
|
func (t *ttsInstances) new(name string) tts.TTS {
|
||||||
return t.m[name]
|
return t.m[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
func setSoundMode(ctx *zero.Ctx, name string) error {
|
func (t *ttsInstances) setSoundMode(ctx *zero.Ctx, name string) error {
|
||||||
gid := ctx.Event.GroupID
|
gid := ctx.Event.GroupID
|
||||||
if gid == 0 {
|
if gid == 0 {
|
||||||
gid = -ctx.Event.UserID
|
gid = -ctx.Event.UserID
|
||||||
@ -109,7 +106,7 @@ func setSoundMode(ctx *zero.Ctx, name string) error {
|
|||||||
return m.SetData(gid, index)
|
return m.SetData(gid, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSoundMode(ctx *zero.Ctx) (name string) {
|
func (t *ttsInstances) getSoundMode(ctx *zero.Ctx) (name string) {
|
||||||
gid := ctx.Event.GroupID
|
gid := ctx.Event.GroupID
|
||||||
if gid == 0 {
|
if gid == 0 {
|
||||||
gid = -ctx.Event.UserID
|
gid = -ctx.Event.UserID
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user