Compare commits
No commits in common. "9360d598b0ffaeb4b5e46a54e1b3b0c24130452f" and "55502295ca51ddf680f822e4464cd04114718b59" have entirely different histories.
9360d598b0
...
55502295ca
@ -14,10 +14,8 @@ const SILENCE_TIMEOUT_MS = 5000;
|
|||||||
const MIN_VALID_DURATION_SEC = 0.5;
|
const MIN_VALID_DURATION_SEC = 0.5;
|
||||||
// 播报超时保护(毫秒):如果FINISHED回调未触发,自动恢复状态
|
// 播报超时保护(毫秒):如果FINISHED回调未触发,自动恢复状态
|
||||||
const BROADCAST_TIMEOUT_MS = 60000;
|
const BROADCAST_TIMEOUT_MS = 60000;
|
||||||
const APPID = "i-sfyrkdr0ubepa";
|
const APPID = "i-sfqpfp8qayj8e";
|
||||||
const APP_KEY = "72vpdansbpg8nxjbxzhp";
|
const APP_KEY = "rdjqhnp5q50e010wvw0z";
|
||||||
// 打断词列表:识别到这些词时自动打断播报
|
|
||||||
const INTERRUPT_KEYWORDS = ["稍等一下", "停一下", "抱歉打断一下", "不好意思", "对不起", "停", "闭嘴"];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测文本是否包含实质内容(去除空白和标点后仍有字符)
|
* 检测文本是否包含实质内容(去除空白和标点后仍有字符)
|
||||||
@ -31,17 +29,6 @@ const hasSubstantialContent = (text: string): boolean => {
|
|||||||
return cleaned.length > 0;
|
return cleaned.length > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测文本是否包含打断词
|
|
||||||
*/
|
|
||||||
const containsInterruptKeyword = (text: string): boolean => {
|
|
||||||
const cleaned = text.replace(
|
|
||||||
/[\s\u3000.,!?;:,。!?;:、…—\-_·""''()()\[\]【】《》<>]/g,
|
|
||||||
"",
|
|
||||||
);
|
|
||||||
return INTERRUPT_KEYWORDS.some((keyword) => cleaned.includes(keyword));
|
|
||||||
};
|
|
||||||
|
|
||||||
enum ReadyState {
|
enum ReadyState {
|
||||||
UNINSTANTIATED = -1,
|
UNINSTANTIATED = -1,
|
||||||
CONNECTING = 0,
|
CONNECTING = 0,
|
||||||
@ -154,8 +141,6 @@ export function useDigitalHuman(options?: {
|
|||||||
|
|
||||||
// 播报超时保护计时器
|
// 播报超时保护计时器
|
||||||
let broadcastTimeoutId: ReturnType<typeof setTimeout> | null = null;
|
let broadcastTimeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||||
// 打断词检测时间戳:用于忽略打断后延迟到达的ASR结果
|
|
||||||
let lastInterruptTime = 0;
|
|
||||||
|
|
||||||
const clearBroadcastTimeout = () => {
|
const clearBroadcastTimeout = () => {
|
||||||
if (broadcastTimeoutId !== null) {
|
if (broadcastTimeoutId !== null) {
|
||||||
@ -179,23 +164,19 @@ export function useDigitalHuman(options?: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 进入播报状态
|
* 进入播报状态:静音麦克风 + 暂停静音检测器(互斥锁)
|
||||||
* RTC模式下保持麦克风开启,允许ASR识别打断词
|
|
||||||
*/
|
*/
|
||||||
const enterBroadcasting = () => {
|
const enterBroadcasting = () => {
|
||||||
isBroadcasting.value = true;
|
isBroadcasting.value = true;
|
||||||
setPickPhase("broadcasting", "数字人开始播报");
|
setPickPhase("broadcasting", "数字人开始播报");
|
||||||
startBroadcastTimeout();
|
startBroadcastTimeout();
|
||||||
// RTC模式:播报期间保持麦克风开启,允许ASR识别打断词
|
// RTC模式:播报期间禁用拾音
|
||||||
if (audioMode.value === "rtc") {
|
if (audioMode.value === "rtc") {
|
||||||
humanInstanceRef.value?.muteMicrophone?.(false);
|
humanInstanceRef.value?.muteMicrophone?.(true);
|
||||||
isMuted.value = false;
|
isMuted.value = true;
|
||||||
canTransfer.value = true;
|
canTransfer.value = false;
|
||||||
const resumed = silenceDetector.resume();
|
silenceDetector.pause();
|
||||||
if (!resumed) {
|
console.info("[播报] RTC模式:麦克风已静音,静音检测器已暂停");
|
||||||
startSilenceDetection();
|
|
||||||
}
|
|
||||||
console.info("[播报] RTC模式:麦克风保持开启,允许ASR识别打断词");
|
|
||||||
}
|
}
|
||||||
console.info("[播报] 开始播报,等待FINISHED信号");
|
console.info("[播报] 开始播报,等待FINISHED信号");
|
||||||
};
|
};
|
||||||
@ -325,15 +306,9 @@ export function useDigitalHuman(options?: {
|
|||||||
type,
|
type,
|
||||||
} = JSON.parse(content.body);
|
} = JSON.parse(content.body);
|
||||||
if (type === "QUERY") {
|
if (type === "QUERY") {
|
||||||
// 播报期间检测打断词:识别到打断词后仅中断播报并恢复拾音,不调用LLM接口
|
// 播报期间忽略ASR结果(双重守卫:麦克风已静音,但防止残余回调)
|
||||||
if (pickPhase.value === "broadcasting") {
|
if (pickPhase.value === "broadcasting") {
|
||||||
const hasInterrupt = containsInterruptKeyword(subtitleContent);
|
console.info("[状态机] 播报中收到ASR结果,忽略");
|
||||||
if (hasInterrupt) {
|
|
||||||
console.info(`[打断词检测] 播报中识别到打断词: "${subtitleContent}",自动打断(仅中断播报,不调用LLM)`);
|
|
||||||
interrupt();
|
|
||||||
} else {
|
|
||||||
console.info(`[打断词检测] 播报中收到ASR结果: "${subtitleContent}",非打断词,忽略`);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,13 +321,6 @@ export function useDigitalHuman(options?: {
|
|||||||
// idle 状态下收到 QUERY:必须验证内容有实质才允许状态转换
|
// idle 状态下收到 QUERY:必须验证内容有实质才允许状态转换
|
||||||
// 环境噪音可能触发 ASR 产生空白/标点内容的 QUERY,不应进入识别
|
// 环境噪音可能触发 ASR 产生空白/标点内容的 QUERY,不应进入识别
|
||||||
if (pickPhase.value === "idle") {
|
if (pickPhase.value === "idle") {
|
||||||
// 忽略打断后3秒内到达的延迟ASR结果(避免打断词被当作新输入)
|
|
||||||
if (Date.now() - lastInterruptTime < 3000) {
|
|
||||||
console.info(
|
|
||||||
"[状态机] 打断后延迟到达的ASR结果,忽略",
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const hasSubstance = hasSubstantialContent(subtitleContent);
|
const hasSubstance = hasSubstantialContent(subtitleContent);
|
||||||
if (!hasSubstance) {
|
if (!hasSubstance) {
|
||||||
console.info(
|
console.info(
|
||||||
@ -528,8 +496,8 @@ export function useDigitalHuman(options?: {
|
|||||||
token: token.value,
|
token: token.value,
|
||||||
wrapperId: "human-wrapper",
|
wrapperId: "human-wrapper",
|
||||||
connectParams: {
|
connectParams: {
|
||||||
ttsPer: "20007751",
|
ttsPer: "5135",
|
||||||
figureId: "4000821",
|
figureId: "4000288",
|
||||||
resolutionHeight: 1920,
|
resolutionHeight: 1920,
|
||||||
resolutionWidth: 1080,
|
resolutionWidth: 1080,
|
||||||
inactiveDisconnectSec: 300,
|
inactiveDisconnectSec: 300,
|
||||||
@ -622,8 +590,6 @@ export function useDigitalHuman(options?: {
|
|||||||
console.info("发送打断");
|
console.info("发送打断");
|
||||||
clearBroadcastTimeout();
|
clearBroadcastTimeout();
|
||||||
await humanInstanceRef.value?.interrupt?.();
|
await humanInstanceRef.value?.interrupt?.();
|
||||||
// 记录打断时间戳,用于忽略打断后延迟到达的ASR结果
|
|
||||||
lastInterruptTime = Date.now();
|
|
||||||
// 打断后播报结束,恢复状态
|
// 打断后播报结束,恢复状态
|
||||||
if (isBroadcasting.value) {
|
if (isBroadcasting.value) {
|
||||||
isBroadcasting.value = false;
|
isBroadcasting.value = false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user