dsh-voice-mode 0.7.26 → 0.7.27
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.
- package/README.en.md +13 -5
- package/README.md +27 -6
- package/lib/client.js +541 -77
- package/lib/index.js +165 -22
- package/package.json +2 -2
package/lib/client.js
CHANGED
|
@@ -1690,13 +1690,24 @@ var zh = {
|
|
|
1690
1690
|
descBargeInSalvage: "AI \u6717\u8BFB\u65F6\u4F60\u5F00\u53E3\u6253\u65AD\uFF1A\u81EA\u52A8\u4FDD\u7559\u4ECE\u5F00\u53E3\u5230\u6253\u65AD\u751F\u6548\u4E4B\u95F4\u4F60\u8BF4\u7684\u8BDD\uFF0C\u5E76\u5165\u8BC6\u522B\u7EE7\u7EED\u53D1\u9001\uFF08\u4FEE\u300C\u6253\u65AD\u5403\u53E5\u300D\uFF1B\u5173 = \u4E22\u5F03\u6253\u65AD\u524D\u8BED\u97F3\u2014\u2014\u4EC5\u5916\u653E\u4E14\u65E0\u56DE\u58F0\u6D88\u9664\u7684\u73AF\u5883\u5EFA\u8BAE\u5173\uFF09",
|
|
1691
1691
|
descLlmCorrect: "\u53D1\u9001\u524D\u7528\u5927\u6A21\u578B\u5BF9\u6574\u6761\u8BED\u97F3\u6587\u672C\u505A\u4E00\u6B21\u7EA0\u9519\uFF08\u53EA\u6539\u9519\u522B\u5B57/\u540C\u97F3\u5B57/\u6807\u70B9\uFF0C\u4FDD\u6301\u539F\u610F\uFF1B\u9700\u5BBF\u4E3B\u5DF2\u914D\u7F6E\u9ED8\u8BA4\u6A21\u578B\uFF0C\u672A\u914D\u7F6E\u5219\u81EA\u52A8\u7528\u539F\u6587\uFF09\u3002\u5F00 = \u6BCF\u6761\u6D88\u606F\u591A\u4E00\u6B21\u7EA0\u9519\u7B49\u5F85\uFF1A\u901A\u5E38 1 \u79D2\u5185\uFF0C\u6700\u957F\u7EA6 10 \u79D2\uFF1B\u6BCF\u5206\u949F\u6700\u591A 10 \u6B21\uFF0C\u8BED\u97F3\u6A21\u5F0F\u5173\u95ED\u6216\u89E6\u53D1\u9650\u6D41\u65F6\u6309\u539F\u6587\u53D1\u9001\u3002\u7EA0\u9519\u5931\u8D25\u6216\u8F93\u51FA\u5F02\u5E38\u540C\u6837\u81EA\u52A8\u7528\u539F\u6587",
|
|
1692
1692
|
descYieldMs: "\u8BA9\u4F4D\u8BED\u4E49\u89E6\u53D1\u540E\u7B49\u5F85\u65F6\u957F\uFF08\u6BEB\u79D2\uFF0C500-3000\uFF0C\u9ED8\u8BA4 1500\uFF1B\u7A97\u53E3\u5185\u7528\u6237\u771F\u8981\u8BF4\u5219\u539F hardBreak \u63A5\u7BA1\uFF0C\u7A97\u53E3\u5230\u70B9\u81EA\u52A8\u6062\u590D\u64AD\u653E\uFF09\u3002\u4EC5\u300C\u6309\u4F4F\u8BF4\u8BDD\u300D\u6A21\u5F0F\u64AD\u653E\u671F\u53EF\u89E6\u53D1",
|
|
1693
|
-
descMode: "\u4EA4\u4E92\u6A21\u5F0F\uFF08toggle \u6301\u7EED\u8046\u542C+\u9759\u97F3\u65AD\u53E5 / hold \u6309\u4F4F\u8BF4\u8BDD\uFF09",
|
|
1693
|
+
descMode: "\u4EA4\u4E92\u6A21\u5F0F\uFF08toggle \u6301\u7EED\u8046\u542C+\u9759\u97F3\u65AD\u53E5 / hold \u6309\u4F4F\u8BF4\u8BDD / once \u8BF4\u5B8C\u4E00\u6BB5\u3001\u7B49\u56DE\u590D\u6717\u8BFB\u5B8C\u518D\u81EA\u52A8\u9000\u51FA\uFF09",
|
|
1694
1694
|
modeToggle: "\u6301\u7EED\u8046\u542C",
|
|
1695
1695
|
modeHold: "\u6309\u4F4F\u8BF4\u8BDD",
|
|
1696
|
+
modeOnce: "\u8BF4\u5B8C\u5C31\u5173",
|
|
1697
|
+
stopReading: "\u505C\u6B62\u6717\u8BFB",
|
|
1698
|
+
readAloudLabel: "\u6717\u8BFB\u56DE\u590D",
|
|
1699
|
+
readAloudVoice: "\u8BED\u97F3\u6A21\u5F0F",
|
|
1700
|
+
readAloudAlways: "\u603B\u662F",
|
|
1701
|
+
readAloudOff: "\u5173\u95ED",
|
|
1702
|
+
descReadAloud: "\u8BED\u97F3\u6A21\u5F0F=\u53EA\u5728\u8BED\u97F3\u6A21\u5F0F\u91CC\u6717\u8BFB\uFF08\u9ED8\u8BA4\uFF09\uFF1B\u603B\u662F=\u5F53\u524D\u4F1A\u8BDD\u7684\u6BCF\u6761\u56DE\u590D\u90FD\u6717\u8BFB\uFF08\u542B\u6253\u5B57\u53D1\u9001\u7684\uFF09\uFF1B\u5173\u95ED=\u4ECE\u4E0D\u6717\u8BFB",
|
|
1703
|
+
showCaptionsLabel: "\u5B57\u5E55\u6D6E\u5C42",
|
|
1704
|
+
descShowCaptions: "\u6717\u8BFB\u65F6\u5728\u53F3\u4E0B\u89D2\u663E\u793A\u5F53\u524D\u53E5\u5B50\u7684\u5B57\u5E55\u6D6E\u5C42",
|
|
1705
|
+
showStatusBarLabel: "\u72B6\u6001\u6761",
|
|
1706
|
+
descShowStatusBar: "\u5728\u8F93\u5165\u6846\u4E0A\u65B9\u663E\u793A\u8BED\u97F3\u72B6\u6001\u6761\uFF08\u6CE2\u5F62\u3001\u8BC6\u522B\u6587\u5B57\u3001\u8BA1\u65F6\u3001\u63D0\u793A\u3001\u9000\u51FA\uFF09\uFF1B\u5173\u95ED\u540E\u72B6\u6001\u53EA\u5728\u9EA6\u514B\u98CE\u6309\u94AE\u4E0A\u663E\u793A",
|
|
1696
1707
|
descWakeWord: "\u5524\u9192\u8BCD\uFF08\u9ED8\u8BA4\u5173\uFF1B\u5982\u300C\u4F60\u597D\u5C0FD\u300D\uFF09\uFF1A\u8BF4\u51FA\u8BCD\u5934\u624D\u8FDB\u5165\u8BC6\u522B\uFF0C\u907F\u514D\u8BEF\u89E6\u3002\u53EF\u4E0E\u547D\u4EE4\u8FDE\u8BF4\uFF08\u300C\u4F60\u597D\u5C0FD\uFF0C\u5E2E\u6211\u67E5\u5929\u6C14\u300D\u2014\u2014\u8BCD\u5934\u4F1A\u81EA\u52A8\u5265\u6389\u3001\u4E0D\u8FDB\u6D88\u606F\uFF09\uFF1B\u6BCF\u53E5\u65AD\u53E5\u6216\u6253\u65AD\u540E\u9700\u91CD\u8BF4\uFF1B\u4EC5 toggle \u6A21\u5F0F\u751F\u6548\uFF08hold / \u624B\u52A8\u6253\u65AD\u4E0B\u4E0D\u751F\u6548\uFF1Bdetect \u81EA\u52A8\u63A2\u6D4B\u672A\u751F\u6548\u3001\u56DE\u843D manual \u65F6\u540C\u6837\u4E0D\u751F\u6548\u2014\u2014Safari \u7B49\u65E0\u539F\u751F\u56DE\u58F0\u6D88\u9664\u7684\u673A\u5668\u4F1A\u9ED8\u8BA4\u843D\u5230\u8FD9\u4E00\u6863\uFF09\uFF1B\u6717\u8BFB\u671F\u8BF4\u5524\u9192\u8BCD\u4E0D\u89E6\u53D1\uFF08\u6253\u65AD\u4ECD\u6309 VAD \u5F00\u53E3\u5373\u6253\u65AD\uFF09\u3002\u5339\u914D\u5E26\u5BB9\u9519\uFF08\u540C\u97F3\u5B57 / \u524D\u5BFC\u8BED\u6C14\u8BCD\uFF09\uFF0C\u5EFA\u8BAE 3-4 \u5B57\uFF1B\u975E\u4E13\u7528 KWS \u5F15\u64CE\uFF0C\u5608\u6742\u73AF\u5883\u53EF\u80FD\u5EF6\u8FDF\u6216\u8BEF\u6FC0\u6D3B",
|
|
1697
1708
|
wakePlaceholder: "\u5982\uFF1A\u4F60\u597D\u5C0FD",
|
|
1698
1709
|
settingsCardDesc: "\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / \u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u9759\u97F3\u505C\u987F / \u7A7A\u95F2\u8D85\u65F6 / \u6A21\u578B\u955C\u50CF / \u81EA\u52A8\u53D1\u9001 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u9006\u6587\u672C\u5F52\u4E00\u5316 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519",
|
|
1699
|
-
settingsEffectiveNote: "\u751F\u6548\u65F6\u673A\u5206\u56DB\u6863\uFF1A\u2460 \u5373\u65F6\u2014\u2014\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / Kokoro \u6A21\u578B\u7CBE\u5EA6\uFF08\u5DF2\u7F13\u5B58\u5219\u5373\u65F6\uFF0C\u5426\u5219\u4E0B\u6B21\u4E0B\u8F7D\uFF09/ \u53E3\u8BED\u5316\u63D0\u793A\u8BCD\uFF08\u5BF9\u540E\u7EED\u56DE\u590D\u751F\u6548\uFF09/ \u6A21\u578B\u955C\u50CF\uFF08\u4E0B\u6B21\u4E0B\u8F7D\u5C1D\u8BD5\u5373\u751F\u6548\uFF09\uFF1B\u2461 \u4E0B\u6B21\u8BC6\u522B\u65F6\u2014\u2014\u5B9A\u7A3F\u91CD\u8BD1\uFF08SenseVoice\uFF09/ \u9006\u6587\u672C\u5F52\u4E00\u5316\uFF1B\u2462 \u4E0B\u4E00\u6BB5\u8BDD\u2014\u2014\u9759\u97F3\u5224\u5B9A\u65F6\u957F\uFF08\u65AD\u53E5\u7AEF\u70B9\uFF1B\u53D1\u9001\u7B49\u5F85\u56FA\u5B9A 1.2 \u79D2\u4E0D\u53D7\u5F71\u54CD\uFF09\uFF1B\u2463 \u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u2014\u2014\u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u5FEB\u6377\u952E / \u81EA\u52A8\u53D1\u9001 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519 / \u7A7A\u95F2\u65F6\u957F\u3002\u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u624D\u751F\u6548\u7684\u9879\u4F1A\u5217\u5728\u5361\u7247\u9876\u90E8\uFF08\u542B\u5F53\u524D\u751F\u6548\u503C\uFF09\u3002",
|
|
1710
|
+
settingsEffectiveNote: "\u751F\u6548\u65F6\u673A\u5206\u56DB\u6863\uFF1A\u2460 \u5373\u65F6\u2014\u2014\u6717\u8BFB\u5F15\u64CE / \u97F3\u8272 / \u8BED\u901F / Kokoro \u6A21\u578B\u7CBE\u5EA6\uFF08\u5DF2\u7F13\u5B58\u5219\u5373\u65F6\uFF0C\u5426\u5219\u4E0B\u6B21\u4E0B\u8F7D\uFF09/ \u53E3\u8BED\u5316\u63D0\u793A\u8BCD\uFF08\u5BF9\u540E\u7EED\u56DE\u590D\u751F\u6548\uFF09/ \u6717\u8BFB\u56DE\u590D / \u72B6\u6001\u6761 / \u5B57\u5E55\u6D6E\u5C42 / \u6A21\u578B\u955C\u50CF\uFF08\u4E0B\u6B21\u4E0B\u8F7D\u5C1D\u8BD5\u5373\u751F\u6548\uFF09\uFF1B\u2461 \u4E0B\u6B21\u8BC6\u522B\u65F6\u2014\u2014\u5B9A\u7A3F\u91CD\u8BD1\uFF08SenseVoice\uFF09/ \u9006\u6587\u672C\u5F52\u4E00\u5316\uFF1B\u2462 \u4E0B\u4E00\u6BB5\u8BDD\u2014\u2014\u9759\u97F3\u5224\u5B9A\u65F6\u957F\uFF08\u65AD\u53E5\u7AEF\u70B9\uFF1B\u53D1\u9001\u7B49\u5F85\u56FA\u5B9A 1.2 \u79D2\u4E0D\u53D7\u5F71\u54CD\uFF09\uFF1B\u2463 \u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u2014\u2014\u6253\u65AD\u7075\u654F\u5EA6 / \u6253\u65AD\u65B9\u5F0F / \u56DE\u58F0\u95E8\u63A7 / \u5FEB\u6377\u952E / \u81EA\u52A8\u53D1\u9001 / \u81EA\u52A8\u6062\u590D / \u4EA4\u4E92\u6A21\u5F0F / \u5524\u9192\u8BCD / \u5DE5\u5177\u63D0\u793A\u97F3 / \u5B57\u5E55\u5B57\u53F7 / \u5B57\u5E55\u5BBD\u5EA6 / \u77ED\u5E94\u7B54\u8BA9\u4F4D / \u8BA9\u4F4D\u7A97\u53E3 / \u6253\u65AD\u8BED\u97F3\u62A2\u6551 / LLM \u7EA0\u9519 / \u7A7A\u95F2\u65F6\u957F\u3002\u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u624D\u751F\u6548\u7684\u9879\u4F1A\u5217\u5728\u5361\u7247\u9876\u90E8\uFF08\u542B\u5F53\u524D\u751F\u6548\u503C\uFF09\u3002",
|
|
1700
1711
|
effectivePending: "\u6709 {count} \u9879\u4FEE\u6539\u5C06\u5728\u4E0B\u6B21\u8FDB\u5165\u8BED\u97F3\u6A21\u5F0F\u65F6\u751F\u6548\uFF1A{items}",
|
|
1701
1712
|
valueOn: "\u5F00",
|
|
1702
1713
|
valueOff: "\u5173",
|
|
@@ -1950,13 +1961,24 @@ var en = {
|
|
|
1950
1961
|
descBargeInSalvage: "When you speak to interrupt while the agent is reading aloud, keep what you said from speech onset to break confirmation and merge it into recognition (fixes swallowed break-in speech; off = discard pre-break audio; recommended off only on speakers without echo cancellation)",
|
|
1951
1962
|
descLlmCorrect: "Before sending, run one LLM pass over the whole transcribed text (typos/homophones/punctuation only, meaning preserved; requires a default model configured in the host \u2014 otherwise the original text is sent as-is). On = one extra correction round trip per message: usually under 1 second, at most ~10 seconds; at most 10 times per minute \u2014 when voice mode is off or the limit is hit, the original text is sent. Failed or abnormal output also falls back to the original text",
|
|
1952
1963
|
descYieldMs: "How long (ms) to drop frames after a yield trigger (500-3000, default 1500; within the window the existing hardBreak takes over if the user really wants to speak; auto-resume after the window expires). Hold-to-talk mode only, during playback",
|
|
1953
|
-
descMode: "Interaction mode (toggle: continuous listen + auto-send / hold: press to talk)",
|
|
1964
|
+
descMode: "Interaction mode (toggle: continuous listen + auto-send / hold: press to talk / once: one utterance, then exit after the reply is read aloud)",
|
|
1954
1965
|
modeToggle: "Continuous listening",
|
|
1955
1966
|
modeHold: "Hold to talk",
|
|
1967
|
+
modeOnce: "One-shot",
|
|
1968
|
+
stopReading: "Stop reading",
|
|
1969
|
+
readAloudLabel: "Read replies",
|
|
1970
|
+
readAloudVoice: "Voice mode",
|
|
1971
|
+
readAloudAlways: "Always",
|
|
1972
|
+
readAloudOff: "Off",
|
|
1973
|
+
descReadAloud: "Voice mode = read replies only in voice mode (default); Always = read every reply in the current session, typed ones included; Off = never read aloud",
|
|
1974
|
+
showCaptionsLabel: "Caption overlay",
|
|
1975
|
+
descShowCaptions: "Show a floating caption of the current sentence while reading aloud",
|
|
1976
|
+
showStatusBarLabel: "Status bar",
|
|
1977
|
+
descShowStatusBar: "Show the voice status bar above the composer (waveform, transcript, timer, notices, exit); when off, state shows only on the mic button",
|
|
1956
1978
|
descWakeWord: 'Wake word (default off; e.g. "Hey D"): recognition starts only after you say it, to avoid accidental triggers. You may say it together with your command ("Hey D, check the weather" \u2014 the wake word is stripped and never sent); it must be repeated after each utterance split or barge-in; toggle mode only (inactive in hold / manual barge-in \u2014 and equally inactive when the detect probe fails and falls back to manual, the default on machines without native echo cancellation such as Safari); saying it while the agent is reading does not trigger (barge-in stays VAD-based). Fault-tolerant matching (homophones / leading fillers); 3-4 characters recommended; not a dedicated KWS engine \u2014 noisy environments may delay or falsely trigger',
|
|
1957
1979
|
wakePlaceholder: "e.g. Hey D",
|
|
1958
1980
|
settingsCardDesc: "Engine / voice / rate / interrupt / barge-in / echo gate / silence / idle / model host / auto-send / auto-resume / mode / wake word / tool beep / ITN / caption font / caption width / yielding / yield window / barge-in salvage / LLM correction",
|
|
1959
|
-
settingsEffectiveNote: "When settings apply, in four tiers: \u2460 immediately \u2014 engine / voice / rate / Kokoro model precision (immediate when cached, else next download) / spoken format (applies to later replies) / model mirror (next download attempt); \u2461 next recognition \u2014 finalization re-transcription (SenseVoice) / ITN; \u2462 next utterance \u2014 silence threshold (endpoint; the send wait stays a fixed 1.2s); \u2463 next time you enter voice mode \u2014 interrupt sensitivity / barge-in mode / echo gate / shortcut / auto-send / auto-resume / interaction mode / wake word / tool beep / caption font / caption width / backchannel yielding / yield window / barge-in salvage / LLM correction / idle timeout. Items that take effect next time you enter voice mode are listed at the top of this card with their current effective values.",
|
|
1981
|
+
settingsEffectiveNote: "When settings apply, in four tiers: \u2460 immediately \u2014 engine / voice / rate / Kokoro model precision (immediate when cached, else next download) / spoken format (applies to later replies) / read replies / status bar / caption overlay / model mirror (next download attempt); \u2461 next recognition \u2014 finalization re-transcription (SenseVoice) / ITN; \u2462 next utterance \u2014 silence threshold (endpoint; the send wait stays a fixed 1.2s); \u2463 next time you enter voice mode \u2014 interrupt sensitivity / barge-in mode / echo gate / shortcut / auto-send / auto-resume / interaction mode / wake word / tool beep / caption font / caption width / backchannel yielding / yield window / barge-in salvage / LLM correction / idle timeout. Items that take effect next time you enter voice mode are listed at the top of this card with their current effective values.",
|
|
1960
1982
|
effectivePending: "{count} change(s) will apply next time you enter voice mode: {items}",
|
|
1961
1983
|
valueOn: "On",
|
|
1962
1984
|
valueOff: "Off",
|
|
@@ -2191,6 +2213,22 @@ function shouldWritePartial(state) {
|
|
|
2191
2213
|
return state !== "wake";
|
|
2192
2214
|
}
|
|
2193
2215
|
|
|
2216
|
+
// src/mic-gesture.ts
|
|
2217
|
+
function isEditingShortcut(combo, mac) {
|
|
2218
|
+
const primary = mac ? combo.meta && !combo.ctrl : combo.ctrl && !combo.meta;
|
|
2219
|
+
return primary && !combo.alt && combo.key.length === 1 && "acvxzy".includes(combo.key);
|
|
2220
|
+
}
|
|
2221
|
+
function takeToggleSlot(history, now) {
|
|
2222
|
+
while (history.length > 0 && now - history[0] >= 2e3) history.shift();
|
|
2223
|
+
if (history.length >= 2) return false;
|
|
2224
|
+
if (history.length > 0 && now - history[history.length - 1] < 250) return false;
|
|
2225
|
+
history.push(now);
|
|
2226
|
+
return true;
|
|
2227
|
+
}
|
|
2228
|
+
function onceFinished(o, running, ttsDrained, playing) {
|
|
2229
|
+
return o.sawRun && !running && ttsDrained && !playing;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2194
2232
|
// src/runtime-boot.ts
|
|
2195
2233
|
var runtimeBoot = null;
|
|
2196
2234
|
function setRuntimeBoot(boot) {
|
|
@@ -2895,7 +2933,7 @@ var NEXT_ENTRY_FIELDS = [
|
|
|
2895
2933
|
{ key: "echoGateDb", label: "echoGateDbLabel", fmt: (v) => `${v} ${t("unitDb")}` },
|
|
2896
2934
|
{ key: "autoSend", label: "autoSendLabel", fmt: (v) => v ? t("valueOn") : t("valueOff") },
|
|
2897
2935
|
{ key: "autoResume", label: "autoResumeLabel", fmt: (v) => v ? t("valueOn") : t("valueOff") },
|
|
2898
|
-
{ key: "mode", label: "modeLabel", fmt: (v) => t(v === "hold" ? "modeHold" : "modeToggle") },
|
|
2936
|
+
{ key: "mode", label: "modeLabel", fmt: (v) => t(v === "hold" ? "modeHold" : v === "once" ? "modeOnce" : "modeToggle") },
|
|
2899
2937
|
{ key: "wakeWord", label: "wakeWordLabel", fmt: (v) => v ? t("valueQuoted").replace("{value}", String(v)) : t("valueOff") },
|
|
2900
2938
|
{ key: "toolBeep", label: "toolBeepLabel", fmt: (v) => v ? t("valueOn") : t("valueOff") },
|
|
2901
2939
|
{ key: "captionFontSize", label: "captionFontSizeLabel", fmt: (v) => t(v === 1 ? "captionSizeM" : v === 2 ? "captionSizeL" : v === 3 ? "captionSizeXL" : "captionSizeS") },
|
|
@@ -3270,7 +3308,8 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3270
3308
|
value: value.mode,
|
|
3271
3309
|
options: [
|
|
3272
3310
|
{ v: "toggle", label: t("modeToggle") },
|
|
3273
|
-
{ v: "hold", label: t("modeHold") }
|
|
3311
|
+
{ v: "hold", label: t("modeHold") },
|
|
3312
|
+
{ v: "once", label: t("modeOnce") }
|
|
3274
3313
|
]
|
|
3275
3314
|
}
|
|
3276
3315
|
) }),
|
|
@@ -3278,6 +3317,21 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3278
3317
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "wakeWord", desc: t("descWakeWord"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextField, { score: scope, field: "wakeWord", value: value.wakeWord ?? "", placeholder: t("wakePlaceholder") }) }),
|
|
3279
3318
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "toolBeep", desc: t("descToolBeep"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.toolBeep), onChange: (e) => void scope.set("toolBeep", e.target.checked) }) }),
|
|
3280
3319
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "autoSend", desc: t("descAutoSend"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.autoSend), onChange: (e) => void scope.set("autoSend", e.target.checked) }) }),
|
|
3320
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "readAloud", desc: t("descReadAloud"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3321
|
+
SegGroup,
|
|
3322
|
+
{
|
|
3323
|
+
score: scope,
|
|
3324
|
+
field: "readAloud",
|
|
3325
|
+
value: value.readAloud ?? "voice",
|
|
3326
|
+
options: [
|
|
3327
|
+
{ v: "voice", label: t("readAloudVoice") },
|
|
3328
|
+
{ v: "always", label: t("readAloudAlways") },
|
|
3329
|
+
{ v: "off", label: t("readAloudOff") }
|
|
3330
|
+
]
|
|
3331
|
+
}
|
|
3332
|
+
) }),
|
|
3333
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "showStatusBar", desc: t("descShowStatusBar"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: value.showStatusBar !== false, onChange: (e) => void scope.set("showStatusBar", e.target.checked) }) }),
|
|
3334
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "showCaptions", desc: t("descShowCaptions"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: value.showCaptions !== false, onChange: (e) => void scope.set("showCaptions", e.target.checked) }) }),
|
|
3281
3335
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "autoResume", desc: t("descAutoResume"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked: Boolean(value.autoResume), onChange: (e) => void scope.set("autoResume", e.target.checked) }) }),
|
|
3282
3336
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Row, { name: "captionFontSize", desc: t("descCaptionFontSize"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3283
3337
|
SegGroup,
|
|
@@ -3409,7 +3463,7 @@ function telemetryDeltas(tel) {
|
|
|
3409
3463
|
}
|
|
3410
3464
|
return out;
|
|
3411
3465
|
}
|
|
3412
|
-
var BUILD_TAG = "
|
|
3466
|
+
var BUILD_TAG = "8c0368a";
|
|
3413
3467
|
var TELEMETRY_FLAG = "dsh-voice-mode.telemetry";
|
|
3414
3468
|
var telemetryEnabled = typeof localStorage !== "undefined" && localStorage.getItem(TELEMETRY_FLAG) === "1";
|
|
3415
3469
|
console.log("[dsh-voice] build=" + BUILD_TAG);
|
|
@@ -3446,20 +3500,30 @@ var ECHO_TAIL_MS = 400;
|
|
|
3446
3500
|
var HOLD_CLEAR_FRAMES = 2;
|
|
3447
3501
|
var WAVE_BARS = 14;
|
|
3448
3502
|
var BASE_PATH2 = "/voice-mode";
|
|
3449
|
-
function
|
|
3503
|
+
function displaySettings(c) {
|
|
3504
|
+
return {
|
|
3505
|
+
readAloud: c.readAloud === "always" || c.readAloud === "off" ? c.readAloud : "voice",
|
|
3506
|
+
showCaptions: c.showCaptions !== false,
|
|
3507
|
+
showStatusBar: c.showStatusBar !== false
|
|
3508
|
+
};
|
|
3509
|
+
}
|
|
3510
|
+
var STOP_READING_LINE = Number.MAX_SAFE_INTEGER;
|
|
3511
|
+
function getTabId(fresh = false) {
|
|
3512
|
+
const KEY = "dshvm-tabId";
|
|
3513
|
+
const make = () => typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
3450
3514
|
try {
|
|
3451
|
-
|
|
3452
|
-
let id = sessionStorage.getItem(KEY);
|
|
3515
|
+
let id = fresh ? null : sessionStorage.getItem(KEY);
|
|
3453
3516
|
if (!id) {
|
|
3454
|
-
id =
|
|
3517
|
+
id = make();
|
|
3455
3518
|
sessionStorage.setItem(KEY, id);
|
|
3456
3519
|
}
|
|
3457
3520
|
return id;
|
|
3458
3521
|
} catch {
|
|
3459
|
-
return
|
|
3522
|
+
return make();
|
|
3460
3523
|
}
|
|
3461
3524
|
}
|
|
3462
3525
|
var TAB_ID = getTabId();
|
|
3526
|
+
var BUS_GEN_KEY = "__dshvmBusGen";
|
|
3463
3527
|
function parseShortcut(s) {
|
|
3464
3528
|
const parts = (s || "").split("+");
|
|
3465
3529
|
const mods = { ctrl: false, shift: false, alt: false, meta: false };
|
|
@@ -3501,6 +3565,55 @@ function apply(ctx) {
|
|
|
3501
3565
|
document.addEventListener("pointerdown", resumeAudio, { passive: true });
|
|
3502
3566
|
document.addEventListener("keydown", resumeAudio, { passive: true });
|
|
3503
3567
|
}
|
|
3568
|
+
const activity = { declared: false, mounted: 0, listeners: /* @__PURE__ */ new Set() };
|
|
3569
|
+
const activityChanged = () => activity.listeners.forEach((fn) => fn());
|
|
3570
|
+
const ActivityMic = (props) => {
|
|
3571
|
+
(0, import_react3.useEffect)(() => {
|
|
3572
|
+
activity.mounted++;
|
|
3573
|
+
activityChanged();
|
|
3574
|
+
return () => {
|
|
3575
|
+
activity.mounted--;
|
|
3576
|
+
activityChanged();
|
|
3577
|
+
};
|
|
3578
|
+
}, []);
|
|
3579
|
+
return React.createElement(MicButton, props);
|
|
3580
|
+
};
|
|
3581
|
+
const RightMic = (props) => {
|
|
3582
|
+
const [show, setShow] = (0, import_react3.useState)(() => !activity.declared);
|
|
3583
|
+
(0, import_react3.useEffect)(() => {
|
|
3584
|
+
let timer;
|
|
3585
|
+
const evaluate = () => {
|
|
3586
|
+
clearTimeout(timer);
|
|
3587
|
+
if (!activity.declared) setShow(true);
|
|
3588
|
+
else if (activity.mounted > 0) setShow(false);
|
|
3589
|
+
else timer = setTimeout(() => setShow(!activity.declared || activity.mounted === 0), 1500);
|
|
3590
|
+
};
|
|
3591
|
+
activity.listeners.add(evaluate);
|
|
3592
|
+
evaluate();
|
|
3593
|
+
return () => {
|
|
3594
|
+
activity.listeners.delete(evaluate);
|
|
3595
|
+
clearTimeout(timer);
|
|
3596
|
+
};
|
|
3597
|
+
}, []);
|
|
3598
|
+
return show ? React.createElement(MicButton, props) : null;
|
|
3599
|
+
};
|
|
3600
|
+
ctx.slots.inject("conversation.input.activity", () => {
|
|
3601
|
+
activity.declared = true;
|
|
3602
|
+
activityChanged();
|
|
3603
|
+
const dispose = ctx.slots.register(
|
|
3604
|
+
{
|
|
3605
|
+
name: "conversation.input.activity",
|
|
3606
|
+
id: "voice-mode",
|
|
3607
|
+
inject: () => ({ bus, scope })
|
|
3608
|
+
},
|
|
3609
|
+
ActivityMic
|
|
3610
|
+
);
|
|
3611
|
+
return () => {
|
|
3612
|
+
activity.declared = false;
|
|
3613
|
+
activityChanged();
|
|
3614
|
+
dispose?.();
|
|
3615
|
+
};
|
|
3616
|
+
});
|
|
3504
3617
|
ctx.slots.inject(
|
|
3505
3618
|
"conversation.input.right",
|
|
3506
3619
|
() => ctx.slots.register(
|
|
@@ -3508,9 +3621,9 @@ function apply(ctx) {
|
|
|
3508
3621
|
name: "conversation.input.right",
|
|
3509
3622
|
id: "voice-mode",
|
|
3510
3623
|
order: 80,
|
|
3511
|
-
inject: () => ({ bus })
|
|
3624
|
+
inject: () => ({ bus, scope })
|
|
3512
3625
|
},
|
|
3513
|
-
|
|
3626
|
+
RightMic
|
|
3514
3627
|
)
|
|
3515
3628
|
);
|
|
3516
3629
|
ctx.slots.inject(
|
|
@@ -3575,6 +3688,8 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3575
3688
|
let fallback = false;
|
|
3576
3689
|
let ctx = null;
|
|
3577
3690
|
let duckGain = null;
|
|
3691
|
+
let analyser = null;
|
|
3692
|
+
let levelBuf = null;
|
|
3578
3693
|
let nextEndAt = 0;
|
|
3579
3694
|
const activeSrcs = /* @__PURE__ */ new Set();
|
|
3580
3695
|
let decoding = false;
|
|
@@ -3589,7 +3704,15 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3589
3704
|
ctx = new AC();
|
|
3590
3705
|
duckGain = ctx.createGain();
|
|
3591
3706
|
duckGain.gain.value = 1;
|
|
3592
|
-
|
|
3707
|
+
try {
|
|
3708
|
+
analyser = ctx.createAnalyser();
|
|
3709
|
+
analyser.fftSize = 256;
|
|
3710
|
+
duckGain.connect(analyser);
|
|
3711
|
+
analyser.connect(ctx.destination);
|
|
3712
|
+
} catch {
|
|
3713
|
+
analyser = null;
|
|
3714
|
+
duckGain.connect(ctx.destination);
|
|
3715
|
+
}
|
|
3593
3716
|
void ctx.resume?.();
|
|
3594
3717
|
} catch {
|
|
3595
3718
|
ctx = null;
|
|
@@ -3721,11 +3844,33 @@ function createAudioEngine(setUi, onPlayed, onPlaybackRef, onAllPlayed) {
|
|
|
3721
3844
|
const now = ctx.currentTime;
|
|
3722
3845
|
duckGain.gain.cancelScheduledValues(now);
|
|
3723
3846
|
duckGain.gain.setTargetAtTime(1, now, 0.035);
|
|
3847
|
+
},
|
|
3848
|
+
level() {
|
|
3849
|
+
if (!analyser) return 0;
|
|
3850
|
+
if (!levelBuf || levelBuf.length !== analyser.fftSize) levelBuf = new Float32Array(analyser.fftSize);
|
|
3851
|
+
analyser.getFloatTimeDomainData(levelBuf);
|
|
3852
|
+
let sum = 0;
|
|
3853
|
+
for (const v of levelBuf) sum += v * v;
|
|
3854
|
+
return Math.min(1, Math.sqrt(sum / levelBuf.length) / 0.2);
|
|
3724
3855
|
}
|
|
3725
3856
|
};
|
|
3726
3857
|
}
|
|
3727
3858
|
function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
3728
3859
|
let activeSessionId = null;
|
|
3860
|
+
let focusedSessionId = null;
|
|
3861
|
+
let focusOwnerTab = null;
|
|
3862
|
+
let voiceActive = null;
|
|
3863
|
+
let voiceOwnerTab = null;
|
|
3864
|
+
const busGen = globalThis[BUS_GEN_KEY] = (globalThis[BUS_GEN_KEY] ?? 0) + 1;
|
|
3865
|
+
const postFocus = (sessionId) => {
|
|
3866
|
+
void fetch(`${location.origin}${basePath}/focus`, {
|
|
3867
|
+
method: "POST",
|
|
3868
|
+
headers: { "content-type": "application/json" },
|
|
3869
|
+
body: JSON.stringify({ sessionId, tabId: TAB_ID }),
|
|
3870
|
+
signal: AbortSignal.timeout(3e3)
|
|
3871
|
+
}).catch(() => {
|
|
3872
|
+
});
|
|
3873
|
+
};
|
|
3729
3874
|
const DEFAULT_BOOT = {
|
|
3730
3875
|
basePath: BASE_PATH2,
|
|
3731
3876
|
silenceMs: 1500,
|
|
@@ -3734,6 +3879,9 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3734
3879
|
autoSend: true,
|
|
3735
3880
|
autoResume: false,
|
|
3736
3881
|
mode: "toggle",
|
|
3882
|
+
readAloud: "voice",
|
|
3883
|
+
showCaptions: true,
|
|
3884
|
+
showStatusBar: true,
|
|
3737
3885
|
// 批 7O(ADR-0006):默认 detect(与 src/index.ts VOICE_SETTINGS_DEFAULTS 对齐)。
|
|
3738
3886
|
bargeInMode: "detect",
|
|
3739
3887
|
echoGateDb: 6,
|
|
@@ -3947,6 +4095,33 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3947
4095
|
ui.sseDown = false;
|
|
3948
4096
|
notify();
|
|
3949
4097
|
}
|
|
4098
|
+
if (focusedSessionId && (typeof document === "undefined" || document.visibilityState === "visible")) {
|
|
4099
|
+
postFocus(focusedSessionId);
|
|
4100
|
+
}
|
|
4101
|
+
});
|
|
4102
|
+
source.addEventListener("replaced", () => {
|
|
4103
|
+
source?.close();
|
|
4104
|
+
source = null;
|
|
4105
|
+
if (globalThis[BUS_GEN_KEY] !== busGen) {
|
|
4106
|
+
ui.sseDown = true;
|
|
4107
|
+
notify();
|
|
4108
|
+
return;
|
|
4109
|
+
}
|
|
4110
|
+
TAB_ID = getTabId(true);
|
|
4111
|
+
connect();
|
|
4112
|
+
});
|
|
4113
|
+
source.addEventListener("display", (e) => {
|
|
4114
|
+
try {
|
|
4115
|
+
ui.boot = { ...ui.boot, ...displaySettings(JSON.parse(e.data)) };
|
|
4116
|
+
notify();
|
|
4117
|
+
} catch {
|
|
4118
|
+
}
|
|
4119
|
+
});
|
|
4120
|
+
source.addEventListener("focus", (e) => {
|
|
4121
|
+
try {
|
|
4122
|
+
focusOwnerTab = JSON.parse(e.data).tabId ?? null;
|
|
4123
|
+
} catch {
|
|
4124
|
+
}
|
|
3950
4125
|
});
|
|
3951
4126
|
source.addEventListener("error", () => {
|
|
3952
4127
|
if (!ui.sseDown) {
|
|
@@ -3959,6 +4134,8 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3959
4134
|
const data = JSON.parse(e.data);
|
|
3960
4135
|
const active = data.active ?? null;
|
|
3961
4136
|
const ownerTabId = data.ownerTabId ?? null;
|
|
4137
|
+
voiceActive = active;
|
|
4138
|
+
voiceOwnerTab = ownerTabId;
|
|
3962
4139
|
const preempted = active !== activeSessionId || ownerTabId !== null && activeSessionId !== null && ownerTabId !== TAB_ID;
|
|
3963
4140
|
if (activeSessionId !== null && preempted) {
|
|
3964
4141
|
const prev = activeSessionId;
|
|
@@ -3987,8 +4164,22 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
3987
4164
|
source.addEventListener("turn", (e) => {
|
|
3988
4165
|
try {
|
|
3989
4166
|
const ev = JSON.parse(e.data);
|
|
4167
|
+
if (ev.state === "agent-speaking" && ev.sessionId && rejectSeqUpTo.get(ev.sessionId) === STOP_READING_LINE && !stopUntilRun.has(ev.sessionId)) {
|
|
4168
|
+
rejectSeqUpTo.delete(ev.sessionId);
|
|
4169
|
+
}
|
|
3990
4170
|
if (ev.sessionId === activeSessionId && ev.state) {
|
|
3991
4171
|
ui.turn = ev.state;
|
|
4172
|
+
if (ev.state === "agent-speaking") ui.ttsDrained = false;
|
|
4173
|
+
notify();
|
|
4174
|
+
}
|
|
4175
|
+
} catch {
|
|
4176
|
+
}
|
|
4177
|
+
});
|
|
4178
|
+
source.addEventListener("tts-idle", (e) => {
|
|
4179
|
+
try {
|
|
4180
|
+
const ev = JSON.parse(e.data);
|
|
4181
|
+
if (ev.sessionId === activeSessionId && !ui.ttsDrained) {
|
|
4182
|
+
ui.ttsDrained = true;
|
|
3992
4183
|
notify();
|
|
3993
4184
|
}
|
|
3994
4185
|
} catch {
|
|
@@ -4074,13 +4265,21 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4074
4265
|
};
|
|
4075
4266
|
connect();
|
|
4076
4267
|
const rejectSeqUpTo = /* @__PURE__ */ new Map();
|
|
4268
|
+
const stopUntilRun = /* @__PURE__ */ new Set();
|
|
4077
4269
|
const lastFinalSeq = /* @__PURE__ */ new Map();
|
|
4078
4270
|
let curSentenceId = null;
|
|
4079
4271
|
let curChunks = [];
|
|
4080
4272
|
let curBytes = 0;
|
|
4081
4273
|
let curChunkCount = 0;
|
|
4082
4274
|
audioListeners.add((frame) => {
|
|
4083
|
-
if (frame.sessionId
|
|
4275
|
+
if (frame.sessionId === activeSessionId && ui.ttsDrained) {
|
|
4276
|
+
ui.ttsDrained = false;
|
|
4277
|
+
notify();
|
|
4278
|
+
}
|
|
4279
|
+
const readAloud = ui.boot.readAloud ?? "voice";
|
|
4280
|
+
if (readAloud === "off") return;
|
|
4281
|
+
const alwaysHere = readAloud === "always" && frame.sessionId === focusedSessionId && focusOwnerTab === TAB_ID && !(voiceActive === frame.sessionId && voiceOwnerTab !== null && voiceOwnerTab !== TAB_ID);
|
|
4282
|
+
if (frame.sessionId !== activeSessionId && !alwaysHere) return;
|
|
4084
4283
|
const rejectLine = rejectSeqUpTo.get(frame.sessionId);
|
|
4085
4284
|
if (rejectLine !== void 0 && frame.sentenceId <= rejectLine) return;
|
|
4086
4285
|
if (backchannelHoldUntil && Date.now() < backchannelHoldUntil) {
|
|
@@ -4140,7 +4339,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4140
4339
|
curChunkCount += 1;
|
|
4141
4340
|
});
|
|
4142
4341
|
const doSkipAudio = (sidArg) => {
|
|
4143
|
-
const sid = sidArg ?? activeSessionId;
|
|
4342
|
+
const sid = sidArg ?? activeSessionId ?? focusedSessionId;
|
|
4144
4343
|
if (sid) {
|
|
4145
4344
|
rejectSeqUpTo.set(sid, Math.max(lastFinalSeq.get(sid) ?? -1, curSentenceId ?? -1));
|
|
4146
4345
|
}
|
|
@@ -4265,6 +4464,38 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
|
|
|
4265
4464
|
resetTelemetry,
|
|
4266
4465
|
warmAudio() {
|
|
4267
4466
|
engine.warm();
|
|
4467
|
+
},
|
|
4468
|
+
playbackLevel() {
|
|
4469
|
+
return engine.level();
|
|
4470
|
+
},
|
|
4471
|
+
runStarted(sessionId) {
|
|
4472
|
+
if (rejectSeqUpTo.get(sessionId) === STOP_READING_LINE) rejectSeqUpTo.delete(sessionId);
|
|
4473
|
+
stopUntilRun.delete(sessionId);
|
|
4474
|
+
},
|
|
4475
|
+
setFocusedSession(sessionId) {
|
|
4476
|
+
if (sessionId === null) {
|
|
4477
|
+
if (focusedSessionId === null) return;
|
|
4478
|
+
focusedSessionId = null;
|
|
4479
|
+
if (focusOwnerTab === TAB_ID) postFocus(null);
|
|
4480
|
+
return;
|
|
4481
|
+
}
|
|
4482
|
+
focusedSessionId = sessionId;
|
|
4483
|
+
if (typeof document === "undefined" || document.visibilityState === "visible") postFocus(sessionId);
|
|
4484
|
+
},
|
|
4485
|
+
stopReading(untilNextRun = false) {
|
|
4486
|
+
const sid = activeSessionId ?? focusedSessionId;
|
|
4487
|
+
doSkipAudio(sid);
|
|
4488
|
+
if (!sid) return;
|
|
4489
|
+
rejectSeqUpTo.set(sid, STOP_READING_LINE);
|
|
4490
|
+
if (untilNextRun) stopUntilRun.add(sid);
|
|
4491
|
+
else stopUntilRun.delete(sid);
|
|
4492
|
+
void fetch(`${location.origin}${basePath}/cancel`, {
|
|
4493
|
+
method: "POST",
|
|
4494
|
+
headers: { "content-type": "application/json" },
|
|
4495
|
+
body: JSON.stringify({ sessionId: sid, keepAsr: true }),
|
|
4496
|
+
signal: AbortSignal.timeout(3e3)
|
|
4497
|
+
}).catch(() => {
|
|
4498
|
+
});
|
|
4268
4499
|
}
|
|
4269
4500
|
};
|
|
4270
4501
|
}
|
|
@@ -4291,12 +4522,124 @@ html.dshvm-holding, html.dshvm-holding * {
|
|
|
4291
4522
|
}
|
|
4292
4523
|
/* \u6279 3\uFF1A\u5B57\u5E55\u4E2D\u6587\u957F\u8BCD/URL \u6362\u884C\uFF08\u5916\u5C42 maxHeight:30vh + overflow:hidden \u63A7\u5236\u9AD8\u5EA6\u4E0D\u6EA2\u51FA\uFF09\u3002 */
|
|
4293
4524
|
.dshvm-caption { word-break: break-word; overflow-wrap: anywhere; }
|
|
4525
|
+
/* \u9EA6\u514B\u98CE\u6309\u94AE\uFF08PR #16 by dyguests\uFF09\uFF1A\u72B6\u6001\u5168\u5728\u6309\u94AE\u4E0A\u2014\u2014\u989C\u8272\u533A\u5206\u6A21\u5F0F\uFF0C\u7AD6\u6761\u8DDF\u968F\u7535\u5E73\uFF0C
|
|
4526
|
+
\u7B49\u5F85\u8F6C\u5708\u3001\u6536\u5C3E\u5BF9\u52FE\u3001\u53F3\u4E0A\u6A59\u70B9=\u68C0\u6D4B\u5230\u8BF4\u8BDD\u3001\u5DE6\u4E0A\u7EA2\u70B9=\u51FA\u9519\u3002\u989C\u8272\u8D70 dsw \u53D8\u91CF\uFF0C\u65E7\u5BBF\u4E3B\u65E0\u53D8\u91CF\u65F6\u7528\u515C\u5E95\u8272\u3002 */
|
|
4527
|
+
.dshvm-mic {
|
|
4528
|
+
position: relative; flex: none; width: 34px; height: 34px; padding: 0;
|
|
4529
|
+
display: grid; place-items: center; border: none; border-radius: 999px;
|
|
4530
|
+
background: transparent; color: var(--dsw-alias-label-secondary, #8b949e); cursor: pointer;
|
|
4531
|
+
transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
|
|
4532
|
+
touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
|
|
4533
|
+
}
|
|
4534
|
+
.dshvm-mic:hover { background: var(--dsw-alias-interactive-bg-hover, rgba(139,148,158,.14)); }
|
|
4535
|
+
.dshvm-mic:focus-visible { outline: 2px solid var(--dsw-alias-state-business-primary, #58a6ff); outline-offset: -2px; }
|
|
4536
|
+
.dshvm-mic svg { display: block; }
|
|
4537
|
+
.dshvm-mic[data-state="pending"] { --c: var(--dsw-alias-state-business-primary, #58a6ff); }
|
|
4538
|
+
.dshvm-mic[data-state="on"] { --c: var(--dsw-alias-state-success-primary, #2ea043); }
|
|
4539
|
+
.dshvm-mic[data-state="hold"] { --c: var(--dsw-alias-state-business-primary, #58a6ff); }
|
|
4540
|
+
.dshvm-mic[data-state="holding"] { --c: var(--dsw-alias-state-error-primary, #f85149); }
|
|
4541
|
+
.dshvm-mic[data-state="reading"] { --c: var(--dsw-alias-state-business-primary, #58a6ff); }
|
|
4542
|
+
.dshvm-mic[data-state="waiting"], .dshvm-mic[data-state="ending"] { --c: var(--dsw-alias-label-tertiary, #8b949e); }
|
|
4543
|
+
.dshvm-mic[data-state]:not([data-state="off"]) { color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); }
|
|
4544
|
+
.dshvm-mic[data-state="on"], .dshvm-mic[data-state="reading"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 10%, transparent); }
|
|
4545
|
+
.dshvm-mic[data-state]:not([data-state="off"]):hover { background: color-mix(in srgb, var(--c) 20%, transparent); }
|
|
4546
|
+
.dshvm-eq { display: inline-flex; align-items: center; justify-content: center; gap: 2px; width: 16px; height: 16px; pointer-events: none; }
|
|
4547
|
+
.dshvm-eq i { display: block; width: 3px; border-radius: 2px; background: currentColor; }
|
|
4548
|
+
.dshvm-eq-out { gap: 1.5px; }
|
|
4549
|
+
.dshvm-eq-out i { width: 2px; }
|
|
4550
|
+
.dshvm-mic-dot { position: absolute; top: 0; width: 7px; height: 7px; border-radius: 999px; pointer-events: none;
|
|
4551
|
+
box-shadow: 0 0 0 2px var(--dsw-specific-input-major, transparent); }
|
|
4552
|
+
.dshvm-mic-dot[data-kind="vad"] { right: 0; background: var(--dsw-alias-state-warn-primary, #d29922); }
|
|
4553
|
+
.dshvm-mic-dot[data-kind="error"] { left: 0; background: var(--dsw-alias-state-error-primary, #f85149); }
|
|
4554
|
+
.dshvm-mic-timer { position: absolute; left: 50%; top: calc(100% + 2px); transform: translateX(-50%); padding: 0 3px; border-radius: 4px;
|
|
4555
|
+
background: var(--dsw-specific-input-major, transparent); font-size: 9.5px; line-height: 12px; color: var(--dsw-alias-label-tertiary, #8b949e);
|
|
4556
|
+
font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none; }
|
|
4557
|
+
.dshvm-spin { animation: dshvm-spin 0.9s linear infinite; }
|
|
4558
|
+
.dshvm-menu { display: flex; flex-direction: column; gap: 2px; padding: 6px; border-radius: 10px;
|
|
4559
|
+
background: var(--dsw-alias-bg-layer-3, #fff); border: 1px solid var(--dsw-alias-border-l2, rgba(139,148,158,.35));
|
|
4560
|
+
box-shadow: 0 8px 24px rgba(15, 17, 21, 0.14); color: var(--dsw-alias-label-primary, inherit);
|
|
4561
|
+
font-family: inherit; font-size: 12px; animation: dshvm-fadein 0.12s ease; }
|
|
4562
|
+
.dshvm-menu-label { padding: 2px 8px 4px; font-size: 11px; color: var(--dsw-alias-label-tertiary, #8b949e); }
|
|
4563
|
+
.dshvm-menu-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 5px 8px;
|
|
4564
|
+
border: none; border-radius: 6px; background: transparent; color: inherit; cursor: pointer; font: inherit; font-size: 12px; text-align: left; }
|
|
4565
|
+
.dshvm-menu-item:hover, .dshvm-menu-item:focus-visible { background: var(--dsw-alias-interactive-bg-hover, rgba(139,148,158,.14)); outline: none; }
|
|
4566
|
+
.dshvm-menu-check { color: var(--dsw-alias-state-business-primary, #58a6ff); font-size: 11px; }
|
|
4567
|
+
.dshvm-menu-sep { height: 1px; margin: 4px 2px; background: var(--dsw-alias-border-l1, rgba(139,148,158,.25)); }
|
|
4568
|
+
@media (prefers-reduced-motion: reduce) { .dshvm-spin, .dshvm-menu { animation: none; } }
|
|
4294
4569
|
`;
|
|
4295
4570
|
document.head.appendChild(el);
|
|
4296
4571
|
}, []);
|
|
4297
4572
|
}
|
|
4573
|
+
var IS_MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent || "");
|
|
4574
|
+
var ONCE_SETTLE_MS = 1200;
|
|
4575
|
+
var ONCE_NO_START_MS = 3e4;
|
|
4576
|
+
var ONCE_STALL_MS = 1e4;
|
|
4577
|
+
function MicMenu({ scope, anchor, onClose }) {
|
|
4578
|
+
const [snap, setSnap] = (0, import_react3.useState)(() => scope.getSnapshot());
|
|
4579
|
+
(0, import_react3.useEffect)(() => scope.subscribe(() => setSnap({ ...scope.getSnapshot() })), [scope]);
|
|
4580
|
+
const menuRef = (0, import_react3.useRef)(null);
|
|
4581
|
+
(0, import_react3.useEffect)(() => {
|
|
4582
|
+
menuRef.current?.querySelector("button")?.focus();
|
|
4583
|
+
const onDown = (e) => {
|
|
4584
|
+
if (e.target instanceof Node && menuRef.current?.contains(e.target)) return;
|
|
4585
|
+
onClose(false);
|
|
4586
|
+
};
|
|
4587
|
+
const onKey = (e) => {
|
|
4588
|
+
if (e.key === "Escape") {
|
|
4589
|
+
e.preventDefault();
|
|
4590
|
+
onClose(true);
|
|
4591
|
+
return;
|
|
4592
|
+
}
|
|
4593
|
+
if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return;
|
|
4594
|
+
e.preventDefault();
|
|
4595
|
+
const items = Array.from(menuRef.current?.querySelectorAll("button") ?? []);
|
|
4596
|
+
const i = items.indexOf(document.activeElement);
|
|
4597
|
+
items[(i + (e.key === "ArrowDown" ? 1 : items.length - 1)) % items.length]?.focus();
|
|
4598
|
+
};
|
|
4599
|
+
document.addEventListener("pointerdown", onDown, true);
|
|
4600
|
+
document.addEventListener("keydown", onKey, true);
|
|
4601
|
+
return () => {
|
|
4602
|
+
document.removeEventListener("pointerdown", onDown, true);
|
|
4603
|
+
document.removeEventListener("keydown", onKey, true);
|
|
4604
|
+
};
|
|
4605
|
+
}, [onClose]);
|
|
4606
|
+
const v = snap.value ?? {};
|
|
4607
|
+
const width = 208;
|
|
4608
|
+
const r = anchor?.getBoundingClientRect();
|
|
4609
|
+
const below = !r || r.top < 340;
|
|
4610
|
+
const pos = {
|
|
4611
|
+
position: "fixed",
|
|
4612
|
+
zIndex: 9999,
|
|
4613
|
+
width,
|
|
4614
|
+
left: r ? Math.max(8, Math.min(window.innerWidth - width - 8, Math.round(r.right - width))) : 8,
|
|
4615
|
+
...below ? { top: r ? Math.round(r.bottom + 8) : 96 } : { bottom: Math.round(window.innerHeight - r.top + 8) }
|
|
4616
|
+
};
|
|
4617
|
+
const item = (role, checked, label, onPick) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", role, "aria-checked": checked, className: "dshvm-menu-item", onClick: onPick, children: [
|
|
4618
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: label }),
|
|
4619
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dshvm-menu-check", children: checked ? "\u2713" : "" })
|
|
4620
|
+
] }, label);
|
|
4621
|
+
const set = (field, value) => void scope.set(field, value);
|
|
4622
|
+
const mode = v.mode === "hold" || v.mode === "once" ? v.mode : "toggle";
|
|
4623
|
+
const read = v.readAloud === "always" || v.readAloud === "off" ? v.readAloud : "voice";
|
|
4624
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { ref: menuRef, className: "dshvm-menu", role: "menu", "aria-label": t("stateVoiceMode"), style: pos, children: [
|
|
4625
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshvm-menu-label", children: t("modeLabel") }),
|
|
4626
|
+
["toggle", "hold", "once"].map(
|
|
4627
|
+
(m) => item("menuitemradio", mode === m, t(m === "toggle" ? "modeToggle" : m === "hold" ? "modeHold" : "modeOnce"), () => set("mode", m))
|
|
4628
|
+
),
|
|
4629
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshvm-menu-sep" }),
|
|
4630
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshvm-menu-label", children: t("readAloudLabel") }),
|
|
4631
|
+
["voice", "always", "off"].map(
|
|
4632
|
+
(m) => item("menuitemradio", read === m, t(m === "voice" ? "readAloudVoice" : m === "always" ? "readAloudAlways" : "readAloudOff"), () => set("readAloud", m))
|
|
4633
|
+
),
|
|
4634
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dshvm-menu-sep" }),
|
|
4635
|
+
item("menuitemcheckbox", v.showCaptions !== false, t("showCaptionsLabel"), () => set("showCaptions", v.showCaptions === false)),
|
|
4636
|
+
item("menuitemcheckbox", v.showStatusBar !== false, t("showStatusBarLabel"), () => set("showStatusBar", v.showStatusBar === false)),
|
|
4637
|
+
item("menuitemcheckbox", v.autoSend !== false, t("autoSendLabel"), () => set("autoSend", v.autoSend === false))
|
|
4638
|
+
] });
|
|
4639
|
+
}
|
|
4298
4640
|
function MicButton({
|
|
4299
4641
|
bus,
|
|
4642
|
+
scope,
|
|
4300
4643
|
sessionId,
|
|
4301
4644
|
useSession,
|
|
4302
4645
|
useInput,
|
|
@@ -4321,6 +4664,10 @@ function MicButton({
|
|
|
4321
4664
|
const manualHoldRef = (0, import_react3.useRef)(false);
|
|
4322
4665
|
const breakRef = (0, import_react3.useRef)(null);
|
|
4323
4666
|
const pausedForHiddenRef = (0, import_react3.useRef)(false);
|
|
4667
|
+
const onceRef = (0, import_react3.useRef)(null);
|
|
4668
|
+
const [onceWaiting, setOnceWaiting] = (0, import_react3.useState)(false);
|
|
4669
|
+
const [onceEnding, setOnceEnding] = (0, import_react3.useState)(false);
|
|
4670
|
+
const toggleHistRef = (0, import_react3.useRef)([]);
|
|
4324
4671
|
const bootNow = () => bus.ui.boot ?? {
|
|
4325
4672
|
basePath: "/voice-mode",
|
|
4326
4673
|
silenceMs: 1500,
|
|
@@ -4329,6 +4676,9 @@ function MicButton({
|
|
|
4329
4676
|
autoSend: true,
|
|
4330
4677
|
autoResume: false,
|
|
4331
4678
|
mode: "toggle",
|
|
4679
|
+
readAloud: "voice",
|
|
4680
|
+
showCaptions: true,
|
|
4681
|
+
showStatusBar: true,
|
|
4332
4682
|
// 批 7O(ADR-0006):bootNow 兜底默认与 VOICE_SETTINGS_DEFAULTS 对齐为 detect。
|
|
4333
4683
|
bargeInMode: "detect",
|
|
4334
4684
|
echoGateDb: 6,
|
|
@@ -4351,7 +4701,7 @@ function MicButton({
|
|
|
4351
4701
|
const uiKeyRef = (0, import_react3.useRef)("");
|
|
4352
4702
|
(0, import_react3.useEffect)(
|
|
4353
4703
|
() => bus.subscribe(({ active, ui: u }) => {
|
|
4354
|
-
const key = `${active}|${u.state}|${u.error ?? ""}|${u.notice ?? ""}|${u.mode}|${u.wakeWord}|${u.ttsNotice ?? ""}`;
|
|
4704
|
+
const key = `${active}|${u.state}|${u.error ?? ""}|${u.notice ?? ""}|${u.mode}|${u.wakeWord}|${u.ttsNotice ?? ""}|${u.playing}|${u.turn}|${u.sseDown}|${u.idleWarn}|${u.boot?.showStatusBar}`;
|
|
4355
4705
|
if (key === uiKeyRef.current) return;
|
|
4356
4706
|
uiKeyRef.current = key;
|
|
4357
4707
|
bumpUi((t3) => t3 + 1);
|
|
@@ -4375,7 +4725,8 @@ function MicButton({
|
|
|
4375
4725
|
idleTimeoutMinutes: c.idleTimeoutMinutes ?? cur.idleTimeoutMinutes,
|
|
4376
4726
|
autoSend: c.autoSend ?? cur.autoSend,
|
|
4377
4727
|
autoResume: c.autoResume === true,
|
|
4378
|
-
mode: c.mode === "hold"
|
|
4728
|
+
mode: c.mode === "hold" || c.mode === "once" ? c.mode : "toggle",
|
|
4729
|
+
...displaySettings(c),
|
|
4379
4730
|
bargeInMode: c.bargeInMode === "manual" ? "manual" : c.bargeInMode === "detect" ? "detect" : "auto",
|
|
4380
4731
|
echoGateDb: typeof c.echoGateDb === "number" ? Math.min(12, Math.max(3, c.echoGateDb)) : cur.echoGateDb,
|
|
4381
4732
|
shortcut: typeof c.shortcut === "string" ? c.shortcut : cur.shortcut,
|
|
@@ -4469,6 +4820,7 @@ function MicButton({
|
|
|
4469
4820
|
isSpeechFalseRun = 0;
|
|
4470
4821
|
submitInFlightRef.current = false;
|
|
4471
4822
|
correctCycleRef.current++;
|
|
4823
|
+
clearOnce();
|
|
4472
4824
|
breakRef.current = null;
|
|
4473
4825
|
manualHoldRef.current = false;
|
|
4474
4826
|
holdCtrlRef.current = false;
|
|
@@ -4530,6 +4882,7 @@ function MicButton({
|
|
|
4530
4882
|
}
|
|
4531
4883
|
const runSubmit = (submitText) => {
|
|
4532
4884
|
submitInFlightRef.current = true;
|
|
4885
|
+
if (bootNow().mode === "once") beginOnceWait();
|
|
4533
4886
|
const snapshot = submitText.trim() || draftSnapshot;
|
|
4534
4887
|
let wroteBack = false;
|
|
4535
4888
|
if (snapshot !== draftSnapshot && typeof actions?.setDraft === "function") {
|
|
@@ -4602,13 +4955,71 @@ function MicButton({
|
|
|
4602
4955
|
const eng = engineRef.current;
|
|
4603
4956
|
if (eng && (eng.state === "speech" || eng.holding)) return;
|
|
4604
4957
|
if (bus.ui.playing) return;
|
|
4605
|
-
if (bootNow().autoSend === false)
|
|
4958
|
+
if (bootNow().autoSend === false) {
|
|
4959
|
+
if (bootNow().mode === "once") void exitModeRef.current("manual");
|
|
4960
|
+
return;
|
|
4961
|
+
}
|
|
4606
4962
|
submitDraftNow();
|
|
4607
4963
|
}, AUTO_SEND_EXTRA_MS);
|
|
4608
4964
|
};
|
|
4965
|
+
const clearOnce = () => {
|
|
4966
|
+
const o = onceRef.current;
|
|
4967
|
+
if (!o) return;
|
|
4968
|
+
onceRef.current = null;
|
|
4969
|
+
clearTimeout(o.noStart);
|
|
4970
|
+
if (o.settle) clearTimeout(o.settle);
|
|
4971
|
+
if (o.stall) clearTimeout(o.stall);
|
|
4972
|
+
setOnceWaiting(false);
|
|
4973
|
+
setOnceEnding(false);
|
|
4974
|
+
};
|
|
4975
|
+
const checkOnce = () => {
|
|
4976
|
+
const o = onceRef.current;
|
|
4977
|
+
if (!o) return;
|
|
4978
|
+
const running = useSession ? runningRef.current : bus.ui.turn === "agent-speaking";
|
|
4979
|
+
if (running) o.sawRun = true;
|
|
4980
|
+
const quiet = o.sawRun && !running && !bus.ui.playing;
|
|
4981
|
+
const done = onceFinished(o, running, bus.ui.ttsDrained === true, bus.ui.playing);
|
|
4982
|
+
if (done && !o.settle) {
|
|
4983
|
+
setOnceEnding(true);
|
|
4984
|
+
o.settle = setTimeout(() => {
|
|
4985
|
+
if (onceRef.current === o) void exitModeRef.current("manual");
|
|
4986
|
+
}, ONCE_SETTLE_MS);
|
|
4987
|
+
} else if (!done && o.settle) {
|
|
4988
|
+
setOnceEnding(false);
|
|
4989
|
+
clearTimeout(o.settle);
|
|
4990
|
+
o.settle = null;
|
|
4991
|
+
}
|
|
4992
|
+
if (quiet && !o.stall) {
|
|
4993
|
+
o.stall = setTimeout(() => {
|
|
4994
|
+
if (onceRef.current === o) void exitModeRef.current("manual");
|
|
4995
|
+
}, ONCE_STALL_MS);
|
|
4996
|
+
} else if (!quiet && o.stall) {
|
|
4997
|
+
clearTimeout(o.stall);
|
|
4998
|
+
o.stall = null;
|
|
4999
|
+
}
|
|
5000
|
+
};
|
|
5001
|
+
const beginOnceWait = () => {
|
|
5002
|
+
if (onceRef.current || localRef.current !== "on") return;
|
|
5003
|
+
cancelAutoSend();
|
|
5004
|
+
clearIdle();
|
|
5005
|
+
const o = {
|
|
5006
|
+
sawRun: false,
|
|
5007
|
+
settle: null,
|
|
5008
|
+
stall: null,
|
|
5009
|
+
noStart: setTimeout(() => {
|
|
5010
|
+
if (onceRef.current === o && !o.sawRun) void exitModeRef.current("manual");
|
|
5011
|
+
}, ONCE_NO_START_MS)
|
|
5012
|
+
};
|
|
5013
|
+
onceRef.current = o;
|
|
5014
|
+
setOnceWaiting(true);
|
|
5015
|
+
void engineRef.current?.stop();
|
|
5016
|
+
bus.setUi({ partial: "", levels: [], isSpeech: void 0 });
|
|
5017
|
+
checkOnce();
|
|
5018
|
+
};
|
|
4609
5019
|
const exitMode = async (reason) => {
|
|
4610
5020
|
if (localRef.current === "off") return;
|
|
4611
5021
|
setLocalMode("off");
|
|
5022
|
+
clearOnce();
|
|
4612
5023
|
clearIdle();
|
|
4613
5024
|
cancelPendingSubmit();
|
|
4614
5025
|
cancelAutoSend();
|
|
@@ -4704,7 +5115,8 @@ function MicButton({
|
|
|
4704
5115
|
{
|
|
4705
5116
|
silenceMs,
|
|
4706
5117
|
basePath,
|
|
4707
|
-
|
|
5118
|
+
// once 的采音/断句/唤醒词与 toggle 完全一致,区别只在定稿后的收尾(见 onSegment)
|
|
5119
|
+
mode: cfg.mode === "hold" ? "hold" : "toggle",
|
|
4708
5120
|
wakeWord: cfg.wakeWord,
|
|
4709
5121
|
echoGateDb: cfg.echoGateDb,
|
|
4710
5122
|
// 批 7N(ADR-0006):打断方式透传——manual 时 handleAudio 仅在 holdActive 期间入流。
|
|
@@ -4843,7 +5255,7 @@ function MicButton({
|
|
|
4843
5255
|
engine.onState((s) => {
|
|
4844
5256
|
bus.setUi({ state: s });
|
|
4845
5257
|
if (s === "speech") cancelAutoSend();
|
|
4846
|
-
if (s === "idle") resetIdle();
|
|
5258
|
+
if (s === "idle" && !onceRef.current) resetIdle();
|
|
4847
5259
|
});
|
|
4848
5260
|
engine.onError((key) => {
|
|
4849
5261
|
bus.setUi({ error: t(key) });
|
|
@@ -4869,7 +5281,7 @@ function MicButton({
|
|
|
4869
5281
|
bus.setUi({ levels: next });
|
|
4870
5282
|
});
|
|
4871
5283
|
engine.onPartial((text) => {
|
|
4872
|
-
if (engineRef.current !== engine) return;
|
|
5284
|
+
if (engineRef.current !== engine || onceRef.current) return;
|
|
4873
5285
|
bus.setUi({ partial: text });
|
|
4874
5286
|
if (!text) return;
|
|
4875
5287
|
if (submitInFlightRef.current) {
|
|
@@ -4889,6 +5301,7 @@ function MicButton({
|
|
|
4889
5301
|
}
|
|
4890
5302
|
});
|
|
4891
5303
|
engine.onSegment((text, meta) => {
|
|
5304
|
+
if (onceRef.current) return;
|
|
4892
5305
|
resetIdle();
|
|
4893
5306
|
submitInFlightRef.current = false;
|
|
4894
5307
|
bus.setUi({ partial: "" });
|
|
@@ -4912,7 +5325,7 @@ function MicButton({
|
|
|
4912
5325
|
}
|
|
4913
5326
|
if (bootNow().mode === "hold") return;
|
|
4914
5327
|
if (bus.ui.playing) return;
|
|
4915
|
-
if (bootNow().autoSend === false) return;
|
|
5328
|
+
if (bootNow().autoSend === false && bootNow().mode !== "once") return;
|
|
4916
5329
|
scheduleAutoSend();
|
|
4917
5330
|
});
|
|
4918
5331
|
bus.setUi({ state: "idle", partial: "", levels: [], botLevels: [], error: null, model: null, ttsNotice: null });
|
|
@@ -4949,11 +5362,13 @@ function MicButton({
|
|
|
4949
5362
|
if (sid2) void bus.exit(sid2);
|
|
4950
5363
|
}
|
|
4951
5364
|
};
|
|
4952
|
-
const
|
|
5365
|
+
const readingOutside = () => localRef.current === "off" && bus.ui.playing;
|
|
4953
5366
|
const toggle = () => {
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
5367
|
+
if (readingOutside()) {
|
|
5368
|
+
bus.stopReading(!!useSession);
|
|
5369
|
+
return;
|
|
5370
|
+
}
|
|
5371
|
+
if (!takeToggleSlot(toggleHistRef.current, Date.now())) return;
|
|
4957
5372
|
if (localRef.current === "on") void exitModeRef.current("manual");
|
|
4958
5373
|
else if (localRef.current === "off") void enterMode();
|
|
4959
5374
|
};
|
|
@@ -4996,13 +5411,31 @@ function MicButton({
|
|
|
4996
5411
|
})();
|
|
4997
5412
|
}, [sessionId]);
|
|
4998
5413
|
const runningSel = useSession ? useSession((s) => s === void 0 ? void 0 : s.running) : void 0;
|
|
5414
|
+
const prevRunningRef = (0, import_react3.useRef)(false);
|
|
4999
5415
|
(0, import_react3.useEffect)(() => {
|
|
5000
5416
|
runningRef.current = runningSel === true;
|
|
5417
|
+
if (runningSel === true && !prevRunningRef.current && sessionId) bus.runStarted(sessionId);
|
|
5418
|
+
prevRunningRef.current = runningSel === true;
|
|
5419
|
+
checkOnce();
|
|
5001
5420
|
}, [runningSel]);
|
|
5421
|
+
(0, import_react3.useEffect)(() => bus.subscribe(() => checkOnce()), [bus]);
|
|
5422
|
+
(0, import_react3.useEffect)(() => {
|
|
5423
|
+
if (!sessionId) return;
|
|
5424
|
+
bus.setFocusedSession(sessionId);
|
|
5425
|
+
const onVis = () => {
|
|
5426
|
+
if (document.visibilityState === "visible") bus.setFocusedSession(sessionId);
|
|
5427
|
+
};
|
|
5428
|
+
document.addEventListener("visibilitychange", onVis);
|
|
5429
|
+
return () => {
|
|
5430
|
+
document.removeEventListener("visibilitychange", onVis);
|
|
5431
|
+
bus.setFocusedSession(null);
|
|
5432
|
+
};
|
|
5433
|
+
}, [bus, sessionId]);
|
|
5002
5434
|
(0, import_react3.useEffect)(() => {
|
|
5003
5435
|
mountedRef.current = true;
|
|
5004
5436
|
return () => {
|
|
5005
5437
|
mountedRef.current = false;
|
|
5438
|
+
clearOnce();
|
|
5006
5439
|
clearIdle();
|
|
5007
5440
|
cancelPendingSubmit();
|
|
5008
5441
|
cancelAutoSend();
|
|
@@ -5060,7 +5493,7 @@ function MicButton({
|
|
|
5060
5493
|
if (combo && !e.repeat && (e.key.toLowerCase() === combo.key || codeKey === combo.key) && e.ctrlKey === combo.ctrl && e.shiftKey === combo.shift && e.altKey === combo.alt && e.metaKey === combo.meta) {
|
|
5061
5494
|
const el = e.target;
|
|
5062
5495
|
const editable = el instanceof HTMLElement && (el.tagName === "TEXTAREA" || el.tagName === "INPUT" || el.isContentEditable);
|
|
5063
|
-
if (!editable &&
|
|
5496
|
+
if (!e.isComposing && !(editable && isEditingShortcut(combo, IS_MAC))) {
|
|
5064
5497
|
e.preventDefault();
|
|
5065
5498
|
cancelCtrl();
|
|
5066
5499
|
toggleRef.current();
|
|
@@ -5068,7 +5501,7 @@ function MicButton({
|
|
|
5068
5501
|
return;
|
|
5069
5502
|
}
|
|
5070
5503
|
const eng = engineRef.current;
|
|
5071
|
-
if (e.key === "Control" && !e.shiftKey && !e.altKey && !e.metaKey && !e.repeat && eng) {
|
|
5504
|
+
if (e.key === "Control" && !e.shiftKey && !e.altKey && !e.metaKey && !e.repeat && eng && !onceRef.current) {
|
|
5072
5505
|
ctrlHoldStart = Date.now();
|
|
5073
5506
|
otherKeyDuringCtrl = false;
|
|
5074
5507
|
if (bootNow().mode === "hold") {
|
|
@@ -5140,7 +5573,7 @@ function MicButton({
|
|
|
5140
5573
|
};
|
|
5141
5574
|
const onVisibility = () => {
|
|
5142
5575
|
if (document.hidden) {
|
|
5143
|
-
if (localRef.current === "on" && engineRef.current) {
|
|
5576
|
+
if (localRef.current === "on" && engineRef.current && !onceRef.current) {
|
|
5144
5577
|
if (bootNow().mode === "hold") {
|
|
5145
5578
|
engineRef.current?.endHeld(true);
|
|
5146
5579
|
holdCtrlRef.current = false;
|
|
@@ -5188,7 +5621,9 @@ function MicButton({
|
|
|
5188
5621
|
const phaseRef = (0, import_react3.useRef)("");
|
|
5189
5622
|
phaseRef.current = livePhase;
|
|
5190
5623
|
const [holding, setHolding] = (0, import_react3.useState)(false);
|
|
5191
|
-
const
|
|
5624
|
+
const reading = local === "off" && bus.ui.playing;
|
|
5625
|
+
const showTurn = onceWaiting || bootNow().showStatusBar === false && bus.ui.state !== "speech" && (bus.ui.playing || bus.ui.turn === "agent-speaking");
|
|
5626
|
+
const label = on && showTurn ? bus.ui.playing ? t("reading") : t("thinking") : reading ? t("stopReading") : on ? busy ? (
|
|
5192
5627
|
// UX:loading-model 是加载/下载模型而非识别——「识别中…」与状态不符。
|
|
5193
5628
|
bus.ui.state === "loading-model" ? t("buttonLoading") : t("recognizing")
|
|
5194
5629
|
) : holdMode ? holding ? t("releaseToSend") : t("holdToTalk") : bus.ui.state === "wake" ? t("sayWake").replace("{wake}", bus.ui.wakeWord || t("wakeWord")) : (
|
|
@@ -5267,7 +5702,7 @@ function MicButton({
|
|
|
5267
5702
|
}, 250);
|
|
5268
5703
|
}
|
|
5269
5704
|
}
|
|
5270
|
-
} else if (localRef.current === "on" && bus.ui.playing) {
|
|
5705
|
+
} else if (localRef.current === "on" && bus.ui.playing && !onceRef.current) {
|
|
5271
5706
|
toggleHoldRef.current = true;
|
|
5272
5707
|
setHolding(true);
|
|
5273
5708
|
const eng = engineRef.current;
|
|
@@ -5311,9 +5746,11 @@ function MicButton({
|
|
|
5311
5746
|
return;
|
|
5312
5747
|
}
|
|
5313
5748
|
if (ms < 250) {
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5749
|
+
if (readingOutside()) {
|
|
5750
|
+
bus.stopReading(!!useSession);
|
|
5751
|
+
return;
|
|
5752
|
+
}
|
|
5753
|
+
if (!takeToggleSlot(toggleHistRef.current, Date.now())) return;
|
|
5317
5754
|
if (localRef.current === "on") {
|
|
5318
5755
|
engineRef.current?.endHeld(true);
|
|
5319
5756
|
void exitModeRef.current("manual");
|
|
@@ -5331,14 +5768,55 @@ function MicButton({
|
|
|
5331
5768
|
setHolding(false);
|
|
5332
5769
|
engineRef.current?.endHeld(true);
|
|
5333
5770
|
};
|
|
5334
|
-
const
|
|
5771
|
+
const statusBarShown = bootNow().showStatusBar !== false;
|
|
5772
|
+
const micHint = bus.activeSessionId !== sessionId ? bus.ui.error ?? bus.ui.notice ?? "" : statusBarShown ? "" : bus.ui.error ?? (bus.ui.sseDown ? t("sseReconnect") : null) ?? bus.ui.notice ?? (bus.ui.idleWarn ? t("idleWarn30s") : null) ?? bus.ui.ttsNotice ?? "";
|
|
5773
|
+
const visual = holding ? "holding" : bus.ui.playing ? "reading" : on && onceEnding ? "ending" : on && onceWaiting ? "waiting" : on ? holdMode ? "hold" : "on" : local === "pending" ? "pending" : "off";
|
|
5774
|
+
const eqKind = visual === "reading" ? "out" : visual === "on" || visual === "holding" ? "in" : null;
|
|
5775
|
+
(0, import_react3.useEffect)(() => {
|
|
5776
|
+
const el = btnRef.current;
|
|
5777
|
+
if (!el || !eqKind) return;
|
|
5778
|
+
const bars = Array.from(el.querySelectorAll(".dshvm-eq i"));
|
|
5779
|
+
const base = eqKind === "out" ? [6, 10, 14, 10, 6] : [6, 12, 8];
|
|
5780
|
+
const paint = (lv) => bars.forEach((b, i) => b.style.height = `${Math.max(3, base[i] * (0.35 + 0.65 * lv)).toFixed(1)}px`);
|
|
5781
|
+
if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
5782
|
+
paint(1);
|
|
5783
|
+
return;
|
|
5784
|
+
}
|
|
5785
|
+
let smooth = 0;
|
|
5786
|
+
let raf = 0;
|
|
5787
|
+
const tick = () => {
|
|
5788
|
+
const raw = eqKind === "out" ? bus.playbackLevel() : bus.ui.levels[bus.ui.levels.length - 1] ?? 0;
|
|
5789
|
+
smooth = Math.max(Math.min(1, Math.max(0, raw)), smooth * 0.82);
|
|
5790
|
+
paint(smooth);
|
|
5791
|
+
raf = requestAnimationFrame(tick);
|
|
5792
|
+
};
|
|
5793
|
+
tick();
|
|
5794
|
+
return () => cancelAnimationFrame(raf);
|
|
5795
|
+
}, [eqKind, bus]);
|
|
5796
|
+
const showTimer = on && !statusBarShown && !onceWaiting;
|
|
5797
|
+
const [elapsed, setElapsed] = (0, import_react3.useState)(0);
|
|
5798
|
+
(0, import_react3.useEffect)(() => {
|
|
5799
|
+
setElapsed(0);
|
|
5800
|
+
if (!showTimer) return;
|
|
5801
|
+
const id = setInterval(() => setElapsed((n) => n + 1), 1e3);
|
|
5802
|
+
return () => clearInterval(id);
|
|
5803
|
+
}, [showTimer]);
|
|
5804
|
+
const [menuOpen, setMenuOpen] = (0, import_react3.useState)(false);
|
|
5805
|
+
const closeMenu = React.useCallback((refocus) => {
|
|
5806
|
+
setMenuOpen(false);
|
|
5807
|
+
if (refocus) btnRef.current?.focus();
|
|
5808
|
+
}, []);
|
|
5809
|
+
const title = bus.ui.error ? String(bus.ui.error) : reading ? t("stopReading") : on ? holdMode ? t("titleHold") : t("titleToggle") : t("titleEnter");
|
|
5335
5810
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
5336
5811
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
5337
5812
|
"button",
|
|
5338
5813
|
{
|
|
5814
|
+
type: "button",
|
|
5815
|
+
className: "dshvm-mic",
|
|
5816
|
+
"data-state": visual,
|
|
5339
5817
|
onClick: (e) => {
|
|
5340
5818
|
if (Date.now() < suppressClickUntilRef.current) return;
|
|
5341
|
-
if (holdMode) {
|
|
5819
|
+
if (holdMode && !readingOutside()) {
|
|
5342
5820
|
if (e.detail !== 0) return;
|
|
5343
5821
|
}
|
|
5344
5822
|
toggle();
|
|
@@ -5347,45 +5825,26 @@ function MicButton({
|
|
|
5347
5825
|
onPointerMove,
|
|
5348
5826
|
onPointerUp,
|
|
5349
5827
|
onPointerCancel,
|
|
5350
|
-
onContextMenu: (e) =>
|
|
5828
|
+
onContextMenu: (e) => {
|
|
5829
|
+
e.preventDefault();
|
|
5830
|
+
const pt = e.nativeEvent.pointerType;
|
|
5831
|
+
if (scope && pt !== "touch" && pt !== "pen") setMenuOpen(true);
|
|
5832
|
+
},
|
|
5351
5833
|
ref: btnRef,
|
|
5352
5834
|
"data-dshvm": "mic",
|
|
5353
|
-
"aria-label": on ? t("ariaActive") : t("ariaEnter"),
|
|
5835
|
+
"aria-label": reading ? t("stopReading") : on ? `${t("ariaActive")} \xB7 ${label}` : local === "pending" ? label : t("ariaEnter"),
|
|
5354
5836
|
"aria-pressed": on,
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
background: holding ? "rgba(248, 81, 73, 0.2)" : on ? holdMode ? "rgba(88, 166, 255, 0.16)" : "rgba(63, 185, 80, 0.16)" : local === "pending" ? "rgba(88, 166, 255, 0.14)" : "rgba(139, 148, 158, 0.08)",
|
|
5359
|
-
cursor: "pointer",
|
|
5360
|
-
padding: "5px 10px",
|
|
5361
|
-
borderRadius: 8,
|
|
5362
|
-
display: "flex",
|
|
5363
|
-
alignItems: "center",
|
|
5364
|
-
gap: 6,
|
|
5365
|
-
fontSize: 12,
|
|
5366
|
-
fontFamily: "system-ui, sans-serif",
|
|
5367
|
-
color: holding ? "#f85149" : on ? holdMode ? "#58a6ff" : "#2ea043" : local === "pending" ? "#58a6ff" : "#8b949e",
|
|
5368
|
-
// 批 H 任务 3:toggle 模式「语音中」绿字加深(#3fb950 → #2ea043)+ fontWeight:600 双保险,
|
|
5369
|
-
// 浅色主题下与浅绿底 (rgba 63,185,80,.16) 对比度 ≥ 4.5:1(WCAG AA 文本级)。
|
|
5370
|
-
fontWeight: on && !holdMode ? 600 : void 0,
|
|
5371
|
-
transition: "background 0.15s ease, color 0.2s ease, border-color 0.15s ease",
|
|
5372
|
-
touchAction: "none",
|
|
5373
|
-
// 触摸设备上让 pointer 事件独占(滑出取消可用)
|
|
5374
|
-
userSelect: "none",
|
|
5375
|
-
WebkitUserSelect: "none",
|
|
5376
|
-
// iOS Safari 前缀,防长按选中文字
|
|
5377
|
-
WebkitTouchCallout: "none"
|
|
5378
|
-
// iOS 长按弹出「拷贝/选择」菜单
|
|
5379
|
-
},
|
|
5837
|
+
"aria-haspopup": scope ? "menu" : void 0,
|
|
5838
|
+
"aria-expanded": scope ? menuOpen : void 0,
|
|
5839
|
+
title,
|
|
5380
5840
|
children: [
|
|
5381
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
),
|
|
5841
|
+
visual !== "waiting" && bus.ui.isSpeech === true && on && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dshvm-mic-dot", "data-kind": "vad", title: t("vadDetected") }),
|
|
5842
|
+
bus.ui.error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dshvm-mic-dot", "data-kind": "error" }),
|
|
5843
|
+
visual === "waiting" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, "aria-hidden": "true", className: "dshvm-spin", children: [
|
|
5844
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: 12, cy: 12, r: 8, fill: "none", stroke: "currentColor", strokeWidth: 2, opacity: 0.25 }),
|
|
5845
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 4a8 8 0 0 1 8 8", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round" })
|
|
5846
|
+
] }) : visual === "ending" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M5.5 12.5l4.2 4.2 8.8-8.8", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round" }) }) : eqKind ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: eqKind === "out" ? "dshvm-eq dshvm-eq-out" : "dshvm-eq", "aria-hidden": "true", children: (eqKind === "out" ? [6, 10, 14, 10, 6] : [6, 12, 8]).map((h, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("i", { style: { height: h } }, i)) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, "aria-hidden": "true", children: [
|
|
5847
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { fill: "currentColor", d: "M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3Z" }),
|
|
5389
5848
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
5390
5849
|
"path",
|
|
5391
5850
|
{
|
|
@@ -5394,10 +5853,15 @@ function MicButton({
|
|
|
5394
5853
|
}
|
|
5395
5854
|
)
|
|
5396
5855
|
] }),
|
|
5397
|
-
|
|
5856
|
+
showTimer && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dshvm-mic-timer", "aria-hidden": "true", children: [
|
|
5857
|
+
String(Math.floor(elapsed / 60)).padStart(2, "0"),
|
|
5858
|
+
":",
|
|
5859
|
+
String(elapsed % 60).padStart(2, "0")
|
|
5860
|
+
] })
|
|
5398
5861
|
]
|
|
5399
5862
|
}
|
|
5400
5863
|
),
|
|
5864
|
+
menuOpen && scope && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MicMenu, { scope, anchor: btnRef.current, onClose: closeMenu }),
|
|
5401
5865
|
micHint && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
5402
5866
|
"span",
|
|
5403
5867
|
{
|
|
@@ -5407,7 +5871,7 @@ function MicButton({
|
|
|
5407
5871
|
title: micHint,
|
|
5408
5872
|
style: {
|
|
5409
5873
|
fontSize: 11,
|
|
5410
|
-
color: "#f85149",
|
|
5874
|
+
color: "var(--dsw-alias-state-error-primary, #f85149)",
|
|
5411
5875
|
maxWidth: 240,
|
|
5412
5876
|
overflow: "hidden",
|
|
5413
5877
|
textOverflow: "ellipsis",
|
|
@@ -5462,7 +5926,7 @@ function VoiceStatusBar({ bus, sessionId }) {
|
|
|
5462
5926
|
return () => clearInterval(id);
|
|
5463
5927
|
}, [b.ui.state]);
|
|
5464
5928
|
const isActive = b.active === sessionId;
|
|
5465
|
-
if (!isActive) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {});
|
|
5929
|
+
if (!isActive || b.ui.boot?.showStatusBar === false) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {});
|
|
5466
5930
|
const stateText = b.ui.state === "loading-model" ? t("loadingModel") : b.ui.state === "transcribing" ? transcribingSec >= 2 ? t("recognizingSec").replace("{sec}", String(transcribingSec)) : t("recognizing") : b.ui.state === "wake" ? t("sayWake").replace("{wake}", b.ui.wakeWord || t("wakeWord")) : b.ui.state === "speech" ? b.ui.mode === "hold" ? t("holdDots") : t("listening") : b.ui.playing ? t("reading") : b.ui.turn === "agent-speaking" ? t("thinking") : b.ui.mode === "hold" ? t("barHold") : t("barListening");
|
|
5467
5931
|
const bars = Array.from({ length: WAVE_BARS }, (_, i) => b.ui.levels[i] ?? 0);
|
|
5468
5932
|
const botBars = Array.from({ length: WAVE_BARS }, (_, i) => b.ui.botLevels[i] ?? 0);
|
|
@@ -5685,7 +6149,7 @@ function VoiceOverlay({ bus }) {
|
|
|
5685
6149
|
(0, import_react3.useEffect)(() => {
|
|
5686
6150
|
return bus.subscribe(setB);
|
|
5687
6151
|
}, [bus]);
|
|
5688
|
-
if (!b.ui.playing) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {});
|
|
6152
|
+
if (!b.ui.playing || b.ui.boot?.showCaptions === false) return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {});
|
|
5689
6153
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
5690
6154
|
"div",
|
|
5691
6155
|
{
|