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
- ✅ 修复 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))
- ✅ 修复使用提示音链接时,小爱回答完毕后,仍然重复播放文字提示语的问题。
- 优化网络请求错误重试策略(消息/播放状态轮询)

View File

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

View File

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