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