@hyprnos/dsh-remote-plugin 0.8.8 → 0.8.10
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/apk/dsh-remote.apk +0 -0
- package/index.mjs +4 -0
- package/package.json +4 -2
- package/public/admin.html +29 -29
- package/public/build.json +2 -2
- package/public/desktop/desktop.html +62 -62
- package/public/index.html +89 -69
- package/public/plugin.html +25 -25
- package/public/skins/blue-fish/preview.html +3 -3
- package/public/skins/bocchi/preview.html +5 -5
- package/public/skins/kita/preview.html +6 -6
- package/public/skins/nijika/preview.html +6 -6
- package/public/skins/penguin/preview.html +3 -3
- package/public/skins/ryo/preview.html +6 -6
- package/public/styles.css +32 -0
- package/public/update.json +12 -12
- package/public/version.json +1 -1
- package/public/voice-input.js +417 -5
- package/public/workflow.js +16 -2
- package/speech-whisper.mjs +705 -0
package/public/voice-input.js
CHANGED
|
@@ -86,6 +86,91 @@
|
|
|
86
86
|
}
|
|
87
87
|
return caret
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
/* ---- 语音设置:术语纠错表 / 识别模型与语言(纯逻辑,弹层只做展示与派发) ---- */
|
|
91
|
+
// 纠错表保存在本机各自一份,格式每行「错误=正确」;从未保存过时才回落到默认条目。
|
|
92
|
+
const CORRECTIONS_KEY = 'dsr.voice.corrections'
|
|
93
|
+
const DEFAULT_CORRECTIONS = ['confit=config', 'servve=server', 'log=logs', 'mcp=MCP'].join('\n')
|
|
94
|
+
const CORRECTIONS_MAX_ENTRIES = 200
|
|
95
|
+
const USABLE_PHASES = ['ready', 'standby', 'waking']
|
|
96
|
+
const IDLE_PHASES = ['', 'unprepared', 'cancelled', 'failed']
|
|
97
|
+
|
|
98
|
+
function phaseUsable(phase) { return USABLE_PHASES.indexOf(String(phase || '')) >= 0 }
|
|
99
|
+
|
|
100
|
+
// 本地文本原样返回(空字符串表示「不纠错」);key 不存在才用默认条目。
|
|
101
|
+
function correctionsText(stored) {
|
|
102
|
+
return typeof stored === 'string' ? stored : DEFAULT_CORRECTIONS
|
|
103
|
+
}
|
|
104
|
+
function escapeRegExp(text) {
|
|
105
|
+
return String(text == null ? '' : text).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
106
|
+
}
|
|
107
|
+
// 解析纠错表:忽略空行、# 注释、缺少 = 的行、左空与错误/正确完全相同的行;重复的「错误」只留第一条。
|
|
108
|
+
// 返回按「错误」长度降序的表,长词先替换,避免短词先把长词切碎。
|
|
109
|
+
function parseCorrections(text) {
|
|
110
|
+
const entries = []
|
|
111
|
+
const seen = new Set()
|
|
112
|
+
for (const raw of String(text == null ? '' : text).split(/\r?\n/)) {
|
|
113
|
+
if (entries.length >= CORRECTIONS_MAX_ENTRIES) break
|
|
114
|
+
const line = raw.trim()
|
|
115
|
+
if (!line || line.charAt(0) === '#') continue
|
|
116
|
+
const at = line.indexOf('=')
|
|
117
|
+
if (at <= 0) continue
|
|
118
|
+
const from = line.slice(0, at).trim()
|
|
119
|
+
const to = line.slice(at + 1).trim()
|
|
120
|
+
if (!from || from === to) continue
|
|
121
|
+
const key = from.toLowerCase()
|
|
122
|
+
if (seen.has(key)) continue
|
|
123
|
+
seen.add(key)
|
|
124
|
+
entries.push({ from, to })
|
|
125
|
+
}
|
|
126
|
+
entries.sort((left, right) => right.from.length - left.from.length)
|
|
127
|
+
return entries
|
|
128
|
+
}
|
|
129
|
+
// 应用纠错表:大小写不敏感、整词匹配(ASCII 单词字符两侧不成词),替换文本保留目标原文。
|
|
130
|
+
// 不用 lookbehind,兼容旧版 iOS Safari;行首行尾算边界,中文相邻文字也算边界。
|
|
131
|
+
function applyCorrections(text, table) {
|
|
132
|
+
let value = String(text == null ? '' : text)
|
|
133
|
+
const entries = Array.isArray(table) ? table : parseCorrections(table)
|
|
134
|
+
for (const entry of entries) {
|
|
135
|
+
if (!entry || !entry.from) continue
|
|
136
|
+
let pattern = null
|
|
137
|
+
try {
|
|
138
|
+
pattern = new RegExp('(^|[^A-Za-z0-9_])(' + escapeRegExp(entry.from) + ')(?![A-Za-z0-9_])', 'gi')
|
|
139
|
+
} catch (_) { continue }
|
|
140
|
+
value = value.replace(pattern, (match, lead, hit) => lead + entry.to)
|
|
141
|
+
}
|
|
142
|
+
return value
|
|
143
|
+
}
|
|
144
|
+
// speech.configure 的 payload 形状固定为 {patch:{providerId}} 或 {patch:{language}}。
|
|
145
|
+
function configureProviderPatch(providerId) {
|
|
146
|
+
const id = String(providerId == null ? '' : providerId).trim()
|
|
147
|
+
return id ? { patch: { providerId: id } } : null
|
|
148
|
+
}
|
|
149
|
+
function configureLanguagePatch(language) {
|
|
150
|
+
const code = String(language == null ? '' : language).trim()
|
|
151
|
+
return code ? { patch: { language: code } } : null
|
|
152
|
+
}
|
|
153
|
+
// 语言候选:provider 自带列表去重,auto(跟随识别/主机默认)固定排第一。
|
|
154
|
+
function voiceLanguages(provider) {
|
|
155
|
+
const out = []
|
|
156
|
+
const list = Array.isArray(provider && provider.languages) ? provider.languages : []
|
|
157
|
+
for (const item of list) {
|
|
158
|
+
const code = typeof item === 'string' ? item.trim() : ''
|
|
159
|
+
if (code && code !== 'auto' && out.indexOf(code) < 0) out.push(code)
|
|
160
|
+
}
|
|
161
|
+
return ['auto'].concat(out)
|
|
162
|
+
}
|
|
163
|
+
// 弹层展示用的准备状态:ready 可用 / busy 下载或加载中 / percent 进度 / failed 失败。
|
|
164
|
+
function providerStatus(provider) {
|
|
165
|
+
const preparation = (provider && provider.preparation) || {}
|
|
166
|
+
const phase = String(preparation.phase || '')
|
|
167
|
+
const total = Number(preparation.totalBytes)
|
|
168
|
+
const completed = Number(preparation.completedBytes)
|
|
169
|
+
const percent = Number.isFinite(total) && total > 0 && Number.isFinite(completed)
|
|
170
|
+
? Math.max(0, Math.min(100, Math.floor(completed / total * 100))) : null
|
|
171
|
+
const ready = phaseUsable(phase)
|
|
172
|
+
return { phase, ready, busy: !ready && IDLE_PHASES.indexOf(phase) < 0, failed: phase === 'failed', percent }
|
|
173
|
+
}
|
|
89
174
|
/* <<< 纯函数区 */
|
|
90
175
|
|
|
91
176
|
const DEFAULT_MAX_DURATION_SECONDS = 120
|
|
@@ -94,7 +179,6 @@
|
|
|
94
179
|
const PREPARE_BACKOFF_MS = 5000
|
|
95
180
|
const PREPARE_MAX_MS = 30 * 60 * 1000
|
|
96
181
|
const PREPARE_RETRY_DELAYS = [5000, 20000, 60000]
|
|
97
|
-
const USABLE_PHASES = ['ready', 'standby', 'waking']
|
|
98
182
|
|
|
99
183
|
let host = null
|
|
100
184
|
let catalog = null
|
|
@@ -110,6 +194,12 @@
|
|
|
110
194
|
let pollTimer = null
|
|
111
195
|
let pollStartedAt = 0
|
|
112
196
|
let hideBarTimer = null
|
|
197
|
+
let settingsEls = null
|
|
198
|
+
let settingsOpen = false
|
|
199
|
+
let settingsLoading = false
|
|
200
|
+
let settingsBusy = false
|
|
201
|
+
let settingsError = ''
|
|
202
|
+
let settingsStamp = 0
|
|
113
203
|
const ABORTED = { voiceAbort: true }
|
|
114
204
|
|
|
115
205
|
function t(key, vars) {
|
|
@@ -153,7 +243,6 @@
|
|
|
153
243
|
if (!catalog) return null
|
|
154
244
|
return providerById(catalog.providerId) || catalog.providers[0] || null
|
|
155
245
|
}
|
|
156
|
-
function phaseUsable(phase) { return USABLE_PHASES.indexOf(String(phase || '')) >= 0 }
|
|
157
246
|
function canCaptureAudio() {
|
|
158
247
|
const navigatorRef = root.navigator || {}
|
|
159
248
|
const media = !!(navigatorRef.mediaDevices && typeof navigatorRef.mediaDevices.getUserMedia === 'function')
|
|
@@ -189,6 +278,8 @@
|
|
|
189
278
|
catalogState = 'ok'
|
|
190
279
|
probeFailures = 0
|
|
191
280
|
renderMic()
|
|
281
|
+
// 弹层开着时用最新 catalog 重渲染(不含 selection 的本地猜测)
|
|
282
|
+
if (settingsOpen) renderSettings()
|
|
192
283
|
return catalog
|
|
193
284
|
} catch (error) {
|
|
194
285
|
if (stamp !== probeStamp) return catalog
|
|
@@ -256,11 +347,19 @@
|
|
|
256
347
|
action.className = 'voice-input-action hidden'
|
|
257
348
|
action.type = 'button'
|
|
258
349
|
action.addEventListener('click', () => { if (typeof barAction === 'function') void barAction() })
|
|
350
|
+
// 齿轮:录音/转写以外的状态都能打开语音设置(识别模型/语言/术语纠错)
|
|
351
|
+
const gear = document.createElement('button')
|
|
352
|
+
gear.id = 'voice-input-settings'
|
|
353
|
+
gear.className = 'voice-input-settings hidden'
|
|
354
|
+
gear.type = 'button'
|
|
355
|
+
gear.textContent = '⚙'
|
|
356
|
+
gear.addEventListener('click', () => { openSettings() })
|
|
259
357
|
bar.appendChild(dot)
|
|
260
358
|
bar.appendChild(text)
|
|
261
359
|
bar.appendChild(action)
|
|
360
|
+
bar.appendChild(gear)
|
|
262
361
|
wrap.insertBefore(bar, composer)
|
|
263
|
-
barEls = { bar, dot, text, action }
|
|
362
|
+
barEls = { bar, dot, text, action, gear }
|
|
264
363
|
return barEls
|
|
265
364
|
}
|
|
266
365
|
|
|
@@ -281,6 +380,12 @@
|
|
|
281
380
|
ui.action.textContent = ''
|
|
282
381
|
ui.action.classList.add('hidden')
|
|
283
382
|
}
|
|
383
|
+
// 录音与转写期间不需要改设置,隐藏齿轮
|
|
384
|
+
const hideSettings = settings.hideSettings === true || settings.recording === true || mode === 'transcribing' || mode === 'starting'
|
|
385
|
+
if (ui.gear) {
|
|
386
|
+
ui.gear.classList.toggle('hidden', hideSettings)
|
|
387
|
+
ui.gear.setAttribute('aria-label', t('voice.settings.title'))
|
|
388
|
+
}
|
|
284
389
|
ui.bar.classList.remove('hidden')
|
|
285
390
|
}
|
|
286
391
|
|
|
@@ -293,6 +398,7 @@
|
|
|
293
398
|
barEls.bar.classList.remove('recording', 'error')
|
|
294
399
|
barEls.text.textContent = ''
|
|
295
400
|
barEls.action.classList.add('hidden')
|
|
401
|
+
if (barEls.gear) barEls.gear.classList.add('hidden')
|
|
296
402
|
}
|
|
297
403
|
}
|
|
298
404
|
|
|
@@ -532,9 +638,12 @@
|
|
|
532
638
|
}, 180000)
|
|
533
639
|
const text = String(result && result.text != null ? result.text : '').trim()
|
|
534
640
|
if (!text) { toast(t('voice.empty'), 'err'); throw ABORTED }
|
|
641
|
+
// 术语纠错在插入前应用:大小写不敏感整词替换,坏行忽略;替换后为空按「没识别到」处理
|
|
642
|
+
const corrected = applyCorrections(text, parseCorrections(savedCorrections()))
|
|
643
|
+
if (!corrected.trim()) { toast(t('voice.empty'), 'err'); throw ABORTED }
|
|
535
644
|
// 转写期间切换了服务器:文本不属于当前草稿,丢弃而不是插入
|
|
536
645
|
if (connectionId() !== connectionAtStart) throw ABORTED
|
|
537
|
-
insertTranscript(
|
|
646
|
+
insertTranscript(corrected)
|
|
538
647
|
}
|
|
539
648
|
|
|
540
649
|
// 只插入文本,不自动发送:保留原有内容与焦点,派发 input 让发送按钮状态刷新。
|
|
@@ -596,6 +705,7 @@
|
|
|
596
705
|
mode = 'idle'
|
|
597
706
|
renderMic()
|
|
598
707
|
handlePrepareError(error)
|
|
708
|
+
if (settingsOpen) renderSettings()
|
|
599
709
|
return
|
|
600
710
|
}
|
|
601
711
|
startPreparationPolling()
|
|
@@ -642,6 +752,8 @@
|
|
|
642
752
|
catalog = normalizeCatalog(next)
|
|
643
753
|
const provider = providerById(prepareProviderId) || selectedProvider()
|
|
644
754
|
const status = paintPreparation(provider)
|
|
755
|
+
// 弹层里的进度/状态跟内联条同步刷新
|
|
756
|
+
if (settingsOpen) renderSettings()
|
|
645
757
|
if (status === 'ready') { mode = 'idle'; renderMic(); hideBarLater(2600); return }
|
|
646
758
|
if (status === 'failed' || status === 'cancelled') { mode = 'idle'; renderMic(); return }
|
|
647
759
|
schedulePreparationPoll(PREPARE_POLL_MS)
|
|
@@ -687,6 +799,7 @@
|
|
|
687
799
|
mode = 'idle'
|
|
688
800
|
renderMic()
|
|
689
801
|
setBar(t('voice.notReady'), providerId ? { action: beginPreparation, actionLabel: t('voice.prepare') } : {})
|
|
802
|
+
if (settingsOpen) renderSettings()
|
|
690
803
|
if (!providerId) return
|
|
691
804
|
try {
|
|
692
805
|
await host.rpc('speech.cancelPreparation', { providerId }, 30000)
|
|
@@ -695,6 +808,303 @@
|
|
|
695
808
|
}
|
|
696
809
|
}
|
|
697
810
|
|
|
811
|
+
/* ---------------- 语音设置弹层(识别模型 / 识别语言 / 术语纠错) ----------------
|
|
812
|
+
* 入口两条:更多页「语音输入」行与内联条齿轮,都调 openSettings()。
|
|
813
|
+
* 弹层只是 catalog 的视图:configure 成功后才更新本地选中态,失败 toast 并回滚。 */
|
|
814
|
+
function storageRead(key) {
|
|
815
|
+
try {
|
|
816
|
+
const store = root.localStorage
|
|
817
|
+
return store && typeof store.getItem === 'function' ? store.getItem(key) : null
|
|
818
|
+
} catch (_) { return null }
|
|
819
|
+
}
|
|
820
|
+
function storageWrite(key, value) {
|
|
821
|
+
try {
|
|
822
|
+
const store = root.localStorage
|
|
823
|
+
if (store && typeof store.setItem === 'function') store.setItem(key, String(value))
|
|
824
|
+
} catch (_) {}
|
|
825
|
+
}
|
|
826
|
+
function savedCorrections() { return correctionsText(storageRead(CORRECTIONS_KEY)) }
|
|
827
|
+
|
|
828
|
+
function nodeOf(tag, className, text) {
|
|
829
|
+
const node = document.createElement(tag)
|
|
830
|
+
if (className) node.className = className
|
|
831
|
+
if (text != null) node.textContent = text
|
|
832
|
+
return node
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
function ensureSettings() {
|
|
836
|
+
if (settingsEls && settingsEls.overlay && settingsEls.overlay.isConnected) return settingsEls
|
|
837
|
+
if (typeof document === 'undefined' || !document.body) return null
|
|
838
|
+
const overlay = nodeOf('div', 'voice-settings hidden')
|
|
839
|
+
overlay.id = 'voice-settings'
|
|
840
|
+
overlay.setAttribute('role', 'dialog')
|
|
841
|
+
overlay.setAttribute('aria-modal', 'true')
|
|
842
|
+
overlay.setAttribute('aria-labelledby', 'voice-settings-title')
|
|
843
|
+
// 点遮罩关闭;面板内部点击不冒泡关闭;Esc 同样关闭
|
|
844
|
+
overlay.addEventListener('click', event => { if (event && event.target === overlay) closeSettings() })
|
|
845
|
+
overlay.addEventListener('keydown', event => { if (event && event.key === 'Escape') closeSettings() })
|
|
846
|
+
const sheet = nodeOf('div', 'voice-settings-sheet')
|
|
847
|
+
const head = nodeOf('div', 'voice-settings-head')
|
|
848
|
+
const title = nodeOf('h2')
|
|
849
|
+
title.id = 'voice-settings-title'
|
|
850
|
+
const close = nodeOf('button', 'voice-settings-close', '×')
|
|
851
|
+
close.id = 'voice-settings-close'
|
|
852
|
+
close.type = 'button'
|
|
853
|
+
close.addEventListener('click', () => closeSettings())
|
|
854
|
+
head.appendChild(title)
|
|
855
|
+
head.appendChild(close)
|
|
856
|
+
|
|
857
|
+
const body = nodeOf('div', 'voice-settings-body')
|
|
858
|
+
const status = nodeOf('p', 'voice-settings-status')
|
|
859
|
+
status.id = 'voice-settings-status'
|
|
860
|
+
status.setAttribute('role', 'status')
|
|
861
|
+
status.setAttribute('aria-live', 'polite')
|
|
862
|
+
|
|
863
|
+
// ① 识别模型:列出 catalog.providers 与准备状态,选中即 speech.configure
|
|
864
|
+
const modelSection = nodeOf('section', 'voice-settings-section')
|
|
865
|
+
const modelTitle = nodeOf('h3', 'voice-settings-section-title')
|
|
866
|
+
const modelHint = nodeOf('p', 'voice-settings-hint')
|
|
867
|
+
const modelList = nodeOf('div', 'voice-settings-options')
|
|
868
|
+
modelList.id = 'voice-settings-models'
|
|
869
|
+
modelList.setAttribute('role', 'radiogroup')
|
|
870
|
+
const prepare = nodeOf('button', 'voice-settings-primary hidden')
|
|
871
|
+
prepare.id = 'voice-settings-prepare'
|
|
872
|
+
prepare.type = 'button'
|
|
873
|
+
prepare.addEventListener('click', () => { void toggleSettingsPrepare() })
|
|
874
|
+
modelSection.appendChild(modelTitle)
|
|
875
|
+
modelSection.appendChild(modelHint)
|
|
876
|
+
modelSection.appendChild(modelList)
|
|
877
|
+
modelSection.appendChild(prepare)
|
|
878
|
+
|
|
879
|
+
// ② 识别语言:候选取所选 provider 的 languages(含 auto)
|
|
880
|
+
const langSection = nodeOf('section', 'voice-settings-section')
|
|
881
|
+
const langTitle = nodeOf('h3', 'voice-settings-section-title')
|
|
882
|
+
const langHint = nodeOf('p', 'voice-settings-hint')
|
|
883
|
+
const langSelect = nodeOf('select', 'voice-settings-select')
|
|
884
|
+
langSelect.id = 'voice-settings-language'
|
|
885
|
+
langSelect.addEventListener('change', () => { void chooseLanguage(langSelect.value) })
|
|
886
|
+
langSection.appendChild(langTitle)
|
|
887
|
+
langSection.appendChild(langHint)
|
|
888
|
+
langSection.appendChild(langSelect)
|
|
889
|
+
|
|
890
|
+
// ③ 术语纠错:每行「错误=正确」,本机保存,转写后整词替换
|
|
891
|
+
const correctionSection = nodeOf('section', 'voice-settings-section')
|
|
892
|
+
const correctionTitle = nodeOf('h3', 'voice-settings-section-title')
|
|
893
|
+
const correctionHint = nodeOf('p', 'voice-settings-hint')
|
|
894
|
+
const correctionText = nodeOf('textarea', 'voice-settings-textarea')
|
|
895
|
+
correctionText.id = 'voice-settings-corrections'
|
|
896
|
+
correctionText.rows = 6
|
|
897
|
+
correctionText.spellcheck = false
|
|
898
|
+
correctionText.addEventListener('input', () => {
|
|
899
|
+
storageWrite(CORRECTIONS_KEY, correctionText.value)
|
|
900
|
+
correctionStatus.textContent = t('voice.correction.saved', { count: parseCorrections(correctionText.value).length })
|
|
901
|
+
})
|
|
902
|
+
const correctionReset = nodeOf('button', 'voice-settings-secondary')
|
|
903
|
+
correctionReset.id = 'voice-settings-corrections-reset'
|
|
904
|
+
correctionReset.type = 'button'
|
|
905
|
+
correctionReset.addEventListener('click', () => {
|
|
906
|
+
correctionText.value = DEFAULT_CORRECTIONS
|
|
907
|
+
storageWrite(CORRECTIONS_KEY, DEFAULT_CORRECTIONS)
|
|
908
|
+
correctionStatus.textContent = t('voice.correction.saved', { count: parseCorrections(DEFAULT_CORRECTIONS).length })
|
|
909
|
+
})
|
|
910
|
+
const correctionStatus = nodeOf('p', 'voice-settings-hint')
|
|
911
|
+
correctionStatus.id = 'voice-settings-corrections-status'
|
|
912
|
+
correctionStatus.setAttribute('role', 'status')
|
|
913
|
+
correctionStatus.setAttribute('aria-live', 'polite')
|
|
914
|
+
correctionSection.appendChild(correctionTitle)
|
|
915
|
+
correctionSection.appendChild(correctionHint)
|
|
916
|
+
correctionSection.appendChild(correctionText)
|
|
917
|
+
correctionSection.appendChild(correctionReset)
|
|
918
|
+
correctionSection.appendChild(correctionStatus)
|
|
919
|
+
|
|
920
|
+
body.appendChild(status)
|
|
921
|
+
body.appendChild(modelSection)
|
|
922
|
+
body.appendChild(langSection)
|
|
923
|
+
body.appendChild(correctionSection)
|
|
924
|
+
sheet.appendChild(head)
|
|
925
|
+
sheet.appendChild(body)
|
|
926
|
+
overlay.appendChild(sheet)
|
|
927
|
+
document.body.appendChild(overlay)
|
|
928
|
+
settingsEls = {
|
|
929
|
+
overlay, sheet, title, close, status,
|
|
930
|
+
modelTitle, modelHint, modelList, prepare,
|
|
931
|
+
langTitle, langHint, langSelect,
|
|
932
|
+
correctionTitle, correctionHint, correctionText, correctionReset, correctionStatus
|
|
933
|
+
}
|
|
934
|
+
return settingsEls
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
function modelStatusLabel(state) {
|
|
938
|
+
if (state.ready) return t('voice.model.ready')
|
|
939
|
+
if (state.failed) return t('voice.model.failed')
|
|
940
|
+
if (state.busy) return state.percent == null ? t('voice.model.preparing') : t('voice.model.downloading', { percent: state.percent })
|
|
941
|
+
return t('voice.model.notReady')
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// 用当前 catalog 渲染:打开弹层与每次轮询后都走这里,选中态只认 catalog.selection
|
|
945
|
+
function renderSettings() {
|
|
946
|
+
const ui = settingsEls
|
|
947
|
+
if (!ui) return
|
|
948
|
+
ui.title.textContent = t('voice.settings.title')
|
|
949
|
+
ui.close.setAttribute('aria-label', t('voice.settings.close'))
|
|
950
|
+
ui.modelTitle.textContent = t('voice.model.title')
|
|
951
|
+
ui.modelHint.textContent = t('voice.model.hint')
|
|
952
|
+
ui.langTitle.textContent = t('voice.lang.title')
|
|
953
|
+
ui.langHint.textContent = t('voice.lang.hint')
|
|
954
|
+
ui.correctionTitle.textContent = t('voice.correction.title')
|
|
955
|
+
ui.correctionHint.textContent = t('voice.correction.hint')
|
|
956
|
+
ui.correctionReset.textContent = t('voice.correction.reset')
|
|
957
|
+
ui.status.textContent = settingsLoading ? t('voice.settings.loading') : settingsError
|
|
958
|
+
|
|
959
|
+
const providers = catalog && Array.isArray(catalog.providers) ? catalog.providers : []
|
|
960
|
+
ui.modelList.replaceChildren()
|
|
961
|
+
let selected = null
|
|
962
|
+
for (const provider of providers) {
|
|
963
|
+
const id = String((provider && provider.id) || '')
|
|
964
|
+
if (!id) continue
|
|
965
|
+
const state = providerStatus(provider)
|
|
966
|
+
const chosen = !!catalog && catalog.providerId === id
|
|
967
|
+
const row = nodeOf('button', 'voice-settings-option' + (chosen ? ' selected' : ''))
|
|
968
|
+
row.id = 'voice-model-' + id
|
|
969
|
+
row.type = 'button'
|
|
970
|
+
row.setAttribute('role', 'radio')
|
|
971
|
+
row.setAttribute('data-voice-model', id)
|
|
972
|
+
row.setAttribute('aria-checked', chosen ? 'true' : 'false')
|
|
973
|
+
row.appendChild(nodeOf('span', 'voice-settings-option-name', String(provider.name || id)))
|
|
974
|
+
row.appendChild(nodeOf('span', 'voice-settings-option-state' + (state.ready ? ' ready' : state.failed ? ' failed' : ''), modelStatusLabel(state)))
|
|
975
|
+
row.addEventListener('click', () => { void chooseProvider(id) })
|
|
976
|
+
ui.modelList.appendChild(row)
|
|
977
|
+
if (chosen) selected = { provider, state }
|
|
978
|
+
}
|
|
979
|
+
if (!providers.length) ui.modelList.appendChild(nodeOf('p', 'voice-settings-empty', t('voice.model.empty')))
|
|
980
|
+
|
|
981
|
+
// 所选 provider 未就绪:弹层里直接「下载并准备」,复用内联条的 prepare 轮询
|
|
982
|
+
const needsPrepare = !!selected && !selected.state.ready
|
|
983
|
+
if (needsPrepare) {
|
|
984
|
+
const busy = selected.state.busy || mode === 'preparing'
|
|
985
|
+
ui.prepare.textContent = busy ? t('voice.cancel') : t('voice.model.prepare')
|
|
986
|
+
ui.prepare.disabled = settingsBusy
|
|
987
|
+
ui.prepare.classList.remove('hidden')
|
|
988
|
+
} else {
|
|
989
|
+
ui.prepare.textContent = ''
|
|
990
|
+
ui.prepare.disabled = false
|
|
991
|
+
ui.prepare.classList.add('hidden')
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
const provider = selected ? selected.provider : selectedProvider()
|
|
995
|
+
const languages = voiceLanguages(provider)
|
|
996
|
+
ui.langSelect.replaceChildren()
|
|
997
|
+
for (const code of languages) {
|
|
998
|
+
const option = nodeOf('option', '', code === 'auto' ? t('voice.lang.auto') : code)
|
|
999
|
+
option.value = code
|
|
1000
|
+
ui.langSelect.appendChild(option)
|
|
1001
|
+
}
|
|
1002
|
+
const current = catalog && catalog.language ? catalog.language : 'auto'
|
|
1003
|
+
ui.langSelect.value = languages.indexOf(current) >= 0 ? current : languages[0]
|
|
1004
|
+
ui.langSelect.disabled = !languages.length
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
async function refreshSettings() {
|
|
1008
|
+
const stamp = ++settingsStamp
|
|
1009
|
+
if (!host || typeof host.rpc !== 'function') {
|
|
1010
|
+
settingsError = t('voice.unavailable')
|
|
1011
|
+
if (settingsOpen) renderSettings()
|
|
1012
|
+
return
|
|
1013
|
+
}
|
|
1014
|
+
settingsLoading = true
|
|
1015
|
+
settingsError = ''
|
|
1016
|
+
renderSettings()
|
|
1017
|
+
try {
|
|
1018
|
+
const value = await host.rpc('speech.catalog', {}, 15000)
|
|
1019
|
+
if (stamp !== settingsStamp) return
|
|
1020
|
+
catalog = normalizeCatalog(value)
|
|
1021
|
+
catalogState = 'ok'
|
|
1022
|
+
renderMic()
|
|
1023
|
+
} catch (error) {
|
|
1024
|
+
if (stamp !== settingsStamp) return
|
|
1025
|
+
settingsError = t('voice.settings.loadFailed', { msg: reasonOf(error) || t('err.dshError') })
|
|
1026
|
+
} finally {
|
|
1027
|
+
if (stamp === settingsStamp) {
|
|
1028
|
+
settingsLoading = false
|
|
1029
|
+
if (settingsOpen) renderSettings()
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
// 选中指定 provider:先 configure,成功才改本地 catalog,失败 toast 并保持原选中态。
|
|
1035
|
+
async function chooseProvider(providerId) {
|
|
1036
|
+
const payload = configureProviderPatch(providerId)
|
|
1037
|
+
if (!payload || !catalog || settingsBusy) return
|
|
1038
|
+
if (catalog.providerId === payload.patch.providerId) { renderSettings(); return }
|
|
1039
|
+
const previous = catalog.providerId
|
|
1040
|
+
settingsBusy = true
|
|
1041
|
+
try {
|
|
1042
|
+
await host.rpc('speech.configure', payload, 20000)
|
|
1043
|
+
if (catalog) catalog.providerId = payload.patch.providerId
|
|
1044
|
+
// 语言候选随 provider 变化,用主机最新 catalog 覆盖本地选择
|
|
1045
|
+
void probeCatalog()
|
|
1046
|
+
if (settingsOpen) renderSettings()
|
|
1047
|
+
} catch (error) {
|
|
1048
|
+
if (catalog) catalog.providerId = previous
|
|
1049
|
+
toast(t('voice.model.selectFailed', { msg: reasonOf(error) || t('err.dshError') }), 'err')
|
|
1050
|
+
if (settingsOpen) renderSettings()
|
|
1051
|
+
} finally {
|
|
1052
|
+
settingsBusy = false
|
|
1053
|
+
renderMic()
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// 识别语言:payload 固定 {patch:{language}}
|
|
1058
|
+
async function chooseLanguage(language) {
|
|
1059
|
+
const payload = configureLanguagePatch(language)
|
|
1060
|
+
if (!payload || !catalog) return
|
|
1061
|
+
if (catalog.language === payload.patch.language) { renderSettings(); return }
|
|
1062
|
+
const previous = catalog.language
|
|
1063
|
+
try {
|
|
1064
|
+
await host.rpc('speech.configure', payload, 20000)
|
|
1065
|
+
if (catalog) catalog.language = payload.patch.language
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
if (catalog) catalog.language = previous
|
|
1068
|
+
toast(t('voice.lang.selectFailed', { msg: reasonOf(error) || t('err.dshError') }), 'err')
|
|
1069
|
+
}
|
|
1070
|
+
if (settingsOpen) renderSettings()
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// 弹层里的「下载并准备 / 取消」:与内联条共用 beginPreparation + 轮询
|
|
1074
|
+
async function toggleSettingsPrepare() {
|
|
1075
|
+
const provider = selectedProvider()
|
|
1076
|
+
if (!provider || !provider.id || settingsBusy) return
|
|
1077
|
+
const state = providerStatus(provider)
|
|
1078
|
+
if (state.busy || mode === 'preparing') {
|
|
1079
|
+
await cancelPreparation()
|
|
1080
|
+
} else {
|
|
1081
|
+
prepareProviderId = provider.id
|
|
1082
|
+
await beginPreparation()
|
|
1083
|
+
}
|
|
1084
|
+
if (settingsOpen) renderSettings()
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
function openSettings() {
|
|
1088
|
+
const ui = ensureSettings()
|
|
1089
|
+
if (!ui) return false
|
|
1090
|
+
settingsOpen = true
|
|
1091
|
+
settingsError = ''
|
|
1092
|
+
ui.overlay.classList.remove('hidden')
|
|
1093
|
+
ui.correctionText.value = savedCorrections()
|
|
1094
|
+
ui.correctionStatus.textContent = t('voice.correction.saved', { count: parseCorrections(ui.correctionText.value).length })
|
|
1095
|
+
renderSettings()
|
|
1096
|
+
try { if (typeof ui.close.focus === 'function') ui.close.focus() } catch (_) {}
|
|
1097
|
+
void refreshSettings()
|
|
1098
|
+
return true
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
function closeSettings() {
|
|
1102
|
+
settingsOpen = false
|
|
1103
|
+
settingsStamp++
|
|
1104
|
+
settingsLoading = false
|
|
1105
|
+
if (settingsEls && settingsEls.overlay) settingsEls.overlay.classList.add('hidden')
|
|
1106
|
+
}
|
|
1107
|
+
|
|
698
1108
|
/* ---------------- 挂载 / 连接切换 ---------------- */
|
|
699
1109
|
function mount(api) {
|
|
700
1110
|
if (!api || typeof api.rpc !== 'function') return false
|
|
@@ -729,11 +1139,13 @@
|
|
|
729
1139
|
mode = 'idle'
|
|
730
1140
|
hideBar()
|
|
731
1141
|
renderMic()
|
|
1142
|
+
// 弹层开着时换成空 catalog,等新连接的 probeCatalog 回来再重渲染
|
|
1143
|
+
if (settingsOpen) renderSettings()
|
|
732
1144
|
if (!host || (host.token && !host.token())) return
|
|
733
1145
|
void probeCatalog()
|
|
734
1146
|
}
|
|
735
1147
|
|
|
736
|
-
const api = { encodeWav, toBase64, decodeBase64, shouldShowMic, insertAtCursor, mount, reset }
|
|
1148
|
+
const api = { encodeWav, toBase64, decodeBase64, shouldShowMic, insertAtCursor, mount, reset, openSettings, closeSettings }
|
|
737
1149
|
if (typeof module !== 'undefined' && module.exports) module.exports = api
|
|
738
1150
|
else root.DshVoiceInput = api
|
|
739
1151
|
})(typeof window === 'undefined' ? globalThis : window)
|
package/public/workflow.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
function icon(name) {
|
|
12
12
|
const paths={host:'M3 4h18v12H3zM8 21h8m-4-5v5',plugins:'M9 3h6v6h6v6h-6v6H9v-6H3V9h6z',
|
|
13
13
|
receipts:'M6 3h12v18l-3-2-3 2-3-2-3 2zM9 8h6m-6 4h6',general:'M12 3v3m0 12v3M3 12h3m12 0h3M6 6l2 2m8 8 2 2M6 18l2-2M16 8l2-2M16 12a4 4 0 1 1-8 0 4 4 0 0 1 8 0',
|
|
14
|
-
model:'m12 3 9 5-9 5-9-5zM3 12l9 5 9-5M3 16l9 5 9-5',notify:'M6 9a6 6 0 0 1 12 0c0 7 3 7 3 8H3c0-1 3-1 3-8m4 12h4',about:'M12 11v6m0-10v.1M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0'
|
|
14
|
+
model:'m12 3 9 5-9 5-9-5zM3 12l9 5 9-5M3 16l9 5 9-5',notify:'M6 9a6 6 0 0 1 12 0c0 7 3 7 3 8H3c0-1 3-1 3-8m4 12h4',about:'M12 11v6m0-10v.1M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0',
|
|
15
|
+
mic:'M12 3a3 3 0 0 0-3 3v5a3 3 0 0 0 6 0V6a3 3 0 0 0-3-3zM5 11a7 7 0 0 0 14 0M12 18v3.5'}
|
|
15
16
|
const svg=document.createElementNS('http://www.w3.org/2000/svg','svg')
|
|
16
17
|
for(const [key,value] of Object.entries({viewBox:'0 0 24 24',fill:'none',stroke:'currentColor','stroke-width':'1.7','stroke-linecap':'round','stroke-linejoin':'round','aria-hidden':'true'}))svg.setAttribute(key,value)
|
|
17
18
|
const path=document.createElementNS(svg.namespaceURI,'path');path.setAttribute('d',paths[name]||paths.host);svg.append(path);return svg
|
|
@@ -176,6 +177,19 @@
|
|
|
176
177
|
workList.append(plugins,receipts);work.append(workTitle,workList)
|
|
177
178
|
for(const name of ['general','model','notify','about']){const row=home.querySelector(`[data-settings-group="${name}"]`);if(row)preferenceList.append(row)}
|
|
178
179
|
preferences.append(preferenceTitle,preferenceList);home.append(work,preferences)
|
|
180
|
+
// 语音输入设置入口:偏好与维护分组内紧跟「外观与输入」,弹层与内联条齿轮共用 voice-input.js
|
|
181
|
+
// 与同组其它行保持相同结构与字号(图标容器 + 标题/说明两行),单行 span 会显得字号偏大、基线不齐。
|
|
182
|
+
const voiceEntry=element('button','setting-row setting-link'),voiceText=element('div')
|
|
183
|
+
const voiceName=element('div','setting-name'),voiceDesc=element('div','setting-desc')
|
|
184
|
+
voiceEntry.type='button';voiceEntry.id='btn-voice-settings';voiceEntry.dataset.settingsGroup='voice'
|
|
185
|
+
voiceName.dataset.i18n='voice.settings.entry';voiceName.textContent=root.I18N?.t?.('voice.settings.entry')||'语音输入'
|
|
186
|
+
voiceDesc.dataset.i18n='voice.settings.entryDesc';voiceDesc.textContent=root.I18N?.t?.('voice.settings.entryDesc')||'识别模型、语言与术语纠错'
|
|
187
|
+
const voiceMark=element('span','workflow-setting-icon');voiceMark.append(icon('mic'))
|
|
188
|
+
voiceText.append(voiceName,voiceDesc)
|
|
189
|
+
voiceEntry.append(voiceMark,voiceText)
|
|
190
|
+
voiceEntry.addEventListener('click',()=>{root.DshVoiceInput?.openSettings?.()})
|
|
191
|
+
const generalRow=preferenceList.querySelector('[data-settings-group="general"]')
|
|
192
|
+
if(generalRow)generalRow.after(voiceEntry);else preferenceList.prepend(voiceEntry)
|
|
179
193
|
home.querySelector('[data-settings-group="tests"]')?.remove()
|
|
180
194
|
home.querySelector('[data-settings-group="theme"]')?.remove()
|
|
181
195
|
const general=$('settings-page-general'),theme=$('settings-page-theme')
|
|
@@ -400,7 +414,7 @@
|
|
|
400
414
|
'notify','peakRemind','server','servers','servers-v1','servers-v2','sessionSort','showArchivedV1','showTools',
|
|
401
415
|
'steerSendingEnabled','token','workspaceFilterV1','dshRemoteClientIdV2','dshPromptPresets','seenNotesVersion',
|
|
402
416
|
'dshCollapsedGoalsV1','workbenchOrderV1','seenAnnouncementsV1','announcementHistoryV1','announcementVotesV1',
|
|
403
|
-
'dshAdminEnabledHostIPsV1','dshAdminManualHostIPsV1','dshRemoteOperationReceiptsV1','dshRemoteDiagnosticsV1','dshRemoteDiagnosticsV1Salt','dshRemoteOnboardingV1'])
|
|
417
|
+
'dshAdminEnabledHostIPsV1','dshAdminManualHostIPsV1','dshRemoteOperationReceiptsV1','dshRemoteDiagnosticsV1','dshRemoteDiagnosticsV1Salt','dshRemoteOnboardingV1','dsr.voice.corrections'])
|
|
404
418
|
for(const key of Object.keys(localStorage))if(keys.has(key)||/^(?:(?:sessions|history)Cache|dshApprovalRecordsV1:)/.test(key))localStorage.removeItem(key)
|
|
405
419
|
sessionStorage.removeItem('dshRemoteOperationReceiptsV1')
|
|
406
420
|
sessionStorage.removeItem('dshRemoteLayout')
|