fix: 提示语列表为空时不播放提示音

This commit is contained in:
WJG 2024-06-11 21:13:30 +08:00
parent 1f7e815df3
commit 46a74d9eaa
No known key found for this signature in database
GPG Key ID: 258474EF8590014A
3 changed files with 25 additions and 18 deletions

View File

@ -5,7 +5,7 @@
## 🔥 Hotfix ## 🔥 Hotfix
- ✅ 修复 MIoT 和 Mina 接口查询到的设备名称不一致的问题。https://github.com/idootop/mi-gpt/issues/62 - ✅ 修复 MIoT 和 Mina 接口查询到的设备名称不一致的问题。https://github.com/idootop/mi-gpt/issues/62
- 提示语列表为空或提示语和提示音链接都为空时不播放提示音。https://github.com/idootop/mi-gpt/issues/30#issuecomment-2153786207 - 提示语列表为空或提示语和提示音链接都为空时不播放提示音。https://github.com/idootop/mi-gpt/issues/30#issuecomment-2153786207
- 修复唤醒模式下,重新匹配唤醒词时,应该走询问 AI 的流程。([issues#25](https://github.com/idootop/mi-gpt/issues/25)) - 修复唤醒模式下,重新匹配唤醒词时,应该走询问 AI 的流程。([issues#25](https://github.com/idootop/mi-gpt/issues/25))
- ✅ 修复使用提示音链接时,小爱回答完毕后,仍然重复播放文字提示语的问题。 - ✅ 修复使用提示音链接时,小爱回答完毕后,仍然重复播放文字提示语的问题。
- 优化网络请求错误重试策略(消息/播放状态轮询) - 优化网络请求错误重试策略(消息/播放状态轮询)

View File

@ -144,7 +144,10 @@ export class AISpeaker extends Speaker {
return; return;
} }
// 回应 // 回应
await this.response({ text: pickOne(this.onEnterAI)!, keepAlive: true }); const text = pickOne(this.onEnterAI);
if (text) {
await this.response({ text, keepAlive: true });
}
// 唤醒 // 唤醒
await super.enterKeepAlive(); await super.enterKeepAlive();
} }
@ -153,11 +156,10 @@ export class AISpeaker extends Speaker {
// 退出唤醒状态 // 退出唤醒状态
await super.exitKeepAlive(); await super.exitKeepAlive();
// 回应 // 回应
await this.response({ const text = pickOne(this.onExitAI);
text: pickOne(this.onExitAI)!, if (text) {
keepAlive: false, await this.response({ text, keepAlive: false, playSFX: false });
playSFX: false, }
});
await this.unWakeUp(); await this.unWakeUp();
} }
@ -207,10 +209,10 @@ export class AISpeaker extends Speaker {
private _askAIForAnswerSteps: AnswerStep[] = [ private _askAIForAnswerSteps: AnswerStep[] = [
async (msg, data) => { async (msg, data) => {
// 思考中 // 思考中
await this.response({ const text = pickOne(this.onAIAsking);
audio: this.audioActive, if (text) {
text: pickOne(this.onAIAsking)!, await this.response({ text, audio: this.audioActive });
}); }
}, },
async (msg, data) => { async (msg, data) => {
// 调用 AI 获取回复 // 调用 AI 获取回复
@ -232,18 +234,19 @@ export class AISpeaker extends Speaker {
this.streamResponse this.streamResponse
) { ) {
// 回复完毕 // 回复完毕
await this.response({ const text = pickOne(this.onAIReplied);
text: pickOne(this.onAIReplied)!, if (text) {
}); await this.response({ text });
}
} }
}, },
async (msg, data) => { async (msg, data) => {
if (data.res === "error") { if (data.res === "error") {
// 回答异常 // 回答异常
await this.response({ const text = pickOne(this.onAIError);
audio: this.audioError, if (text) {
text: pickOne(this.onAIError)!, await this.response({ text, audio: this.audioError });
}); }
} }
}, },
async (msg, data) => { async (msg, data) => {

View File

@ -196,6 +196,10 @@ export class BaseSpeaker {
} = options ?? {}; } = options ?? {};
options.hasNewMsg ??= this.checkIfHasNewMsg().hasNewMsg; options.hasNewMsg ??= this.checkIfHasNewMsg().hasNewMsg;
if (!text && !stream && !audio) {
return;
}
const doubaoTTS = process.env.TTS_DOUBAO; const doubaoTTS = process.env.TTS_DOUBAO;
if (!doubaoTTS) { if (!doubaoTTS) {
tts = "xiaoai"; // 没有提供豆包语音接口时,只能使用小爱自带 TTS tts = "xiaoai"; // 没有提供豆包语音接口时,只能使用小爱自带 TTS