dsh-voice-input-ru 0.0.0-stage → 0.1.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 +102 -2
- package/README.ru.md +103 -0
- package/assets/screenshot-1.png +0 -0
- package/assets/screenshot-2.png +0 -0
- package/cordis.patch.yml +6 -0
- package/lib/client.js +335 -0
- package/lib/index.js +12 -0
- package/package.json +79 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vladimir Toropov
|
|
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,103 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-voice-input-ru
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Русская версия](README.ru.md)
|
|
4
|
+
|
|
5
|
+
A microphone button for the [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)
|
|
6
|
+
(`dsh`) Web UI composer. Speech is recognized by the browser's standard
|
|
7
|
+
**Web Speech API** (`SpeechRecognition` / `webkitSpeechRecognition`) and the
|
|
8
|
+
final transcript is appended to the message draft. The recognition language
|
|
9
|
+
defaults to Russian (`ru-RU`) and can be switched at runtime without a rebuild.
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
## What it does
|
|
15
|
+
|
|
16
|
+
- Adds one button to the composer seat `conversation.input.right` — next to the
|
|
17
|
+
input, before the send button. The shipped UI is not replaced; the button is
|
|
18
|
+
an additive entry in that seat.
|
|
19
|
+
- One press starts a single-utterance recognition session; pressing again ends
|
|
20
|
+
it early. When you stop speaking the browser finishes the session itself.
|
|
21
|
+
- The final transcript is **appended to the draft** (with a separating space
|
|
22
|
+
when the field already has text). Sending stays manual — the plugin never
|
|
23
|
+
submits a message.
|
|
24
|
+
- The button has clear states: idle, listening (pulsing), error (microphone
|
|
25
|
+
permission, no microphone, network) and unsupported (no Web Speech API in
|
|
26
|
+
this browser — the button renders disabled with an explanatory tooltip).
|
|
27
|
+
- Styling uses only the host's semantic tokens (`--dsw-alias-*`), so it follows
|
|
28
|
+
light and dark themes; the stylesheet is scoped to
|
|
29
|
+
`[data-plugin="dsh-voice-input-ru"]` and removed when the plugin stops.
|
|
30
|
+
- Accessibility: `aria-label`, `aria-pressed`, visible focus ring, reduced
|
|
31
|
+
motion.
|
|
32
|
+
|
|
33
|
+
## Requirements
|
|
34
|
+
|
|
35
|
+
- `dsh` 0.2.1 or newer with the Web client bundle (developed against
|
|
36
|
+
`0.1.2-rc.1`, verified on `0.2.1-rc.2`). The slot name and the
|
|
37
|
+
`slots.register({ name, id, order }, component)` API are checked there.
|
|
38
|
+
- A browser that implements the Web Speech API: **Chrome** or **Edge**.
|
|
39
|
+
Safari and Firefox do not ship `SpeechRecognition`, and the button stays
|
|
40
|
+
disabled there.
|
|
41
|
+
- Network access: Chromium sends the audio to its own speech service for
|
|
42
|
+
recognition. **Recognition is not local** — nothing is uploaded by this
|
|
43
|
+
plugin itself, but the browser vendor's service receives the audio.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
dsh plugin --profile web add dsh-voice-input-ru
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Or from the repository source:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
dsh plugin --profile web add https://github.com/VToropov1337/dsh-voice-input-ru
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Restart the web interface afterwards — client bundles are scanned when the
|
|
58
|
+
host starts. Then a microphone button appears next to the composer.
|
|
59
|
+
|
|
60
|
+
## Change the recognition language
|
|
61
|
+
|
|
62
|
+
Russian is the default. Any other BCP-47 tag is applied without rebuilding —
|
|
63
|
+
set the `localStorage` entry and start dictating:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
localStorage.setItem('dsh-voice-input-ru:language', 'en-US')
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The value is validated (BCP-47 shape) and re-read on every start, so the next
|
|
70
|
+
dictation uses the new language. A tag the browser cannot recognize produces a
|
|
71
|
+
`language-not-supported` error on the button. To go back to the default:
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
localStorage.removeItem('dsh-voice-input-ru:language')
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Structure
|
|
78
|
+
|
|
79
|
+
| File | Purpose |
|
|
80
|
+
|---|---|
|
|
81
|
+
| `src/host/index.ts` | Host half: an empty `apply`, so the package exists as a loader row |
|
|
82
|
+
| `src/client/index.ts` | Browser half: slot registration and stylesheet injection |
|
|
83
|
+
| `src/client/MicSeat.tsx` | The button component and the recognition state machine |
|
|
84
|
+
| `src/client/speech.ts` | Structural typings for the Web Speech API and constructor lookup |
|
|
85
|
+
| `src/client/styles.ts` | CSS (host tokens) plus injection/removal of the `<style>` element |
|
|
86
|
+
| `cordis.patch.yml` | Loader row for this package (`dsh.bundle.patch`) |
|
|
87
|
+
| `tsdown.config.ts` | Build: host ESM + client CJS bundle for the `__ModuleLoader__` handoff |
|
|
88
|
+
|
|
89
|
+
The client bundle requires only `react` and `react/jsx-runtime` from the
|
|
90
|
+
platform's frozen browser module table and injects the `slots` service.
|
|
91
|
+
|
|
92
|
+
## Development
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
npm install --no-audit --no-fund --cache .npm-cache
|
|
96
|
+
npm run typecheck # tsc --noEmit
|
|
97
|
+
npm run build # tsdown -> lib/index.js + lib/client.js
|
|
98
|
+
scripts/register.sh # build + register in the local `web` profile
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT — see [LICENSE](LICENSE).
|
package/README.ru.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# dsh-voice-input-ru
|
|
2
|
+
|
|
3
|
+
[English version](README.md)
|
|
4
|
+
|
|
5
|
+
Кнопка микрофона в композере веб-интерфейса
|
|
6
|
+
[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (`dsh`).
|
|
7
|
+
Распознавание речи выполняет стандартный браузерный **Web Speech API**
|
|
8
|
+
(`SpeechRecognition` / `webkitSpeechRecognition`), финальный распознанный текст
|
|
9
|
+
добавляется в черновик сообщения. Язык распознавания по умолчанию — русский
|
|
10
|
+
(`ru-RU`); другой включается на ходу, без пересборки.
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## Что делает
|
|
16
|
+
|
|
17
|
+
- Добавляет одну кнопку в слот композера `conversation.input.right` — рядом с
|
|
18
|
+
полем ввода, перед кнопкой отправки. Официальный UI не заменяется: кнопка
|
|
19
|
+
аддитивная запись в этот слот.
|
|
20
|
+
- Одно нажатие начинает сессию распознавания одного высказывания; повторное
|
|
21
|
+
нажатие завершает её досрочно. Когда вы замолкаете, браузер завершает сессию
|
|
22
|
+
сам.
|
|
23
|
+
- Финальный текст **добавляется в черновик** (с разделяющим пробелом, если в
|
|
24
|
+
поле уже есть текст). Отправка остаётся ручной — плагин никогда не отправляет
|
|
25
|
+
сообщение сам.
|
|
26
|
+
- Состояния кнопки: ожидание, слушает (пульсация), ошибка (доступ к микрофону,
|
|
27
|
+
нет микрофона, сеть) и «не поддерживается» (в браузере нет Web Speech API —
|
|
28
|
+
кнопка неактивна, причина в tooltip).
|
|
29
|
+
- Оформление — только на семантических токенах хоста (`--dsw-alias-*`), поэтому
|
|
30
|
+
работает в светлой и тёмной темах; стили ограничены
|
|
31
|
+
`[data-plugin="dsh-voice-input-ru"]` и удаляются при остановке плагина.
|
|
32
|
+
- Доступность: `aria-label`, `aria-pressed`, видимый фокус, reduced motion.
|
|
33
|
+
|
|
34
|
+
## Требования
|
|
35
|
+
|
|
36
|
+
- `dsh` 0.2.1 или новее с веб-клиентом (разработано против `0.1.2-rc.1`,
|
|
37
|
+
проверено на `0.2.1-rc.2`): имя слота и API
|
|
38
|
+
`slots.register({ name, id, order }, component)`.
|
|
39
|
+
- Браузер с Web Speech API: **Chrome** или **Edge**. В Safari и Firefox
|
|
40
|
+
`SpeechRecognition` нет — кнопка там остаётся неактивной.
|
|
41
|
+
- Сеть: Chromium отправляет аудио в свой сервис распознавания. **Распознавание
|
|
42
|
+
не локальное** — сам плагин ничего не выгружает, но аудио получает сервис
|
|
43
|
+
производителя браузера.
|
|
44
|
+
|
|
45
|
+
## Установка
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
dsh plugin --profile web add dsh-voice-input-ru
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Или прямо из репозитория:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
dsh plugin --profile web add https://github.com/VToropov1337/dsh-voice-input-ru
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
После установки перезапустите веб-интерфейс — клиентские бандлы сканируются при
|
|
58
|
+
старте хоста. Затем рядом с композером появится кнопка микрофона.
|
|
59
|
+
|
|
60
|
+
## Смена языка распознавания
|
|
61
|
+
|
|
62
|
+
По умолчанию — русский. Любой другой BCP-47-тег применяется без пересборки:
|
|
63
|
+
задайте запись в `localStorage` и начинайте диктовку:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
localStorage.setItem('dsh-voice-input-ru:language', 'en-US')
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Значение проверяется (форма BCP-47) и читается при каждом старте, поэтому
|
|
70
|
+
следующая диктовка пойдёт на новом языке. Неизвестный браузеру тег даст ошибку
|
|
71
|
+
`language-not-supported` на кнопке. Вернуться к дефолту:
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
localStorage.removeItem('dsh-voice-input-ru:language')
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Структура
|
|
78
|
+
|
|
79
|
+
| Файл | Назначение |
|
|
80
|
+
|---|---|
|
|
81
|
+
| `src/host/index.ts` | Серверная половина: пустой `apply`, чтобы пакет появился в Loader |
|
|
82
|
+
| `src/client/index.ts` | Браузерная половина: регистрация слота и инъекция стилей |
|
|
83
|
+
| `src/client/MicSeat.tsx` | Компонент кнопки и конечный автомат распознавания |
|
|
84
|
+
| `src/client/speech.ts` | Структурные типы Web Speech API и поиск конструктора |
|
|
85
|
+
| `src/client/styles.ts` | CSS (токены хоста) и вставка/удаление `<style>` |
|
|
86
|
+
| `cordis.patch.yml` | Строка Loader для этого пакета (`dsh.bundle.patch`) |
|
|
87
|
+
| `tsdown.config.ts` | Сборка: серверный ESM + клиентский CJS-бандл для `__ModuleLoader__` |
|
|
88
|
+
|
|
89
|
+
Клиентскому бандлу из платформы нужны только `react` и `react/jsx-runtime`;
|
|
90
|
+
дополнительно он инжектит сервис `slots`.
|
|
91
|
+
|
|
92
|
+
## Разработка
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
npm install --no-audit --no-fund --cache .npm-cache
|
|
96
|
+
npm run typecheck # tsc --noEmit
|
|
97
|
+
npm run build # tsdown -> lib/index.js + lib/client.js
|
|
98
|
+
scripts/register.sh # сборка + регистрация в локальном профиле web
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Лицензия
|
|
102
|
+
|
|
103
|
+
MIT — см. [LICENSE](LICENSE).
|
|
Binary file
|
|
Binary file
|
package/cordis.patch.yml
ADDED
package/lib/client.js
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-voice-input-ru",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
module.exports;
|
|
6
|
+
let react = require("react");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
//#region src/client/speech.ts
|
|
9
|
+
/** Resolve the best available SpeechRecognition constructor, if any. */
|
|
10
|
+
function resolveSpeechRecognition() {
|
|
11
|
+
if (typeof window === "undefined") return void 0;
|
|
12
|
+
const w = window;
|
|
13
|
+
return w.SpeechRecognition ?? w.webkitSpeechRecognition;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/client/MicSeat.tsx
|
|
17
|
+
/**
|
|
18
|
+
* dsh-voice-input-ru — MicSeat: the composer microphone control.
|
|
19
|
+
*
|
|
20
|
+
* Registered into the `conversation.input.right` seat (compact controls
|
|
21
|
+
* before the composer submit action). The component only uses the session
|
|
22
|
+
* standard kit of that seat — `useInput` (live draft snapshot) and
|
|
23
|
+
* `inputActions.setDraft` — plus the browser's Web Speech API, so it renders
|
|
24
|
+
* exactly where the host mounts the seat and needs no other service.
|
|
25
|
+
*
|
|
26
|
+
* Behavior: one press starts a single-utterance SpeechRecognition session
|
|
27
|
+
* (Web Speech API, `SpeechRecognition` / `webkitSpeechRecognition`); final
|
|
28
|
+
* transcripts are appended to the message draft when the session ends (the
|
|
29
|
+
* browser stops it automatically after a pause, or the user presses the
|
|
30
|
+
* button again). Pressing again while listening stops and commits. When the
|
|
31
|
+
* API is unavailable the seat renders a disabled button; when the browser
|
|
32
|
+
* refuses the microphone, the failure shows as a short-lived state on the
|
|
33
|
+
* same control.
|
|
34
|
+
*
|
|
35
|
+
* Recognition language defaults to Russian (`ru-RU`): the Web Speech service
|
|
36
|
+
* transcribes best when the language matches the spoken one, and guessing
|
|
37
|
+
* from browser/UI locales produced English transcripts for Russian speech.
|
|
38
|
+
* Any other BCP-47 tag is set without a rebuild by writing the `LANG_STORAGE_KEY`
|
|
39
|
+
* localStorage entry (see the README); the value is re-read on every start,
|
|
40
|
+
* so a change applies to the next dictation.
|
|
41
|
+
*/
|
|
42
|
+
/** Default recognition language (BCP-47): Russian speech is the primary use case. */
|
|
43
|
+
const DEFAULT_RECOGNITION_LANG = "ru-RU";
|
|
44
|
+
/**
|
|
45
|
+
* localStorage key holding the recognition language. Setting it to another
|
|
46
|
+
* BCP-47 tag switches recognition without a rebuild:
|
|
47
|
+
* `localStorage.setItem('dsh-voice-input-ru:language', 'en-US')`.
|
|
48
|
+
* The value is read on every start; an invalid tag falls back to the default.
|
|
49
|
+
*/
|
|
50
|
+
const LANG_STORAGE_KEY = "dsh-voice-input-ru:language";
|
|
51
|
+
/** Shape check only — the browser reports real support as `language-not-supported`. */
|
|
52
|
+
const BCP47 = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$/;
|
|
53
|
+
/** Read the configured recognition language, falling back to the default. */
|
|
54
|
+
function recognitionLanguage() {
|
|
55
|
+
try {
|
|
56
|
+
const stored = window.localStorage.getItem(LANG_STORAGE_KEY)?.trim();
|
|
57
|
+
if (stored !== void 0 && stored !== "" && BCP47.test(stored)) return stored;
|
|
58
|
+
} catch {}
|
|
59
|
+
return DEFAULT_RECOGNITION_LANG;
|
|
60
|
+
}
|
|
61
|
+
/** Pick the UI language for tooltips/aria from the document, else the browser. */
|
|
62
|
+
function uiLanguage() {
|
|
63
|
+
const root = typeof document !== "undefined" ? document.documentElement.lang : "";
|
|
64
|
+
return (root !== "" ? root : typeof navigator !== "undefined" ? navigator.language : "en").startsWith("ru") ? "ru" : "en";
|
|
65
|
+
}
|
|
66
|
+
function say(ru, en) {
|
|
67
|
+
return uiLanguage() === "ru" ? ru : en;
|
|
68
|
+
}
|
|
69
|
+
function errorMessage(event) {
|
|
70
|
+
switch (event.error) {
|
|
71
|
+
case "not-allowed":
|
|
72
|
+
case "service-not-allowed": return say("Доступ к микрофону запрещён — разрешите его в браузере", "Microphone access denied — allow it in the browser");
|
|
73
|
+
case "audio-capture": return say("Микрофон не найден или не подключён", "No microphone found or connected");
|
|
74
|
+
case "network": return say("Ошибка сети при распознавании речи", "Speech recognition network error");
|
|
75
|
+
case "language-not-supported": return say("Язык распознавания не поддерживается браузером", "Recognition language is not supported by the browser");
|
|
76
|
+
case "aborted": return "";
|
|
77
|
+
default: return say(`Ошибка распознавания речи (${event.error})`, `Speech recognition error (${event.error})`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const ERROR_RESET_MS = 3500;
|
|
81
|
+
const MIC_PATH = "M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3Z";
|
|
82
|
+
function MicSeat(props) {
|
|
83
|
+
const { useInput, inputActions } = props;
|
|
84
|
+
const draft = useInput((state) => state.draft);
|
|
85
|
+
const draftRef = (0, react.useRef)(draft);
|
|
86
|
+
draftRef.current = draft;
|
|
87
|
+
const actionsRef = (0, react.useRef)(inputActions);
|
|
88
|
+
actionsRef.current = inputActions;
|
|
89
|
+
const [status, setStatus] = (0, react.useState)(() => resolveSpeechRecognition() !== void 0 ? "idle" : "unsupported");
|
|
90
|
+
const [detail, setDetail] = (0, react.useState)("");
|
|
91
|
+
const recognitionRef = (0, react.useRef)(null);
|
|
92
|
+
const finalsRef = (0, react.useRef)([]);
|
|
93
|
+
const errorTimerRef = (0, react.useRef)(void 0);
|
|
94
|
+
(0, react.useEffect)(() => {
|
|
95
|
+
return () => {
|
|
96
|
+
if (errorTimerRef.current !== void 0) window.clearTimeout(errorTimerRef.current);
|
|
97
|
+
recognitionRef.current?.abort();
|
|
98
|
+
recognitionRef.current = null;
|
|
99
|
+
};
|
|
100
|
+
}, []);
|
|
101
|
+
const showError = (message) => {
|
|
102
|
+
if (message === "") return;
|
|
103
|
+
setDetail(message);
|
|
104
|
+
setStatus("error");
|
|
105
|
+
if (errorTimerRef.current !== void 0) window.clearTimeout(errorTimerRef.current);
|
|
106
|
+
errorTimerRef.current = window.setTimeout(() => {
|
|
107
|
+
errorTimerRef.current = void 0;
|
|
108
|
+
setStatus((current) => current === "error" ? "idle" : current);
|
|
109
|
+
setDetail("");
|
|
110
|
+
}, ERROR_RESET_MS);
|
|
111
|
+
};
|
|
112
|
+
/** Fold every collected final transcript into the composer draft. */
|
|
113
|
+
const commitFinals = () => {
|
|
114
|
+
const collected = finalsRef.current;
|
|
115
|
+
finalsRef.current = [];
|
|
116
|
+
const text = collected.map((part) => part.trim()).filter((part) => part !== "").join(" ");
|
|
117
|
+
if (text === "") return;
|
|
118
|
+
const draft = draftRef.current ?? "";
|
|
119
|
+
const separator = draft.length > 0 && !/\s$/u.test(draft) ? " " : "";
|
|
120
|
+
actionsRef.current?.setDraft(draft + separator + text);
|
|
121
|
+
};
|
|
122
|
+
const fail = (message) => {
|
|
123
|
+
recognitionRef.current?.abort();
|
|
124
|
+
recognitionRef.current = null;
|
|
125
|
+
showError(message);
|
|
126
|
+
};
|
|
127
|
+
const beginListening = () => {
|
|
128
|
+
const Ctor = resolveSpeechRecognition();
|
|
129
|
+
if (Ctor === void 0) {
|
|
130
|
+
setStatus("unsupported");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (recognitionRef.current !== null) return;
|
|
134
|
+
let recognition;
|
|
135
|
+
try {
|
|
136
|
+
recognition = new Ctor();
|
|
137
|
+
} catch {
|
|
138
|
+
fail(say("Не удалось запустить распознавание речи", "Could not start speech recognition"));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
recognition.lang = recognitionLanguage();
|
|
142
|
+
recognition.continuous = false;
|
|
143
|
+
recognition.interimResults = false;
|
|
144
|
+
recognition.maxAlternatives = 1;
|
|
145
|
+
let failed = false;
|
|
146
|
+
recognition.onresult = (event) => {
|
|
147
|
+
const parts = [];
|
|
148
|
+
for (let index = event.resultIndex; index < event.results.length; index += 1) {
|
|
149
|
+
const result = event.results[index];
|
|
150
|
+
if (result === void 0 || !result.isFinal) continue;
|
|
151
|
+
const transcript = result[0]?.transcript.trim();
|
|
152
|
+
if (transcript !== void 0 && transcript !== "") parts.push(transcript);
|
|
153
|
+
}
|
|
154
|
+
if (parts.length > 0) finalsRef.current.push(...parts);
|
|
155
|
+
};
|
|
156
|
+
recognition.onerror = (event) => {
|
|
157
|
+
const message = errorMessage(event);
|
|
158
|
+
if (message === "") return;
|
|
159
|
+
failed = true;
|
|
160
|
+
fail(message);
|
|
161
|
+
};
|
|
162
|
+
recognition.onend = () => {
|
|
163
|
+
if (recognitionRef.current === recognition) recognitionRef.current = null;
|
|
164
|
+
setStatus((current) => current === "listening" ? failed ? current : "idle" : current);
|
|
165
|
+
if (!failed) commitFinals();
|
|
166
|
+
};
|
|
167
|
+
recognitionRef.current = recognition;
|
|
168
|
+
finalsRef.current = [];
|
|
169
|
+
setDetail("");
|
|
170
|
+
setStatus("listening");
|
|
171
|
+
try {
|
|
172
|
+
recognition.start();
|
|
173
|
+
} catch {
|
|
174
|
+
fail(say("Не удалось запустить распознавание речи", "Could not start speech recognition"));
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const stopListening = () => {
|
|
178
|
+
recognitionRef.current?.stop();
|
|
179
|
+
};
|
|
180
|
+
const listening = status === "listening";
|
|
181
|
+
const unsupported = status === "unsupported";
|
|
182
|
+
const unavailable = unsupported || inputActions === void 0;
|
|
183
|
+
const label = unsupported ? say("Голосовой ввод недоступен в этом браузере", "Voice input is not available in this browser") : listening ? say("Слушаю… нажмите, чтобы закончить", "Listening… press to stop") : status === "error" ? `${say("Голосовой ввод", "Voice input")} — ${detail}` : say("Голосовой ввод (микрофон)", "Voice input (microphone)");
|
|
184
|
+
const title = unsupported ? say("Распознавание речи не поддерживается этим браузером. Попробуйте Chrome или Edge.", "Speech recognition is not supported by this browser. Try Chrome or Edge.") : status === "error" ? `${say("Голосовой ввод", "Voice input")}: ${detail}` : listening ? say("Идёт распознавание — нажмите, чтобы закончить и вставить текст", "Recognizing — press to stop and insert the text") : say("Нажмите и говорите — распознанный текст появится в поле ввода", "Press and speak — the recognized text will be inserted into the input");
|
|
185
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
186
|
+
type: "button",
|
|
187
|
+
className: "dshvmic",
|
|
188
|
+
"data-plugin": "dsh-voice-input-ru",
|
|
189
|
+
"aria-label": label,
|
|
190
|
+
"aria-pressed": listening,
|
|
191
|
+
title,
|
|
192
|
+
disabled: unavailable,
|
|
193
|
+
onMouseDown: (event) => {
|
|
194
|
+
if (event.button === 0) event.preventDefault();
|
|
195
|
+
},
|
|
196
|
+
onClick: () => {
|
|
197
|
+
if (listening) stopListening();
|
|
198
|
+
else beginListening();
|
|
199
|
+
},
|
|
200
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
201
|
+
className: "dshvmic-wave",
|
|
202
|
+
viewBox: "0 0 24 24",
|
|
203
|
+
width: "16",
|
|
204
|
+
height: "16",
|
|
205
|
+
fill: "none",
|
|
206
|
+
stroke: "currentColor",
|
|
207
|
+
strokeWidth: "1.8",
|
|
208
|
+
strokeLinecap: "round",
|
|
209
|
+
strokeLinejoin: "round",
|
|
210
|
+
"aria-hidden": "true",
|
|
211
|
+
children: [
|
|
212
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: MIC_PATH }),
|
|
213
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M5 10v1a7 7 0 0 0 14 0v-1" }),
|
|
214
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
215
|
+
x1: "12",
|
|
216
|
+
y1: "18.5",
|
|
217
|
+
x2: "12",
|
|
218
|
+
y2: "22"
|
|
219
|
+
})
|
|
220
|
+
]
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/client/styles.ts
|
|
226
|
+
/**
|
|
227
|
+
* dsh-voice-input-ru — plugin-owned stylesheet.
|
|
228
|
+
*
|
|
229
|
+
* Injected as one <style data-plugin data-plugin-css> tag inside apply() and
|
|
230
|
+
* removed by the disposer, so a stopped or HMR-reloaded plugin never leaves a
|
|
231
|
+
* stray sheet behind. Every rule is scoped through the plugin's own
|
|
232
|
+
* data-plugin attribute — never through host internals — and colors come only
|
|
233
|
+
* from the host's semantic alias tokens, so the mic follows light/dark themes.
|
|
234
|
+
*/
|
|
235
|
+
const STYLE_ID = "dsh-voice-input-ru/styles";
|
|
236
|
+
const CSS_TEXT = `
|
|
237
|
+
[data-plugin="dsh-voice-input-ru"].dshvmic {
|
|
238
|
+
display: inline-flex;
|
|
239
|
+
align-items: center;
|
|
240
|
+
justify-content: center;
|
|
241
|
+
width: 28px;
|
|
242
|
+
height: 28px;
|
|
243
|
+
flex: none;
|
|
244
|
+
margin: 0;
|
|
245
|
+
padding: 0;
|
|
246
|
+
color: var(--dsw-alias-label-secondary);
|
|
247
|
+
background: transparent;
|
|
248
|
+
border: 0;
|
|
249
|
+
border-radius: 50%;
|
|
250
|
+
cursor: pointer;
|
|
251
|
+
outline: none;
|
|
252
|
+
transition: color 120ms ease, background-color 120ms ease;
|
|
253
|
+
}
|
|
254
|
+
[data-plugin="dsh-voice-input-ru"].dshvmic:hover:not(:disabled),
|
|
255
|
+
[data-plugin="dsh-voice-input-ru"].dshvmic:focus-visible {
|
|
256
|
+
background: var(--dsw-alias-interactive-bg-hover);
|
|
257
|
+
}
|
|
258
|
+
[data-plugin="dsh-voice-input-ru"].dshvmic:hover:not(:disabled) {
|
|
259
|
+
color: var(--dsw-alias-label-primary);
|
|
260
|
+
}
|
|
261
|
+
[data-plugin="dsh-voice-input-ru"].dshvmic:focus-visible {
|
|
262
|
+
box-shadow: 0 0 0 2px var(--dsw-alias-border-l3);
|
|
263
|
+
}
|
|
264
|
+
[data-plugin="dsh-voice-input-ru"].dshvmic:disabled {
|
|
265
|
+
color: var(--dsw-alias-label-dimmed);
|
|
266
|
+
cursor: default;
|
|
267
|
+
}
|
|
268
|
+
[data-plugin="dsh-voice-input-ru"].dshvmic[aria-pressed="true"] {
|
|
269
|
+
color: var(--dsw-alias-state-error-primary);
|
|
270
|
+
background: var(--dsw-alias-interactive-bg-hover-danger);
|
|
271
|
+
}
|
|
272
|
+
[data-plugin="dsh-voice-input-ru"].dshvmic[aria-pressed="true"] .dshvmic-wave {
|
|
273
|
+
animation: dshvmic-pulse 1.3s ease-in-out infinite;
|
|
274
|
+
}
|
|
275
|
+
@keyframes dshvmic-pulse {
|
|
276
|
+
0%, 100% { opacity: 1; }
|
|
277
|
+
50% { opacity: 0.35; }
|
|
278
|
+
}
|
|
279
|
+
@media (prefers-reduced-motion: reduce) {
|
|
280
|
+
[data-plugin="dsh-voice-input-ru"].dshvmic[aria-pressed="true"] .dshvmic-wave {
|
|
281
|
+
animation: none;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
`;
|
|
285
|
+
/** Append the sheet once; returns a disposer when this call added the tag. */
|
|
286
|
+
function injectStyles() {
|
|
287
|
+
if (typeof document === "undefined") return void 0;
|
|
288
|
+
if (document.querySelector(`style[data-plugin-css="dsh-voice-input-ru/styles"]`) !== null) return void 0;
|
|
289
|
+
const tag = document.createElement("style");
|
|
290
|
+
tag.dataset.plugin = "dsh-voice-input-ru";
|
|
291
|
+
tag.dataset.pluginCss = STYLE_ID;
|
|
292
|
+
tag.textContent = CSS_TEXT;
|
|
293
|
+
document.head.appendChild(tag);
|
|
294
|
+
return () => {
|
|
295
|
+
tag.remove();
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/client/index.ts
|
|
300
|
+
/**
|
|
301
|
+
* dsh-voice-input-ru — Client half (installed package bundle entry).
|
|
302
|
+
*
|
|
303
|
+
* Registers the microphone seat into the composer's `conversation.input.right`
|
|
304
|
+
* slot (compact controls before the submit action), right next to the message
|
|
305
|
+
* input. The seat runs the browser's Web Speech API and writes recognized text
|
|
306
|
+
* into the composer draft through the session standard kit (`useInput` +
|
|
307
|
+
* `inputActions.setDraft`), which the host hands to every entry of that slot —
|
|
308
|
+
* no other client service is needed.
|
|
309
|
+
*
|
|
310
|
+
* This module is the body of the package's `./client` export: tsdown bundles
|
|
311
|
+
* it (external `react` — the browser module table supplies it via the injected
|
|
312
|
+
* `require`) into the web boot handoff shape
|
|
313
|
+
* (`window.__ModuleLoader__.load({ id, factory })`).
|
|
314
|
+
*/
|
|
315
|
+
const NS = "dsh-voice-input-ru";
|
|
316
|
+
/** Client plugin body. */
|
|
317
|
+
function apply(ctx) {
|
|
318
|
+
ctx.effect(() => injectStyles(), `${NS}: styles`);
|
|
319
|
+
ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
|
|
320
|
+
name: "conversation.input.right",
|
|
321
|
+
id: NS,
|
|
322
|
+
order: 100
|
|
323
|
+
}, (props) => (0, react.createElement)(MicSeat, props)));
|
|
324
|
+
}
|
|
325
|
+
module.exports = {
|
|
326
|
+
name: NS,
|
|
327
|
+
inject: ["slots"],
|
|
328
|
+
apply
|
|
329
|
+
};
|
|
330
|
+
//#endregion
|
|
331
|
+
return module.exports;
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
//# sourceMappingURL=client.js.map
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/host/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* dsh-voice-input-ru — Host half (installed package entry).
|
|
4
|
+
*
|
|
5
|
+
* Pure UI plugin: the empty apply exists so the plugin appears in the host
|
|
6
|
+
* cordis.yml / Loader; the browser half ships via exports["./client"],
|
|
7
|
+
* discovered through the package.json `dsh.client` declaration.
|
|
8
|
+
*/
|
|
9
|
+
/** Host plugin body — no host-side behavior for this surface plugin. */
|
|
10
|
+
function apply() {}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { apply };
|
package/package.json
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-voice-input-ru",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Microphone button in the DeepSeek Harness composer that dictates speech through the browser's Web Speech API into the message draft; recognition language defaults to Russian and is switchable at runtime.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"default": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./client": "./lib/client.js",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib/index.js",
|
|
16
|
+
"lib/client.js",
|
|
17
|
+
"assets/",
|
|
18
|
+
"cordis.patch.yml",
|
|
19
|
+
"README.md",
|
|
20
|
+
"README.ru.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsdown",
|
|
25
|
+
"watch": "tsdown --watch",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"prepack": "npm run build",
|
|
28
|
+
"register": "bash scripts/register.sh"
|
|
29
|
+
},
|
|
30
|
+
"dsh": {
|
|
31
|
+
"bundle": {
|
|
32
|
+
"patch": "./cordis.patch.yml"
|
|
33
|
+
},
|
|
34
|
+
"client": {
|
|
35
|
+
"inject": [
|
|
36
|
+
"@deepseek-ai/dsh-client-ui-conversation"
|
|
37
|
+
],
|
|
38
|
+
"platform": "web"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"dsh": ">=0.2.1-rc.1 <0.3.0-0"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"deepseek-harness",
|
|
46
|
+
"dsh",
|
|
47
|
+
"dsh-plugin",
|
|
48
|
+
"cordis",
|
|
49
|
+
"plugin",
|
|
50
|
+
"speech-recognition",
|
|
51
|
+
"speech-to-text",
|
|
52
|
+
"voice",
|
|
53
|
+
"dictation",
|
|
54
|
+
"russian"
|
|
55
|
+
],
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/VToropov1337/dsh-voice-input-ru.git"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://github.com/VToropov1337/dsh-voice-input-ru#readme",
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/VToropov1337/dsh-voice-input-ru/issues"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
67
|
+
"react": "^18.2.0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependenciesMeta": {
|
|
70
|
+
"react": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@types/node": "^22.10.5",
|
|
76
|
+
"@types/react": "^18.3.18",
|
|
77
|
+
"react": "^18.3.1",
|
|
78
|
+
"tsdown": "^0.22.14",
|
|
79
|
+
"typescript": "^5.7.3"
|
|
80
|
+
}
|
|
81
|
+
}
|