@siact/sime-x-vue 0.0.21 → 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1512,7 +1512,15 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1512
1512
  }
1513
1513
  };
1514
1514
  const test = () => {
1515
- aiChatbotX.speakText("你好,世界,今天是想起五天气横扫的缺点");
1515
+ [
1516
+ "1你好,世界,今天是想起五天气横扫的缺点",
1517
+ "2你好,世界,今天是想起五天气横扫的缺点",
1518
+ "3你好,世界,今天是想起五天气横扫的缺点"
1519
+ ].forEach((text, index) => {
1520
+ setTimeout(() => {
1521
+ aiChatbotX.speakText(text);
1522
+ }, index * 1e3);
1523
+ });
1516
1524
  };
1517
1525
  const test1 = () => {
1518
1526
  aiChatbotX.abortInvoke();
@@ -1678,7 +1686,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1678
1686
  }
1679
1687
  });
1680
1688
 
1681
- const commandTest = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-2d2cea1f"]]);
1689
+ const commandTest = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-36096054"]]);
1682
1690
 
1683
1691
  class CommandManager {
1684
1692
  commands = /* @__PURE__ */ new Map();
@@ -1922,6 +1930,37 @@ function useTTS(getVoiceConfig) {
1922
1930
  console.error("[TTS] speak 失败:", err);
1923
1931
  }
1924
1932
  };
1933
+ const speakAndWait = async (text) => {
1934
+ const clean = normalizeSpeakText(text);
1935
+ if (!clean.trim()) return;
1936
+ hasPendingAudio.value = true;
1937
+ const ttsInst = await ensureInstance();
1938
+ if (!ttsInst) {
1939
+ hasPendingAudio.value = false;
1940
+ return;
1941
+ }
1942
+ return new Promise((resolve) => {
1943
+ let settled = false;
1944
+ const settle = () => {
1945
+ if (settled) return;
1946
+ settled = true;
1947
+ clearTimeout(safetyTimer);
1948
+ onQueueEmptyCb = null;
1949
+ resolve();
1950
+ };
1951
+ const safetyTimer = setTimeout(() => {
1952
+ console.warn("[TTS] speakAndWait 安全超时,强制 resolve");
1953
+ settle();
1954
+ }, 6e4);
1955
+ onQueueEmptyCb = settle;
1956
+ try {
1957
+ ttsInst.speak(clean);
1958
+ } catch (err) {
1959
+ console.error("[TTS] speak 失败:", err);
1960
+ settle();
1961
+ }
1962
+ });
1963
+ };
1925
1964
  const feed = (delta) => {
1926
1965
  sentenceBuffer += delta;
1927
1966
  while (true) {
@@ -1944,6 +1983,11 @@ function useTTS(getVoiceConfig) {
1944
1983
  sentenceBuffer = "";
1945
1984
  isSpeaking.value = false;
1946
1985
  hasPendingAudio.value = false;
1986
+ if (onQueueEmptyCb) {
1987
+ const cb = onQueueEmptyCb;
1988
+ onQueueEmptyCb = null;
1989
+ cb();
1990
+ }
1947
1991
  if (instance) {
1948
1992
  try {
1949
1993
  instance.stop();
@@ -1976,6 +2020,7 @@ function useTTS(getVoiceConfig) {
1976
2020
  hasPendingAudio,
1977
2021
  warmUpAudio,
1978
2022
  speak,
2023
+ speakAndWait,
1979
2024
  feed,
1980
2025
  flush,
1981
2026
  stop,
@@ -2277,8 +2322,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2277
2322
  bubbleSize: {},
2278
2323
  bubbleDismissDelay: {}
2279
2324
  },
2280
- setup(__props) {
2325
+ emits: ["wake-up"],
2326
+ setup(__props, { emit: __emit }) {
2281
2327
  const props = __props;
2328
+ const emit = __emit;
2282
2329
  const aiChatbotX = injectStrict(AiChatbotXKey);
2283
2330
  const getVoiceConfig = () => {
2284
2331
  if (props.voiceConfig) return props.voiceConfig;
@@ -2330,20 +2377,46 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2330
2377
  tts.stop();
2331
2378
  bubble.hide();
2332
2379
  };
2333
- const speakTextWithBubble = async (text) => {
2334
- bubble.open();
2335
- agent.currentTextContent.value = text;
2336
- try {
2337
- await tts.speak(text);
2338
- } finally {
2339
- bubble.scheduleDismiss();
2380
+ const speakQueue = [];
2381
+ let isProcessingSpeakQueue = false;
2382
+ const processSpeakQueue = async () => {
2383
+ if (isProcessingSpeakQueue) return;
2384
+ isProcessingSpeakQueue = true;
2385
+ tts.hasPendingAudio.value = true;
2386
+ while (speakQueue.length > 0) {
2387
+ const text = speakQueue.shift();
2388
+ bubble.open();
2389
+ agent.currentTextContent.value = text;
2390
+ try {
2391
+ await tts.speakAndWait(text);
2392
+ } catch (e) {
2393
+ console.error("[speakQueue] 播报失败:", e);
2394
+ }
2395
+ if (speakQueue.length > 0) {
2396
+ tts.hasPendingAudio.value = true;
2397
+ }
2398
+ }
2399
+ isProcessingSpeakQueue = false;
2400
+ tts.hasPendingAudio.value = false;
2401
+ bubble.scheduleDismiss();
2402
+ };
2403
+ const speakTextWithBubble = (text) => {
2404
+ speakQueue.push(text);
2405
+ if (!isProcessingSpeakQueue) {
2406
+ processSpeakQueue();
2340
2407
  }
2341
2408
  };
2409
+ const stopSpeak = () => {
2410
+ speakQueue.length = 0;
2411
+ isProcessingSpeakQueue = false;
2412
+ tts.stop();
2413
+ };
2342
2414
  const voice = useVoiceRecognition({
2343
2415
  modelPath: props.modelPath,
2344
2416
  wakeWords: props.wakeWords,
2345
2417
  getVoiceConfig,
2346
2418
  onWake: () => {
2419
+ emit("wake-up");
2347
2420
  interruptCurrentResponse();
2348
2421
  tts.warmUpAudio();
2349
2422
  const text = wakeResponses.value[Math.floor(Math.random() * wakeResponses.value.length)];
@@ -2368,7 +2441,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2368
2441
  agentInvoke: agent.invoke,
2369
2442
  agentAbort: agent.abort,
2370
2443
  speakText: speakTextWithBubble,
2371
- stopSpeak: tts.stop
2444
+ stopSpeak
2372
2445
  });
2373
2446
  onBeforeUnmount(async () => {
2374
2447
  bubble.destroy();
@@ -2507,7 +2580,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2507
2580
  }
2508
2581
  });
2509
2582
 
2510
- const voiceAssistant = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ac1884ea"]]);
2583
+ const voiceAssistant = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-177013f4"]]);
2511
2584
 
2512
2585
  var clientCommandKey = /* @__PURE__ */ ((clientCommandKey2) => {
2513
2586
  clientCommandKey2["SET_THEME"] = "SiMeAgent_setTheme";