dsh-chrome-dictation 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +101 -2
- package/client.js +441 -0
- package/cordis.patch.yml +7 -0
- package/icon.svg +12 -0
- package/index.js +2 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +50 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eric Zhou
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,102 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-chrome-dictation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Dictate into the [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) message
|
|
4
|
+
composer with the speech recognition Chrome already ships. No local model, no dependency
|
|
5
|
+
install: recognition happens in Chrome's speech service.
|
|
6
|
+
|
|
7
|
+
This is a DSH-only plugin: it adds a microphone to the DSH Web composer and has no effect
|
|
8
|
+
outside DeepSeek Harness.
|
|
9
|
+
|
|
10
|
+
## Requirements
|
|
11
|
+
|
|
12
|
+
- DeepSeek Harness `^0.2.3-alpha.2` (Web GUI).
|
|
13
|
+
- Chrome or Edge. Firefox and Safari expose no built-in recognizer; the microphone explains
|
|
14
|
+
that instead of silently doing nothing.
|
|
15
|
+
- A secure page (`localhost` counts) and a network route to Chrome's speech service. That
|
|
16
|
+
service is remote: recognition needs a proxy where the service is blocked.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
**From a plugin index (Discover).** Turn on **Custom plugin indexes** under Experimental
|
|
21
|
+
plugins, open **Plugins → Discover → Add index source**, and add:
|
|
22
|
+
|
|
23
|
+
```text
|
|
24
|
+
https://raw.githubusercontent.com/EricZhou0815/dsh-chrome-dictation/main/index.json
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Where `raw.githubusercontent.com` is unreachable, use the jsDelivr mirror of the same file:
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
https://cdn.jsdelivr.net/gh/EricZhou0815/dsh-chrome-dictation@main/index.json
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**By package name.** Once published to npm, **Plugins → Add plugin** accepts
|
|
34
|
+
`dsh-chrome-dictation`.
|
|
35
|
+
|
|
36
|
+
**From Git.** **Plugins → Add plugin** with a pinned commit:
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
git+https://github.com/EricZhou0815/dsh-chrome-dictation.git#<40-hex-commit>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**From a local directory.** **Plugins → Add plugin** with the checkout path.
|
|
43
|
+
|
|
44
|
+
Installing enables the bundle immediately. Reload the Web page once so the browser half
|
|
45
|
+
loads.
|
|
46
|
+
|
|
47
|
+
## Use it
|
|
48
|
+
|
|
49
|
+
1. Pick the dictation language from the dropdown left of the microphone (中文, English, 粤语,
|
|
50
|
+
繁體, 日本語, 한국어). It starts from the DSH interface language and remembers your choice.
|
|
51
|
+
2. Click the microphone in the composer tool row, next to the model selector.
|
|
52
|
+
3. Speak. The row shows the live partial transcript while it listens.
|
|
53
|
+
4. Click the round stop button to insert the transcript at the caret in the unsent draft, or
|
|
54
|
+
the left close button (or Escape) to throw the recording away. Dictation never submits the
|
|
55
|
+
message.
|
|
56
|
+
|
|
57
|
+
The first use asks for microphone permission; the row says so while the prompt is open. Long
|
|
58
|
+
pauses end recognition on their own, and the finished text is inserted then.
|
|
59
|
+
|
|
60
|
+
## Failures
|
|
61
|
+
|
|
62
|
+
- A denied microphone, a blocked recognition service, and a network failure each show a short
|
|
63
|
+
reason instead of failing silently.
|
|
64
|
+
- Text captured before a failure is kept: the error row offers **Insert** to place it at the
|
|
65
|
+
caret, or **Close** to discard it.
|
|
66
|
+
- If the draft changed while dictating, the transcript is kept the same way instead of landing
|
|
67
|
+
in text the user has since edited.
|
|
68
|
+
- "No speech detected" is a normal outcome: it shows as a neutral note and clears itself.
|
|
69
|
+
|
|
70
|
+
## What it changes in DSH
|
|
71
|
+
|
|
72
|
+
DSH ships an optional **Voice input** bundle whose microphone transcribes locally with
|
|
73
|
+
SenseVoice, installing dependencies and downloading model files on first use. Dictation and
|
|
74
|
+
that microphone share one composer seat, so this bundle's patch disables the shipped
|
|
75
|
+
`ui-voice-input` row while it is installed. Remove this bundle to get the SenseVoice
|
|
76
|
+
microphone back. No recorded audio is kept by either control.
|
|
77
|
+
|
|
78
|
+
## Limits
|
|
79
|
+
|
|
80
|
+
- Chrome and Edge only, secure pages only.
|
|
81
|
+
- Chrome ends a recognition session on a long pause and caps a single session's runtime; long
|
|
82
|
+
dictation needs more than one click.
|
|
83
|
+
- The transcript is plain text: no Markdown, attachments, or automatic submission.
|
|
84
|
+
- The recognizer language is fixed per session; switch the dropdown before you start.
|
|
85
|
+
|
|
86
|
+
## Development
|
|
87
|
+
|
|
88
|
+
| File | Role |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `package.json` | bundle patch plus `dsh.client` declaration |
|
|
91
|
+
| `cordis.patch.yml` | inserts this plugin, disables the shipped `ui-voice-input` |
|
|
92
|
+
| `index.js` | Host half (empty: recognition and rendering live in the browser) |
|
|
93
|
+
| `client.js` | browser half: microphone, language dropdown, Web Speech API |
|
|
94
|
+
| `locale/*.json` | plugin-manager title and description |
|
|
95
|
+
| `icon.svg` | plugin icon |
|
|
96
|
+
|
|
97
|
+
The browser half ships as plain JavaScript for the DSH client module loader; there is no
|
|
98
|
+
build step. After editing `client.js`, reload the DSH Web page.
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT
|
package/client.js
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-chrome-dictation',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const { useEffect, useRef, useState } = React
|
|
6
|
+
const h = React.createElement
|
|
7
|
+
|
|
8
|
+
const NS = 'chrome-dictation'
|
|
9
|
+
|
|
10
|
+
const zh = {
|
|
11
|
+
start: '语音输入(Chrome 内置识别,无需下载)',
|
|
12
|
+
stop: '停止并插入',
|
|
13
|
+
cancel: '取消听写',
|
|
14
|
+
close: '关闭',
|
|
15
|
+
insert: '插入',
|
|
16
|
+
waiting: '等待麦克风授权…',
|
|
17
|
+
listening: '正在听写…',
|
|
18
|
+
empty: '没有识别到语音。',
|
|
19
|
+
conflict: '草稿已变化,转写文字没有插入。',
|
|
20
|
+
denied: '麦克风被拒绝,请在地址栏允许麦克风后重试。',
|
|
21
|
+
blocked: '浏览器禁止了语音识别服务。',
|
|
22
|
+
network: '连不上 Chrome 的语音识别服务,请检查网络或代理。',
|
|
23
|
+
noMic: '找不到麦克风设备。',
|
|
24
|
+
unavailable: '语音识别服务不可用,请稍后重试。',
|
|
25
|
+
unsupported: '当前浏览器没有 Chrome 内置语音识别,请用 Chrome 或 Edge 打开。',
|
|
26
|
+
failed: '语音识别失败({message})',
|
|
27
|
+
language: '听写语言:{language}',
|
|
28
|
+
languageLabel: '听写语言',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const en = {
|
|
32
|
+
start: 'Dictate with Chrome (no download)',
|
|
33
|
+
stop: 'Stop and insert',
|
|
34
|
+
cancel: 'Cancel dictation',
|
|
35
|
+
close: 'Close',
|
|
36
|
+
insert: 'Insert',
|
|
37
|
+
waiting: 'Waiting for the microphone…',
|
|
38
|
+
listening: 'Listening…',
|
|
39
|
+
empty: 'No speech was detected.',
|
|
40
|
+
conflict: 'The draft changed, so the transcript was not inserted.',
|
|
41
|
+
denied: 'Microphone access was denied. Allow it in the address bar and try again.',
|
|
42
|
+
blocked: 'The browser blocked its speech recognition service.',
|
|
43
|
+
network: 'Chrome could not reach its speech service. Check the network or proxy.',
|
|
44
|
+
noMic: 'No microphone was found.',
|
|
45
|
+
unavailable: 'The speech service is unavailable. Try again later.',
|
|
46
|
+
unsupported: 'This browser has no built-in Chrome speech recognition. Open DSH in Chrome or Edge.',
|
|
47
|
+
failed: 'Speech recognition failed ({message})',
|
|
48
|
+
language: 'Dictation language: {language}',
|
|
49
|
+
languageLabel: 'Dictation language',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Chrome exposes the recognizer under a vendor prefix; other engines have none. */
|
|
53
|
+
function Recognition() {
|
|
54
|
+
return window.SpeechRecognition || window.webkitSpeechRecognition || undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Recognizer languages offered by the dropdown; add a row to offer more. */
|
|
58
|
+
const LANGUAGES = [
|
|
59
|
+
{ tag: 'zh-CN', label: '中文' },
|
|
60
|
+
{ tag: 'en-US', label: 'English' },
|
|
61
|
+
{ tag: 'zh-HK', label: '粤语' },
|
|
62
|
+
{ tag: 'zh-TW', label: '繁體' },
|
|
63
|
+
{ tag: 'ja-JP', label: '日本語' },
|
|
64
|
+
{ tag: 'ko-KR', label: '한국어' },
|
|
65
|
+
]
|
|
66
|
+
const STORAGE_KEY = 'dsh.chrome-dictation.lang'
|
|
67
|
+
|
|
68
|
+
/** Map a DSH locale or browser language onto a recognizer tag; empty means "no opinion". */
|
|
69
|
+
function speechLanguage(tag) {
|
|
70
|
+
const raw = String(tag || '').toLowerCase()
|
|
71
|
+
if (raw === '') return ''
|
|
72
|
+
if (raw.startsWith('yue')) return 'zh-HK'
|
|
73
|
+
if (raw.startsWith('zh')) return raw.includes('-hk') ? 'zh-HK' : raw.includes('-tw') ? 'zh-TW' : 'zh-CN'
|
|
74
|
+
if (raw.startsWith('ja')) return 'ja-JP'
|
|
75
|
+
if (raw.startsWith('ko')) return 'ko-KR'
|
|
76
|
+
if (raw.startsWith('en')) return 'en-US'
|
|
77
|
+
return raw.includes('-') ? String(tag) : ''
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Keep only languages the dropdown can show, so the select never renders blank. */
|
|
81
|
+
function knownLanguage(tag) {
|
|
82
|
+
return LANGUAGES.some((item) => item.tag === tag) ? tag : ''
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function labelOf(tag) {
|
|
86
|
+
const known = LANGUAGES.find((item) => item.tag === tag)
|
|
87
|
+
return known ? known.label : tag
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function storedLanguage() {
|
|
91
|
+
try {
|
|
92
|
+
const stored = window.localStorage.getItem(STORAGE_KEY)
|
|
93
|
+
return stored === null || stored === '' ? '' : stored
|
|
94
|
+
} catch (_error) { return '' }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function storeLanguage(tag) {
|
|
98
|
+
try { window.localStorage.setItem(STORAGE_KEY, tag) } catch (_error) { /* private mode */ }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Chosen language, else the DSH interface language, else the page and browser language. */
|
|
102
|
+
function initialLanguage(readLocale) {
|
|
103
|
+
const stored = knownLanguage(storedLanguage())
|
|
104
|
+
if (stored !== '') return stored
|
|
105
|
+
const page = (typeof document !== 'undefined' && document.documentElement.lang) || ''
|
|
106
|
+
const browser = (typeof navigator !== 'undefined' && navigator.language) || ''
|
|
107
|
+
const candidates = [typeof readLocale === 'function' ? readLocale() : '', page, browser]
|
|
108
|
+
for (const candidate of candidates) {
|
|
109
|
+
const mapped = knownLanguage(speechLanguage(candidate))
|
|
110
|
+
if (mapped !== '') return mapped
|
|
111
|
+
}
|
|
112
|
+
return 'en-US'
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function messageFor(error, t) {
|
|
116
|
+
if (error === 'not-allowed') return t('denied')
|
|
117
|
+
if (error === 'service-not-allowed') return t('blocked')
|
|
118
|
+
if (error === 'network') return t('network')
|
|
119
|
+
if (error === 'audio-capture') return t('noMic')
|
|
120
|
+
if (error === 'no-speech') return t('empty')
|
|
121
|
+
if (error === 'language-not-supported' || error === 'service-unavailable') return t('unavailable')
|
|
122
|
+
return t('failed', { message: error || 'unknown' })
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const micIcon = h('svg', {
|
|
126
|
+
width: 18, height: 18, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
|
|
127
|
+
strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
|
|
128
|
+
}, h('rect', { x: 9, y: 3, width: 6, height: 11, rx: 3 }), h('path', { d: 'M5 11a7 7 0 0 0 14 0' }), h('path', { d: 'M12 18v3' }))
|
|
129
|
+
|
|
130
|
+
const stopIcon = h('svg', {
|
|
131
|
+
width: 14, height: 14, viewBox: '0 0 24 24', fill: 'currentColor', 'aria-hidden': true,
|
|
132
|
+
}, h('rect', { x: 7, y: 7, width: 10, height: 10, rx: 2 }))
|
|
133
|
+
|
|
134
|
+
const caretIcon = h('svg', {
|
|
135
|
+
width: 10, height: 10, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
|
|
136
|
+
strokeWidth: 2.4, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
|
|
137
|
+
}, h('path', { d: 'M6 9l6 6 6-6' }))
|
|
138
|
+
|
|
139
|
+
const closeIcon = h('svg', {
|
|
140
|
+
width: 14, height: 14, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
|
|
141
|
+
strokeWidth: 2, strokeLinecap: 'round', 'aria-hidden': true,
|
|
142
|
+
}, h('path', { d: 'M6 6l12 12' }), h('path', { d: 'M18 6L6 18' }))
|
|
143
|
+
|
|
144
|
+
const css = `
|
|
145
|
+
.bd-anchor { display: inline-flex; align-items: center; gap: 2px; flex: none; }
|
|
146
|
+
.bd-select { position: relative; display: inline-flex; align-items: center; flex: none; }
|
|
147
|
+
.bd-lang { max-width: 84px; height: 24px; padding: 0 15px 0 6px; flex: none; border: 0; border-radius: 6px;
|
|
148
|
+
appearance: none; -webkit-appearance: none; background: transparent;
|
|
149
|
+
color: var(--dsw-alias-label-secondary); font: inherit; font-size: 12px; line-height: 24px;
|
|
150
|
+
text-overflow: ellipsis; cursor: pointer; }
|
|
151
|
+
.bd-lang:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-2));
|
|
152
|
+
color: var(--dsw-alias-label-primary); }
|
|
153
|
+
.bd-lang:disabled { opacity: .45; cursor: not-allowed; }
|
|
154
|
+
.bd-caret { position: absolute; right: 3px; display: inline-flex; pointer-events: none;
|
|
155
|
+
color: var(--dsw-alias-label-tertiary); }
|
|
156
|
+
.bd-trigger { width: 28px; height: 28px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
|
|
157
|
+
flex: none; border: 0; border-radius: 8px; background: transparent; color: var(--dsw-alias-label-primary); cursor: pointer; }
|
|
158
|
+
.bd-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-2)); }
|
|
159
|
+
.bd-trigger:disabled { opacity: .45; cursor: not-allowed; }
|
|
160
|
+
.bd-row { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; min-height: 34px; }
|
|
161
|
+
.bd-round { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
|
|
162
|
+
flex: none; border: 0; border-radius: 50%; background: var(--dsw-specific-selector, var(--dsw-alias-bg-layer-1));
|
|
163
|
+
color: var(--dsw-alias-label-secondary); cursor: pointer; }
|
|
164
|
+
.bd-round:hover { background: var(--dsw-alias-interactive-bg-hover-solid, var(--dsw-alias-interactive-bg-hover));
|
|
165
|
+
color: var(--dsw-alias-label-primary); }
|
|
166
|
+
.bd-live { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
|
|
167
|
+
font-size: 12px; color: var(--dsw-alias-label-secondary); }
|
|
168
|
+
.bd-text { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
169
|
+
.bd-dot { width: 8px; height: 8px; flex: none; border-radius: 50%;
|
|
170
|
+
background: var(--dsw-alias-state-business-primary, var(--dsw-alias-brand-primary));
|
|
171
|
+
animation: bd-pulse 1.2s ease-in-out infinite; }
|
|
172
|
+
.bd-error { flex: 1; min-width: 0; color: var(--dsw-alias-state-error-primary); font-size: 12px;
|
|
173
|
+
white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
174
|
+
.bd-notice { flex: 1; min-width: 0; color: var(--dsw-alias-label-secondary); font-size: 12px;
|
|
175
|
+
white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
176
|
+
.bd-action { flex: none; padding: 4px 10px; border: 0; border-radius: 6px; background: transparent;
|
|
177
|
+
color: var(--dsw-alias-state-business-primary, var(--dsw-alias-brand-primary)); font: inherit; font-size: 12px; cursor: pointer; }
|
|
178
|
+
.bd-action:hover { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-2)); }
|
|
179
|
+
@keyframes bd-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
|
|
180
|
+
@media (prefers-reduced-motion: reduce) { .bd-dot { animation: none; } }
|
|
181
|
+
`
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* One microphone control that streams microphone audio through the browser's
|
|
185
|
+
* built-in recognizer and inserts the final transcript into the unsent draft.
|
|
186
|
+
*/
|
|
187
|
+
function Dictation({ inputActions, onActiveChange, locked, readLocale, t }) {
|
|
188
|
+
const translate = typeof t === 'function' ? t : (key) => en[key] || key
|
|
189
|
+
const supported = Recognition() !== undefined
|
|
190
|
+
const [language, setLanguage] = useState(() => initialLanguage(readLocale))
|
|
191
|
+
const [phase, setPhase] = useState('idle')
|
|
192
|
+
const [interim, setInterim] = useState('')
|
|
193
|
+
const [notice, setNotice] = useState('')
|
|
194
|
+
const [failure, setFailure] = useState('')
|
|
195
|
+
const [pending, setPending] = useState('')
|
|
196
|
+
const recognition = useRef(null)
|
|
197
|
+
const finals = useRef('')
|
|
198
|
+
const interimRef = useRef('')
|
|
199
|
+
const failureRef = useRef('')
|
|
200
|
+
const generation = useRef(0)
|
|
201
|
+
const started = useRef(false)
|
|
202
|
+
const span = useRef(null)
|
|
203
|
+
const stopButton = useRef(null)
|
|
204
|
+
|
|
205
|
+
const dismiss = () => {
|
|
206
|
+
setFailure('')
|
|
207
|
+
setPending('')
|
|
208
|
+
setNotice('')
|
|
209
|
+
setPhase('idle')
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Settle one recognition run: report its failure, its empty result, or insert its text. */
|
|
213
|
+
const finalize = (reason) => {
|
|
214
|
+
const active = recognition.current
|
|
215
|
+
recognition.current = undefined
|
|
216
|
+
generation.current += 1
|
|
217
|
+
if (active) { active.onresult = null; active.onerror = null; active.onend = null }
|
|
218
|
+
const text = (finals.current + interimRef.current).trim()
|
|
219
|
+
finals.current = ''
|
|
220
|
+
interimRef.current = ''
|
|
221
|
+
setInterim('')
|
|
222
|
+
if (reason === 'error') {
|
|
223
|
+
const message = failureRef.current || translate('failed', { message: 'unknown' })
|
|
224
|
+
failureRef.current = ''
|
|
225
|
+
setPending(text)
|
|
226
|
+
setFailure(message)
|
|
227
|
+
setPhase('error')
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
if (text === '') {
|
|
231
|
+
setNotice(translate('empty'))
|
|
232
|
+
setPhase('notice')
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
if (span.current && inputActions.insertText(text, span.current)) { setPhase('idle'); return }
|
|
236
|
+
setPending(text)
|
|
237
|
+
setFailure(translate('conflict'))
|
|
238
|
+
setPhase('error')
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const cancel = () => {
|
|
242
|
+
const active = recognition.current
|
|
243
|
+
recognition.current = undefined
|
|
244
|
+
generation.current += 1
|
|
245
|
+
if (active) {
|
|
246
|
+
active.onresult = null
|
|
247
|
+
active.onerror = null
|
|
248
|
+
active.onend = null
|
|
249
|
+
try { active.abort() } catch (_error) { /* already ended */ }
|
|
250
|
+
}
|
|
251
|
+
finals.current = ''
|
|
252
|
+
interimRef.current = ''
|
|
253
|
+
failureRef.current = ''
|
|
254
|
+
setInterim('')
|
|
255
|
+
dismiss()
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const stop = () => {
|
|
259
|
+
const active = recognition.current
|
|
260
|
+
if (!active) return
|
|
261
|
+
if (!started.current) { cancel(); return }
|
|
262
|
+
try { active.stop() } catch (_error) { finalize('auto') }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const insertPending = () => {
|
|
266
|
+
if (pending === '') return
|
|
267
|
+
if (inputActions.insertText(pending, inputActions.captureInsertion())) dismiss()
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const start = () => {
|
|
271
|
+
const Ctor = Recognition()
|
|
272
|
+
if (!Ctor || locked || recognition.current) return
|
|
273
|
+
const active = new Ctor()
|
|
274
|
+
const run = ++generation.current
|
|
275
|
+
finals.current = ''
|
|
276
|
+
interimRef.current = ''
|
|
277
|
+
failureRef.current = ''
|
|
278
|
+
started.current = false
|
|
279
|
+
span.current = inputActions.captureInsertion()
|
|
280
|
+
setInterim('')
|
|
281
|
+
setNotice('')
|
|
282
|
+
setFailure('')
|
|
283
|
+
setPending('')
|
|
284
|
+
recognition.current = active
|
|
285
|
+
active.lang = language
|
|
286
|
+
active.continuous = true
|
|
287
|
+
active.interimResults = true
|
|
288
|
+
active.maxAlternatives = 1
|
|
289
|
+
active.onstart = () => {
|
|
290
|
+
if (run !== generation.current) return
|
|
291
|
+
started.current = true
|
|
292
|
+
setPhase('listening')
|
|
293
|
+
}
|
|
294
|
+
active.onresult = (event) => {
|
|
295
|
+
if (run !== generation.current) return
|
|
296
|
+
if (!started.current) { started.current = true; setPhase('listening') }
|
|
297
|
+
let live = ''
|
|
298
|
+
for (let index = event.resultIndex; index < event.results.length; index += 1) {
|
|
299
|
+
const result = event.results[index]
|
|
300
|
+
const text = result[0] ? result[0].transcript : ''
|
|
301
|
+
if (result.isFinal) finals.current += text
|
|
302
|
+
else live += text
|
|
303
|
+
}
|
|
304
|
+
interimRef.current = live
|
|
305
|
+
setInterim(live)
|
|
306
|
+
}
|
|
307
|
+
active.onerror = (event) => {
|
|
308
|
+
if (run !== generation.current) return
|
|
309
|
+
if (event.error === 'aborted') return
|
|
310
|
+
failureRef.current = messageFor(event.error, translate)
|
|
311
|
+
finalize('error')
|
|
312
|
+
}
|
|
313
|
+
active.onend = () => {
|
|
314
|
+
if (run !== generation.current) return
|
|
315
|
+
finalize('auto')
|
|
316
|
+
}
|
|
317
|
+
setPhase('requesting')
|
|
318
|
+
try { active.start() } catch (error) {
|
|
319
|
+
recognition.current = undefined
|
|
320
|
+
generation.current += 1
|
|
321
|
+
setFailure(translate('failed', { message: String(error) }))
|
|
322
|
+
setPhase('error')
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
useEffect(() => {
|
|
327
|
+
onActiveChange(phase !== 'idle')
|
|
328
|
+
return () => { onActiveChange(false) }
|
|
329
|
+
}, [phase, onActiveChange])
|
|
330
|
+
|
|
331
|
+
useEffect(() => () => {
|
|
332
|
+
const active = recognition.current
|
|
333
|
+
recognition.current = undefined
|
|
334
|
+
generation.current += 1
|
|
335
|
+
if (active) {
|
|
336
|
+
active.onresult = null
|
|
337
|
+
active.onerror = null
|
|
338
|
+
active.onend = null
|
|
339
|
+
try { active.abort() } catch (_error) { /* already ended */ }
|
|
340
|
+
}
|
|
341
|
+
finals.current = ''
|
|
342
|
+
interimRef.current = ''
|
|
343
|
+
}, [])
|
|
344
|
+
|
|
345
|
+
useEffect(() => {
|
|
346
|
+
if (phase === 'listening' && stopButton.current) stopButton.current.focus()
|
|
347
|
+
}, [phase])
|
|
348
|
+
|
|
349
|
+
useEffect(() => {
|
|
350
|
+
if (phase !== 'notice') return undefined
|
|
351
|
+
const timer = setTimeout(() => { setPhase('idle') }, 2600)
|
|
352
|
+
return () => clearTimeout(timer)
|
|
353
|
+
}, [phase])
|
|
354
|
+
|
|
355
|
+
useEffect(() => {
|
|
356
|
+
if (phase === 'idle') return undefined
|
|
357
|
+
const escape = (event) => {
|
|
358
|
+
if (event.key !== 'Escape') return
|
|
359
|
+
event.preventDefault()
|
|
360
|
+
if (phase === 'requesting' || phase === 'listening') cancel()
|
|
361
|
+
else dismiss()
|
|
362
|
+
}
|
|
363
|
+
const hidden = () => {
|
|
364
|
+
if (document.hidden && (phase === 'requesting' || phase === 'listening')) cancel()
|
|
365
|
+
}
|
|
366
|
+
document.addEventListener('keydown', escape)
|
|
367
|
+
document.addEventListener('visibilitychange', hidden)
|
|
368
|
+
return () => {
|
|
369
|
+
document.removeEventListener('keydown', escape)
|
|
370
|
+
document.removeEventListener('visibilitychange', hidden)
|
|
371
|
+
}
|
|
372
|
+
}, [phase])
|
|
373
|
+
|
|
374
|
+
if (phase === 'requesting' || phase === 'listening') {
|
|
375
|
+
const label = interim || translate(phase === 'requesting' ? 'waiting' : 'listening')
|
|
376
|
+
return h('div', { className: 'bd-row', 'data-chrome-dictation': phase },
|
|
377
|
+
h('style', null, css),
|
|
378
|
+
h('button', { type: 'button', className: 'bd-round', 'aria-label': translate('cancel'),
|
|
379
|
+
title: translate('cancel'), onClick: cancel }, closeIcon),
|
|
380
|
+
h('span', { className: 'bd-live', role: 'status', 'aria-live': 'polite', title: label },
|
|
381
|
+
h('span', { className: 'bd-dot' }),
|
|
382
|
+
h('span', { className: 'bd-text' }, label)),
|
|
383
|
+
h('button', { ref: stopButton, type: 'button', className: 'bd-round', 'aria-label': translate('stop'),
|
|
384
|
+
title: translate('stop'), onClick: stop }, stopIcon))
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (phase === 'error') {
|
|
388
|
+
return h('div', { className: 'bd-row', 'data-chrome-dictation': 'error' },
|
|
389
|
+
h('style', null, css),
|
|
390
|
+
h('span', { className: 'bd-error', role: 'alert', title: failure }, failure),
|
|
391
|
+
pending === '' ? null : h('button', { type: 'button', className: 'bd-action', onClick: insertPending },
|
|
392
|
+
translate('insert')),
|
|
393
|
+
h('button', { type: 'button', className: 'bd-round', 'aria-label': translate('close'),
|
|
394
|
+
title: translate('close'), onClick: dismiss }, closeIcon))
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (phase === 'notice') {
|
|
398
|
+
return h('div', { className: 'bd-row', 'data-chrome-dictation': 'notice' },
|
|
399
|
+
h('style', null, css),
|
|
400
|
+
h('span', { className: 'bd-notice', role: 'status' }, notice))
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const hint = supported ? translate('start') : translate('unsupported')
|
|
404
|
+
const chooseLanguage = (event) => {
|
|
405
|
+
const chosen = knownLanguage(event.target.value)
|
|
406
|
+
if (chosen === '') return
|
|
407
|
+
setLanguage(chosen)
|
|
408
|
+
storeLanguage(chosen)
|
|
409
|
+
}
|
|
410
|
+
return h('div', null,
|
|
411
|
+
h('style', null, css),
|
|
412
|
+
h('span', { className: 'bd-anchor' },
|
|
413
|
+
h('span', { className: 'bd-select' },
|
|
414
|
+
h('select', { className: 'bd-lang', value: language, disabled: locked,
|
|
415
|
+
title: translate('language', { language: labelOf(language) }),
|
|
416
|
+
'aria-label': translate('languageLabel'),
|
|
417
|
+
onChange: chooseLanguage },
|
|
418
|
+
LANGUAGES.map((item) => h('option', { key: item.tag, value: item.tag }, item.label))),
|
|
419
|
+
h('span', { className: 'bd-caret', 'aria-hidden': true }, caretIcon)),
|
|
420
|
+
h('button', { type: 'button', className: 'bd-trigger', disabled: locked,
|
|
421
|
+
title: hint, 'aria-label': hint, onMouseDown: (event) => { event.preventDefault() },
|
|
422
|
+
onClick: () => {
|
|
423
|
+
if (supported) start()
|
|
424
|
+
else { setFailure(translate('unsupported')); setPhase('error') }
|
|
425
|
+
} }, micIcon)))
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return {
|
|
429
|
+
inject: ['slots', 'locale'],
|
|
430
|
+
apply(ctx) {
|
|
431
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }))
|
|
432
|
+
const readLocale = () => ctx.locale.getLocale().active
|
|
433
|
+
ctx.slots.inject('conversation.input.activity', () => ctx.slots.register({
|
|
434
|
+
name: 'conversation.input.activity',
|
|
435
|
+
locale: NS,
|
|
436
|
+
inject: () => ({ readLocale }),
|
|
437
|
+
}, Dictation))
|
|
438
|
+
},
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
})
|
package/cordis.patch.yml
ADDED
package/icon.svg
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bd-mic" x1="11" y1="8" x2="26" y2="29" gradientUnits="userSpaceOnUse">
|
|
4
|
+
<stop stop-color="#67C7FE" />
|
|
5
|
+
<stop offset="1" stop-color="#3F77D8" />
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect x="14.5" y="6" width="7" height="13.5" rx="3.5" fill="url(#bd-mic)" />
|
|
9
|
+
<path d="M10.5 17.5a7.5 7.5 0 0 0 15 0" stroke="url(#bd-mic)" stroke-width="2.4" stroke-linecap="round" />
|
|
10
|
+
<path d="M18 25.2v3.3" stroke="url(#bd-mic)" stroke-width="2.4" stroke-linecap="round" />
|
|
11
|
+
<path d="M14.6 30h6.8" stroke="url(#bd-mic)" stroke-width="2.4" stroke-linecap="round" />
|
|
12
|
+
</svg>
|
package/index.js
ADDED
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "DSH Chrome dictation",
|
|
4
|
+
"description": "Dictate into the DeepSeek Harness message composer with the speech recognition Chrome already ships, so dictation needs no local model and no dependency download. Click the microphone, speak, and click stop; the transcript is inserted at the caret in the unsent draft. The language dropdown beside the microphone offers 中文, English, 粤语, 繁體, 日本語 and 한국어; it starts from the DSH interface language and remembers the language you pick. Installing this bundle disables the shipped Voice input microphone, which transcribes locally with SenseVoice and downloads its runtime on first use, so the composer keeps one dictation control; removing this bundle restores it. Chrome sends the audio to its speech service, so recognition needs a network connection (and a proxy where that service is blocked outside Chrome's reach) and works only in Chrome or Edge on a secure page. Nothing is transcribed offline."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "DSH Chrome 语音输入",
|
|
4
|
+
"description": "用 Chrome 自带的语音识别在 DeepSeek Harness 的输入框里听写,不需要下载本地模型,也不需要安装依赖。点麦克风后说话,再点停止,转写结果会插入到草稿的光标处,不会自动发送。麦克风左边的语言下拉框提供中文、English、粤语、繁體、日本語、한국어;默认跟随 DSH 界面语言,并记住你选过的语言。安装这个插件会禁用官方的 Voice input 麦克风(那个用本地 SenseVoice 转写、首次使用要下载运行时),所以输入框只保留一个语音入口;移除插件后它会恢复。Chrome 会把音频发给它的语音服务,因此识别需要联网(该服务访问不到的地区还需要代理),且只在 Chrome 或 Edge 的安全页面上可用;识别不是离线完成的。"
|
|
5
|
+
}
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-chrome-dictation",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Dictate into the DeepSeek Harness message composer with Chrome's built-in speech recognition; no local model or dependency download.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"dsh": "^0.2.3-alpha.2"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./index.js",
|
|
11
|
+
"./client": "./client.js",
|
|
12
|
+
"./locale/*.json": "./locale/*.json",
|
|
13
|
+
"./icon": "./icon.svg"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"index.js",
|
|
17
|
+
"client.js",
|
|
18
|
+
"cordis.patch.yml",
|
|
19
|
+
"locale/*.json",
|
|
20
|
+
"icon.svg",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"dsh",
|
|
26
|
+
"dsh-plugin",
|
|
27
|
+
"deepseek-harness",
|
|
28
|
+
"dictation",
|
|
29
|
+
"voice-input",
|
|
30
|
+
"speech-recognition",
|
|
31
|
+
"web-speech-api",
|
|
32
|
+
"chrome"
|
|
33
|
+
],
|
|
34
|
+
"author": "Eric Zhou",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"homepage": "https://github.com/EricZhou0815/dsh-chrome-dictation#readme",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/EricZhou0815/dsh-chrome-dictation.git"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"dsh": {
|
|
45
|
+
"bundle": { "patch": "./cordis.patch.yml" },
|
|
46
|
+
"client": {
|
|
47
|
+
"platform": "web",
|
|
48
|
+
"immediately": true,
|
|
49
|
+
"inject": ["@deepseek-ai/dsh-client-ui-conversation"]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|