mirror of
https://github.com/idootop/mi-gpt.git
synced 2025-04-07 19:21:30 +00:00
fix: 修复小爱回复无法终止的问题
This commit is contained in:
parent
f4866f8729
commit
025ebe476d
|
@ -110,6 +110,14 @@ export class BaseSpeaker {
|
|||
|
||||
audioBeep?: string;
|
||||
responding = false;
|
||||
/**
|
||||
* 检测是否有新消息
|
||||
*
|
||||
* 有新消息产生时,旧的回复会终止
|
||||
*/
|
||||
checkIfHasNewMsg() {
|
||||
return { hasNewMsg: () => false, noNewMsg: () => true };
|
||||
}
|
||||
async response(options: {
|
||||
tts?: TTSProvider;
|
||||
text?: string;
|
||||
|
@ -118,6 +126,7 @@ export class BaseSpeaker {
|
|||
speaker?: string;
|
||||
keepAlive?: boolean;
|
||||
playSFX?: boolean;
|
||||
hasNewMsg?: () => boolean;
|
||||
}) {
|
||||
let {
|
||||
text,
|
||||
|
@ -127,6 +136,7 @@ export class BaseSpeaker {
|
|||
keepAlive = false,
|
||||
tts = this.tts,
|
||||
} = options ?? {};
|
||||
options.hasNewMsg ??= this.checkIfHasNewMsg().hasNewMsg;
|
||||
|
||||
const doubaoTTS = process.env.TTS_DOUBAO;
|
||||
if (!doubaoTTS) {
|
||||
|
@ -203,6 +213,7 @@ export class BaseSpeaker {
|
|||
speaker?: string;
|
||||
keepAlive?: boolean;
|
||||
playSFX?: boolean;
|
||||
hasNewMsg?: () => boolean;
|
||||
}) {
|
||||
let {
|
||||
text,
|
||||
|
@ -214,6 +225,14 @@ export class BaseSpeaker {
|
|||
speaker = this._defaultSpeaker,
|
||||
} = options ?? {};
|
||||
|
||||
const hasNewMsg = () => {
|
||||
const flag = options.hasNewMsg?.();
|
||||
if (this.debug) {
|
||||
this.logger.debug("checkIfHasNewMsg:" + flag);
|
||||
}
|
||||
return flag;
|
||||
};
|
||||
|
||||
const ttsText = text?.replace(/\n\s*\n/g, "\n")?.trim();
|
||||
const ttsNotXiaoai = !stream && !!text && !audio && tts !== "xiaoai";
|
||||
playSFX = ttsNotXiaoai && playSFX;
|
||||
|
@ -258,6 +277,7 @@ export class BaseSpeaker {
|
|||
playing = { ...playing, ...res };
|
||||
}
|
||||
if (
|
||||
hasNewMsg() ||
|
||||
!this.responding || // 有新消息
|
||||
(playing.status === "playing" && playing.media_type) // 小爱自己开始播放音乐
|
||||
) {
|
||||
|
|
|
@ -10,11 +10,11 @@ import { testMiGPT } from "./migpt";
|
|||
async function main() {
|
||||
// println(kBannerASCII);
|
||||
// testDB();
|
||||
testSpeaker();
|
||||
// testSpeaker();
|
||||
// testOpenAI();
|
||||
// testMyBot();
|
||||
// testLog();
|
||||
// testMiGPT();
|
||||
testMiGPT();
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
@ -18,6 +18,7 @@ export async function testMiGPT() {
|
|||
userId: process.env.MI_USER!,
|
||||
password: process.env.MI_PASS!,
|
||||
did: process.env.MI_DID,
|
||||
debug: true,
|
||||
},
|
||||
bot: {
|
||||
name: "傻妞",
|
||||
|
|
|
@ -11,7 +11,7 @@ export async function testSpeaker() {
|
|||
debug: true,
|
||||
});
|
||||
await speaker.initMiServices();
|
||||
await testAISpeakerStatus(speaker);
|
||||
// await testAISpeakerStatus(speaker);
|
||||
// await testSpeakerResponse(speaker);
|
||||
await testSpeakerStreamResponse(speaker);
|
||||
// await testSpeakerGetMessages(speaker);
|
||||
|
|
Loading…
Reference in New Issue
Block a user