refactor: 更新唤醒词格式,与文档行为一致 fix #8

This commit is contained in:
WJG 2024-05-26 18:57:33 +08:00
parent 02b033402e
commit 5a537fee23
No known key found for this signature in database
GPG Key ID: 258474EF8590014A
3 changed files with 52 additions and 37 deletions

View File

@ -1,11 +1,11 @@
const botName = "傻妞";
// 小爱音箱扮演角色的简介
const botProfile = `
性别
性格乖巧可爱
爱好喜欢搞怪爱吃醋
`;
const masterName = "陆小千";
// 小爱音箱主人(你)的简介
const masterProfile = `
性别
性格善良正直
@ -13,26 +13,40 @@ const masterProfile = `
`;
export default {
speaker: {
userId: process.env.MI_USER,
password: process.env.MI_PASS,
did: process.env.MI_DID,
/**
* 小米音箱 TTS 指令
*
* 比如小爱音箱 Prolx06 -> [5, 1]
*
* 不同设备的具体指令可在此网站查询https://home.miot-spec.com
*/
ttsCommand: [5, 1],
wakeUpCommand: [5, 3],
},
bot: {
name: botName,
name: "傻妞",
profile: botProfile,
},
master: {
name: masterName,
name: "陆小千",
profile: masterProfile,
},
// 当消息以召唤关键词开头时,会调用 AI 来回复消息
callAIPrefix: ["请", "你", "傻妞"],
// 当消息中包含唤醒关键词时,会进入 AI 唤醒状态
wakeUpKeywords: ["打开", "进入", "召唤"],
// 当消息中包含退出关键词时,会退出 AI 唤醒状态
exitKeywords: ["关闭", "退出", "再见"],
// 进入 AI 模式的欢迎语
onEnterAI: ["你好,我是傻妞,很高兴认识你"],
// 退出 AI 模式的提示语
onExitAI: ["傻妞已退出"],
// AI 开始回答时的提示语
onAIAsking: ["让我先想想", "请稍等"],
// AI 回答异常时的提示语
onAIError: ["啊哦,出错了,请稍后再试吧!"],
// 无响应一段时间后,多久自动退出唤醒模式(单位秒,默认 30 秒)
exitKeepAliveAfter: 30,
speaker: {
// TTS 指令
ttsCommand: [5, 1],
// 设备唤醒指令
wakeUpCommand: [5, 3],
// 小爱音箱 ID 或名称
did: process.env.MI_DID,
// 小米账号
userId: process.env.MI_USER,
// 账号密码
password: process.env.MI_PASS,
},
};

View File

@ -129,7 +129,7 @@ main();
| `callAIPrefix` | 当消息以召唤关键词开头时,会调用 AI 来响应用户消息 | `["请","傻妞"]` |
| `wakeUpKeywords` | 当消息中包含唤醒关键词时,会进入 AI 唤醒状态 | `["召唤傻妞","打开傻妞"]` |
| `exitKeywords` | 当消息中包含退出关键词时,会退出 AI 唤醒状态 | `["退出傻妞","关闭傻妞"]` |
| `onEnterAI` | 进入 AI 模式的欢迎语 | `["你好,我是傻妞,请问有什么能够帮你的吗?"]` |
| `onEnterAI` | 进入 AI 模式的欢迎语 | `["你好,我是傻妞,很高兴认识你"]` |
| `onExitAI` | 退出 AI 模式的提示语 | `["傻妞已退出"]` |
| `onAIAsking` | AI 开始回答时的提示语 | `["请稍等,让我想想"]` |
| `onAIError` | AI 回答异常时的提示语 | `["出错了,请稍后再试吧!"]` |

View File

@ -60,7 +60,7 @@ export type AISpeakerConfig = SpeakerConfig & {
/**
* AI
*
*
*
*/
onEnterAI?: string[];
/**
@ -88,11 +88,11 @@ export class AISpeaker extends Speaker {
askAI: AISpeakerConfig["askAI"];
name: string;
switchSpeakerPrefix: string[];
onEnterAI: () => string[];
onExitAI: () => string[];
callAIPrefix: () => string[];
wakeUpKeywords: () => string[];
exitKeywords: () => string[];
onEnterAI: string[];
onExitAI: string[];
callAIPrefix: string[];
wakeUpKeywords: string[];
exitKeywords: string[];
onAIAsking: string[];
onAIError: string[];
audio_active?: string;
@ -104,8 +104,11 @@ export class AISpeaker extends Speaker {
askAI,
name = "傻妞",
switchSpeakerPrefix,
callAIPrefix = ["请", "你", "傻妞"],
wakeUpKeywords = ["打开", "进入", "召唤"],
exitKeywords = ["关闭", "退出", "再见"],
onEnterAI = ["你好,我是傻妞,很高兴认识你"],
onExitAI = ["傻妞已退出"],
onAIAsking = ["让我先想想", "请稍等"],
onAIError = ["啊哦,出错了,请稍后再试吧!"],
audio_active = process.env.AUDIO_ACTIVE,
@ -119,18 +122,16 @@ export class AISpeaker extends Speaker {
this.audio_error = audio_error;
this.switchSpeakerPrefix =
switchSpeakerPrefix ?? getDefaultSwitchSpeakerPrefix();
this.wakeUpKeywords = () => wakeUpKeywords.map((e) => e + this.name);
this.exitKeywords = () => exitKeywords.map((e) => e + this.name);
this.onEnterAI = () =>
config.onEnterAI ?? [`你好,我是${this.name},很高兴为你服务!`];
this.onExitAI = () => config.onExitAI ?? [`${this.name}已关闭!`];
this.callAIPrefix = () =>
config.callAIPrefix ?? ["请", "你", this.name, "问问" + this.name];
this.wakeUpKeywords = wakeUpKeywords;
this.exitKeywords = exitKeywords;
this.onEnterAI = onEnterAI;
this.onExitAI = onExitAI;
this.callAIPrefix = callAIPrefix;
}
async enterKeepAlive() {
// 回应
await this.response({ text: pickOne(this.onEnterAI())!, keepAlive: true });
await this.response({ text: pickOne(this.onEnterAI)!, keepAlive: true });
// 唤醒
await super.enterKeepAlive();
}
@ -140,7 +141,7 @@ export class AISpeaker extends Speaker {
await super.exitKeepAlive();
// 回应
await this.response({
text: pickOne(this.onExitAI())!,
text: pickOne(this.onExitAI)!,
keepAlive: false,
playSFX: false,
});
@ -150,13 +151,13 @@ export class AISpeaker extends Speaker {
get commands() {
return [
{
match: (msg) => this.wakeUpKeywords().some((e) => msg.text.includes(e)),
match: (msg) => this.wakeUpKeywords.some((e) => msg.text.includes(e)),
run: async (msg) => {
await this.enterKeepAlive();
},
},
{
match: (msg) => this.exitKeywords().some((e) => msg.text.includes(e)),
match: (msg) => this.exitKeywords.some((e) => msg.text.includes(e)),
run: async (msg) => {
await this.exitKeepAlive();
},
@ -183,7 +184,7 @@ export class AISpeaker extends Speaker {
{
match: (msg) =>
this.keepAlive ||
this.callAIPrefix().some((e) => msg.text.startsWith(e)),
this.callAIPrefix.some((e) => msg.text.startsWith(e)),
run: (msg) => this.askAIForAnswer(msg),
},
] as SpeakerCommand[];