@siact/sime-x-vue 0.0.21 → 0.0.22

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,
@@ -2330,14 +2375,39 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2330
2375
  tts.stop();
2331
2376
  bubble.hide();
2332
2377
  };
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();
2378
+ const speakQueue = [];
2379
+ let isProcessingSpeakQueue = false;
2380
+ const processSpeakQueue = async () => {
2381
+ if (isProcessingSpeakQueue) return;
2382
+ isProcessingSpeakQueue = true;
2383
+ tts.hasPendingAudio.value = true;
2384
+ while (speakQueue.length > 0) {
2385
+ const text = speakQueue.shift();
2386
+ bubble.open();
2387
+ agent.currentTextContent.value = text;
2388
+ try {
2389
+ await tts.speakAndWait(text);
2390
+ } catch (e) {
2391
+ console.error("[speakQueue] 播报失败:", e);
2392
+ }
2393
+ if (speakQueue.length > 0) {
2394
+ tts.hasPendingAudio.value = true;
2395
+ }
2340
2396
  }
2397
+ isProcessingSpeakQueue = false;
2398
+ tts.hasPendingAudio.value = false;
2399
+ bubble.scheduleDismiss();
2400
+ };
2401
+ const speakTextWithBubble = (text) => {
2402
+ speakQueue.push(text);
2403
+ if (!isProcessingSpeakQueue) {
2404
+ processSpeakQueue();
2405
+ }
2406
+ };
2407
+ const stopSpeak = () => {
2408
+ speakQueue.length = 0;
2409
+ isProcessingSpeakQueue = false;
2410
+ tts.stop();
2341
2411
  };
2342
2412
  const voice = useVoiceRecognition({
2343
2413
  modelPath: props.modelPath,
@@ -2368,7 +2438,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2368
2438
  agentInvoke: agent.invoke,
2369
2439
  agentAbort: agent.abort,
2370
2440
  speakText: speakTextWithBubble,
2371
- stopSpeak: tts.stop
2441
+ stopSpeak
2372
2442
  });
2373
2443
  onBeforeUnmount(async () => {
2374
2444
  bubble.destroy();
@@ -2507,7 +2577,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2507
2577
  }
2508
2578
  });
2509
2579
 
2510
- const voiceAssistant = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ac1884ea"]]);
2580
+ const voiceAssistant = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d15c792e"]]);
2511
2581
 
2512
2582
  var clientCommandKey = /* @__PURE__ */ ((clientCommandKey2) => {
2513
2583
  clientCommandKey2["SET_THEME"] = "SiMeAgent_setTheme";