dsh-voice-mode 0.7.38 → 0.7.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +26 -2
- package/README.md +26 -2
- package/lib/client.js +27 -14
- package/lib/index.js +194 -4
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -135,7 +135,7 @@ If a wake word is configured, you land in standby first (the status bar prompts
|
|
|
135
135
|
|
|
136
136
|
| Key | Default | Description |
|
|
137
137
|
| --- | --- | --- |
|
|
138
|
-
| `ttsEngine` | `edge` | Read-aloud engine: `edge` Microsoft cloud (default, fast) / `vits` local Chinese / `kokoro` local zh+en; **applies live** |
|
|
138
|
+
| `ttsEngine` | `edge` | Read-aloud engine: `edge` Microsoft cloud (default, fast) / `vits` local Chinese / `kokoro` local zh+en / `openai` any OpenAI-compatible server (see below); **applies live** |
|
|
139
139
|
| `kokoroModel` | `int8` | Kokoro precision: `int8` (default, 109 MB, CPU/low-bandwidth) / `fp32` (311 MB, better quality, GPU/large memory); same 103 voices; **applies live** |
|
|
140
140
|
| `voice` | per engine | Voice: 5 VITS speakers; 103 Kokoro voices (◀▶ stepper; 62/68/75/76 favourite males pinned); Edge ShortNames below. The inline "试听" button previews it at the current rate |
|
|
141
141
|
| `rate` | `1.1` | Reading speed multiplier (0.5 slow ~ 2.0 fast), **applies live** (batch J 1.0→1.1) |
|
|
@@ -214,6 +214,30 @@ You can also edit the `voice-mode:` section of `~/.dsh/settings.yaml` directly (
|
|
|
214
214
|
> (`enabled/cacheDir` remain bundle-config-only).
|
|
215
215
|
> The plugin HTTP namespace is fixed to `/voice-mode` (matching the client bundle contract; not configurable).
|
|
216
216
|
|
|
217
|
+
### OpenAI-compatible TTS server (`ttsEngine: openai`)
|
|
218
|
+
|
|
219
|
+
Any server that implements OpenAI's `POST /v1/audio/speech` can read replies aloud: a self-hosted one on a GPU machine ([vLLM-Omni](https://github.com/vllm-project/vllm-omni), [Kokoro-FastAPI](https://github.com/remsky/Kokoro-FastAPI), LocalAI, ...) or a hosted API such as OpenAI or [OpenRouter](https://openrouter.ai/docs/guides/overview/multimodal/tts). The server is set in the bundle config (it is host-only; the key never reaches the browser), and the engine is picked in the settings panel like the others:
|
|
220
|
+
|
|
221
|
+
```yaml
|
|
222
|
+
- id: voice-mode
|
|
223
|
+
name: dsh-voice-mode
|
|
224
|
+
config:
|
|
225
|
+
ttsEngine: openai
|
|
226
|
+
voice: vivian # voice name on the server; empty = openaiTts.voice
|
|
227
|
+
openaiTts:
|
|
228
|
+
baseUrl: http://gpu-box:8091/v1 # OpenRouter: https://openrouter.ai/api/v1, OpenAI: https://api.openai.com/v1
|
|
229
|
+
apiKey: '' # Bearer key, empty for servers without auth
|
|
230
|
+
model: Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice
|
|
231
|
+
voice: vivian
|
|
232
|
+
responseFormat: mp3 # mp3 | wav
|
|
233
|
+
timeoutMs: 8000 # per sentence; slower counts as unavailable
|
|
234
|
+
fallback: kokoro # none | vits | kokoro: local engine while the server is down or slow
|
|
235
|
+
fallbackVoice: zf_xiaobei # empty = that engine's default voice
|
|
236
|
+
instructions: '' # optional style text for models that accept it
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Each sentence is one request (the queue already synthesizes sentence by sentence while the reply is still streaming, so in-sentence streaming would not start playback any sooner). `rate` is sent as `speed` when it is not 1. With a `fallback`, a failed or timed-out request makes that sentence (and the next 30 s) use the local engine, then the server is tried again, so a dead server does not cost a timeout per sentence. The text to be spoken goes to `baseUrl`, so pick a server you trust with your replies.
|
|
240
|
+
|
|
217
241
|
---
|
|
218
242
|
|
|
219
243
|
## 🌐 API
|
|
@@ -310,7 +334,7 @@ An honest disclosure of what the plugin does (mapped to the awesome-dsh-plugin c
|
|
|
310
334
|
|
|
311
335
|
| Category | What it does | Where data goes |
|
|
312
336
|
| --- | --- | --- |
|
|
313
|
-
| **network** | (1) The default read-aloud engine **Edge** sends the **reply text to be spoken** over WebSocket to Microsoft `speech.platform.bing.com` (cloud synthesis — local VITS / Kokoro avoids this TTS request after its models are ready; host LLM traffic is separate); (2) downloads local models on first use from `huggingface.co` (or your configured mirror `hf-mirror.com`) with host restrictions and pinned digests for primary/listed files; auxiliary directories use manifest/presence checks; (3) registers loopback HTTP routes `/voice-mode/*` on the dsh host (loopback only by default; LAN needs `allowLan`) | Browser audio is sent to the configured dsh host for recognition; the plugin does not use an independent cloud ASR. Edge sends text to Microsoft. Submitted transcripts and optional LLM correction follow the host LLM configuration |
|
|
337
|
+
| **network** | (1) The default read-aloud engine **Edge** sends the **reply text to be spoken** over WebSocket to Microsoft `speech.platform.bing.com` (cloud synthesis — local VITS / Kokoro avoids this TTS request after its models are ready; host LLM traffic is separate); (2) downloads local models on first use from `huggingface.co` (or your configured mirror `hf-mirror.com`) with host restrictions and pinned digests for primary/listed files; auxiliary directories use manifest/presence checks; (3) with `ttsEngine: openai`, sends the text to be spoken to the configured `openaiTts.baseUrl` (and to nothing else); (4) registers loopback HTTP routes `/voice-mode/*` on the dsh host (loopback only by default; LAN needs `allowLan`) | Browser audio is sent to the configured dsh host for recognition; the plugin does not use an independent cloud ASR. Edge sends text to Microsoft. Submitted transcripts and optional LLM correction follow the host LLM configuration |
|
|
314
338
|
| **fs-read / fs-write** | Model cache (Linux/macOS `~/.cache/dsh-voice-mode/models/`, Windows `%LOCALAPPDATA%\dsh-voice-mode\models\`); the dsh 0.1.7+ settings overlay `$DSH_HOME/voice-mode.settings.json`; **never touches your workspace files** | All local |
|
|
315
339
|
| **shell (child processes)** | Local TTS synthesis runs in a separate child process (`child_process.fork` → `lib/tts-vits-worker.cjs`); when the host is Electron (the official desktop app), it additionally probes and launches a real Node.js for Kokoro (`node -p …` to check the version). **It never executes user input and never builds shell command strings** | Local |
|
|
316
340
|
| **env** | Uses directory/runtime environment settings such as `DSH_HOME`, `LOCALAPPDATA`, `PATH` and optional `DSHVM_NODE`; this default speech path does not require an extra speech-service API key | — |
|
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ dsh plugin --profile web add dsh-voice-mode
|
|
|
121
121
|
|
|
122
122
|
| 键 | 默认 | 说明 |
|
|
123
123
|
| --- | --- | --- |
|
|
124
|
-
| `ttsEngine` | `edge` | 朗读引擎:`edge` 微软云端(默认,快)/ `vits` 本地中文 / `kokoro`
|
|
124
|
+
| `ttsEngine` | `edge` | 朗读引擎:`edge` 微软云端(默认,快)/ `vits` 本地中文 / `kokoro` 本地中英 / `openai` 任意 OpenAI 兼容服务(见下文);**即时生效** |
|
|
125
125
|
| `kokoroModel` | `int8` | Kokoro 模型精度:`int8`(默认,109MB,纯 CPU/低带宽推荐)/ `fp32`(311MB,音质更好,独显/大内存推荐);两档共用 103 音色,**即时生效** |
|
|
126
126
|
| `voice` | 按引擎 | 音色:VITS 五说话人;Kokoro 103 个(下拉+◀▶,62 深沉/68 浑厚/75 清亮/76 磁性置顶);Edge 进入时自动加载全量 322 个。行内「试听」可即时预览 |
|
|
127
127
|
| `rate` | `1.1` | 朗读语速倍率(0.5 慢速 ~ 2.0 快速),**即时生效** |
|
|
@@ -201,6 +201,30 @@ dsh plugin --profile web add dsh-voice-mode
|
|
|
201
201
|
> (`enabled` / `cacheDir` 则仅由 bundle 配置决定)。
|
|
202
202
|
> 插件 HTTP 命名空间固定为 `/voice-mode`(与客户端打包契约一致,不可配置)。
|
|
203
203
|
|
|
204
|
+
### OpenAI 兼容的 TTS 服务(`ttsEngine: openai`)
|
|
205
|
+
|
|
206
|
+
任何实现了 OpenAI `POST /v1/audio/speech` 的服务都能用来朗读:自己 GPU 机器上的([vLLM-Omni](https://github.com/vllm-project/vllm-omni)、[Kokoro-FastAPI](https://github.com/remsky/Kokoro-FastAPI)、LocalAI 等),或者 OpenAI、[OpenRouter](https://openrouter.ai/docs/guides/overview/multimodal/tts) 这类托管 API。服务地址写在组合包 config 里(仅 host 侧,key 不会下发到浏览器),引擎和其他引擎一样在设置面板里选:
|
|
207
|
+
|
|
208
|
+
```yaml
|
|
209
|
+
- id: voice-mode
|
|
210
|
+
name: dsh-voice-mode
|
|
211
|
+
config:
|
|
212
|
+
ttsEngine: openai
|
|
213
|
+
voice: vivian # 服务端的音色名;留空 = openaiTts.voice
|
|
214
|
+
openaiTts:
|
|
215
|
+
baseUrl: http://gpu-box:8091/v1 # OpenRouter: https://openrouter.ai/api/v1,OpenAI: https://api.openai.com/v1
|
|
216
|
+
apiKey: '' # Bearer key,服务无鉴权时留空
|
|
217
|
+
model: Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice
|
|
218
|
+
voice: vivian
|
|
219
|
+
responseFormat: mp3 # mp3 | wav
|
|
220
|
+
timeoutMs: 8000 # 单句超时,超过视为不可用
|
|
221
|
+
fallback: kokoro # none | vits | kokoro:服务挂了或太慢时用的本地引擎
|
|
222
|
+
fallbackVoice: zf_xiaobei # 留空 = 该引擎的默认音色
|
|
223
|
+
instructions: '' # 可选,支持风格说明的模型才用
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
每句一个请求(队列本来就在回复还在生成时逐句合成,句内流式不会让播放更早开始)。`rate` 不为 1 时作为 `speed` 发送。配置了 `fallback` 时,请求失败或超时的那句(以及之后 30 秒)改用本地引擎,然后再试服务,服务挂掉不会让每句都等一次超时。被朗读的文本会发到 `baseUrl`,请选你信得过的服务。
|
|
227
|
+
|
|
204
228
|
---
|
|
205
229
|
|
|
206
230
|
## 🌐 API
|
|
@@ -297,7 +321,7 @@ flowchart LR
|
|
|
297
321
|
|
|
298
322
|
| 类别 | 具体行为 | 数据去向 |
|
|
299
323
|
| --- | --- | --- |
|
|
300
|
-
| **network** | Edge
|
|
324
|
+
| **network** | Edge 将待朗读文本发往微软在线服务;`ttsEngine: openai` 时将待朗读文本发往配置的 `openaiTts.baseUrl`(不发往别处);本地模型从官方源或配置镜像下载,主要模型及清单内支持文件做摘要校验,辅助目录用清单/存在性检查;插件在宿主注册 `/voice-mode/*` 路由 | 浏览器音频发送到所连接的 dsh 宿主识别,不使用独立云 ASR;提交文本及可选 LLM 纠错遵循宿主配置。切换本地 TTS 不会让宿主 LLM 自动离线 |
|
|
301
325
|
| **fs-read / fs-write** | 模型缓存(Linux/macOS `~/.cache/dsh-voice-mode/models/`,Windows `%LOCALAPPDATA%\dsh-voice-mode\models\`);dsh 0.1.7+ 的设置覆盖层 `$DSH_HOME/voice-mode.settings.json`;**不读写你的工作区文件** | 全部在本机 |
|
|
302
326
|
| **shell(子进程)** | 本地 TTS 合成跑在独立子进程(`child_process.fork` → `lib/tts-vits-worker.cjs`);宿主为 Electron(官方桌面端)时,为 Kokoro 额外探测并启动一个真正的 Node.js(`node -p …` 探测版本,见 ADR/兼容契约)。**不执行用户输入、不经 shell 拼接命令** | 本机 |
|
|
303
327
|
| **env** | 使用目录和运行时定位相关环境设置,如 `DSH_HOME`、`LOCALAPPDATA`、`PATH` 和可选 `DSHVM_NODE`;默认语音路径无需额外语音服务密钥 | 宿主 LLM 的配置和费用另计 |
|
package/lib/client.js
CHANGED
|
@@ -1759,10 +1759,14 @@ var zh = {
|
|
|
1759
1759
|
voiceNext: "\u4E0B\u4E00\u97F3\u8272",
|
|
1760
1760
|
descVoice: "Edge \u4E91\u7AEF\u97F3\u8272\uFF08\u8FDB\u5165\u65F6\u81EA\u52A8\u52A0\u8F7D\u5FAE\u8F6F\u5168\u90E8\u97F3\u8272\uFF0C\u5E38\u7528\u4E2D\u6587\u97F3\u8272\u7F6E\u9876\uFF0C\u4E0B\u62C9\u6216 \u25C0\u25B6 \u9009\uFF1B\u4E5F\u53EF\u300C\u81EA\u5B9A\u4E49\u300D\u586B ShortName\uFF09",
|
|
1761
1761
|
descVoiceLocal: "\u672C\u5730\u97F3\u8272\uFF08vits \u4E94\u4E2A\u8BF4\u8BDD\u4EBA\u5168\u90E8\u5217\u51FA\uFF0C\u4E0B\u62C9\u9009\u6216 \u25C0\u25B6 \u5207\u6362\uFF1B\u65E0\u9700\u81EA\u5B9A\u4E49\uFF09",
|
|
1762
|
-
descTtsEngine: "\u672C\u5730 VITS\uFF08\u7EAF\u4E2D\u6587\uFF09/ \u672C\u5730 Kokoro\uFF08\u4E2D\u82F1\u5747\u53EF\uFF09/ Edge \u4E91\u7AEF\uFF08\u97F3\u8D28\u6700\u81EA\u7136\uFF0C\u6587\u672C\u4E0A\u5FAE\u8F6F\uFF09",
|
|
1762
|
+
descTtsEngine: "\u672C\u5730 VITS\uFF08\u7EAF\u4E2D\u6587\uFF09/ \u672C\u5730 Kokoro\uFF08\u4E2D\u82F1\u5747\u53EF\uFF09/ Edge \u4E91\u7AEF\uFF08\u97F3\u8D28\u6700\u81EA\u7136\uFF0C\u6587\u672C\u4E0A\u5FAE\u8F6F\uFF09/ OpenAI \u517C\u5BB9\u670D\u52A1\uFF08\u81EA\u5EFA\u6216\u6258\u7BA1\uFF0C\u6587\u672C\u53D1\u5F80\u914D\u7F6E\u7684\u5730\u5740\uFF09",
|
|
1763
1763
|
engineVits: "\u672C\u5730 VITS",
|
|
1764
1764
|
engineKokoro: "\u672C\u5730\u4E2D\u82F1",
|
|
1765
1765
|
engineEdge: "Edge \u4E91\u7AEF",
|
|
1766
|
+
engineOpenai: "OpenAI \u517C\u5BB9",
|
|
1767
|
+
descVoiceOpenai: "\u670D\u52A1\u7AEF\u7684\u97F3\u8272\u540D\uFF08\u7559\u7A7A = \u914D\u7F6E\u91CC\u7684 openaiTts.voice\uFF09",
|
|
1768
|
+
engineRemoteDown: "\u670D\u52A1\u4E0D\u53EF\u7528",
|
|
1769
|
+
errRemoteTts: "\u6717\u8BFB\u670D\u52A1\u8FDE\u4E0D\u4E0A\u3001\u62A5\u9519\u6216\u592A\u6162\uFF1B\u914D\u7F6E\u4E86\u56DE\u9000\u65F6\u8FD9\u671F\u95F4\u7528\u672C\u5730\u5F15\u64CE\u6717\u8BFB",
|
|
1766
1770
|
descVoiceKokoro: "Kokoro \u4E2D\u82F1\u97F3\u8272\uFF08103 \u4E2A\u5168\u90E8\u5217\u51FA\uFF0C\u4E0B\u62C9\u9009\u6216 \u25C0\u25B6 \u5207\u6362\uFF1B48-51 \u4E2D\u6587\u540D\uFF0C\u5176\u4F59\u6309\u7F16\u53F7+\u5B9E\u6D4B\u6027\u522B\u6807\u6CE8\uFF0C\u4E2D\u82F1\u6DF7\u8BFB\u5747\u53EF\uFF09",
|
|
1767
1771
|
descRate: "\u6717\u8BFB\u8BED\u901F\u500D\u7387\uFF080.5 \u6162\u901F \uFF5E 2.0 \u5FEB\u901F\uFF0C1.1 \u9ED8\u8BA4\uFF1B\u8BA9\u56DE\u590D\u66F4\u7D27\u51D1\uFF09",
|
|
1768
1772
|
descInterrupt: "\u53D1\u58F0\u6253\u65AD\u7075\u654F\u5EA6\uFF080 \u9AD8\u95E8\u69DB \u22480.3s \u786E\u8BA4 / 1 \u4E2D\u95E8\u69DB \u22480.2s / 2 \u4F4E\u95E8\u69DB \u22480.1s\uFF0C\u6700\u7075\u654F\uFF09\uFF1B\u503C\u8D8A\u4F4E\u95E8\u69DB\u8D8A\u9AD8\uFF0C\u8D8A\u96BE\u6253\u65AD",
|
|
@@ -1962,6 +1966,7 @@ var zh = {
|
|
|
1962
1966
|
hostOfficial: "\u5B98\u65B9\u6E90",
|
|
1963
1967
|
hostMirror: "\u56FD\u5185\u955C\u50CF",
|
|
1964
1968
|
engineBadgeCloud: "\u8BC6\u522B\u672C\u5730 \xB7 \u6717\u8BFB\u4E91\u7AEF",
|
|
1969
|
+
engineBadgeRemote: "\u8BC6\u522B\u672C\u5730 \xB7 \u6717\u8BFB\u8D70\u914D\u7F6E\u7684\u670D\u52A1",
|
|
1965
1970
|
engineBadgeLocal: "\u8BC6\u522B\u672C\u5730 \xB7 \u6717\u8BFB\u672C\u5730",
|
|
1966
1971
|
errRateLimited: "\u8BF7\u6C42\u8FC7\u4E8E\u9891\u7E41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5",
|
|
1967
1972
|
errUnknownSession: "\u8BED\u97F3\u4F1A\u8BDD\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u5F00\u542F\u8BED\u97F3\u6A21\u5F0F",
|
|
@@ -2046,10 +2051,14 @@ var en = {
|
|
|
2046
2051
|
voiceNext: "Next voice",
|
|
2047
2052
|
descVoice: "Edge cloud voices (auto-loads all Microsoft voices; common Chinese voices pinned on top; \u25C0\u25B6 or dropdown; custom ShortName allowed)",
|
|
2048
2053
|
descVoiceLocal: "Local voice (vits, all 5 speakers listed; dropdown or \u25C0\u25B6; no custom needed)",
|
|
2049
|
-
descTtsEngine: "Local VITS (Chinese only) / Local Kokoro (Chinese + English) / Edge cloud (most natural, text sent to Microsoft)",
|
|
2054
|
+
descTtsEngine: "Local VITS (Chinese only) / Local Kokoro (Chinese + English) / Edge cloud (most natural, text sent to Microsoft) / OpenAI-compatible server (self-hosted or hosted, text sent to the configured URL)",
|
|
2050
2055
|
engineVits: "Local VITS",
|
|
2051
2056
|
engineKokoro: "Local Kokoro",
|
|
2052
2057
|
engineEdge: "Edge cloud",
|
|
2058
|
+
engineOpenai: "OpenAI-compatible",
|
|
2059
|
+
descVoiceOpenai: "Voice name on the server (empty = openaiTts.voice from the config)",
|
|
2060
|
+
engineRemoteDown: "server unavailable",
|
|
2061
|
+
errRemoteTts: "The TTS server is unreachable, failing or too slow; the local fallback reads aloud meanwhile if one is configured",
|
|
2053
2062
|
descVoiceKokoro: "Kokoro zh-en voices (103; \u25C0\u25B6 to cycle; 48-51 named Chinese, others numbered with measured gender; mixed zh-en supported)",
|
|
2054
2063
|
descRate: "Speech rate (0.5 slow \u2013 2.0 fast, 1.1 default; more compact replies)",
|
|
2055
2064
|
descInterrupt: "Interrupt sensitivity (0 high \u22480.3 s confirm / 1 medium \u22480.2 s / 2 low \u22480.1 s, most responsive); lower = higher barrier = harder to interrupt",
|
|
@@ -2240,6 +2249,7 @@ var en = {
|
|
|
2240
2249
|
hostOfficial: "Official",
|
|
2241
2250
|
hostMirror: "Mirror (CN)",
|
|
2242
2251
|
engineBadgeCloud: "ASR local \xB7 TTS cloud",
|
|
2252
|
+
engineBadgeRemote: "ASR local \xB7 TTS on your configured server",
|
|
2243
2253
|
engineBadgeLocal: "ASR local \xB7 TTS local",
|
|
2244
2254
|
errRateLimited: "Too many requests \u2014 try again shortly",
|
|
2245
2255
|
errUnknownSession: "Voice session expired \u2014 re-enter voice mode",
|
|
@@ -2876,7 +2886,9 @@ var ENGINE_DEFAULT_VOICE = {
|
|
|
2876
2886
|
// 避免「config 直连」与「面板切引擎」落到不同默认音色。
|
|
2877
2887
|
vits: "suyingxue",
|
|
2878
2888
|
kokoro: "zf_xiaobei",
|
|
2879
|
-
edge: "zh-CN-XiaoxiaoNeural"
|
|
2889
|
+
edge: "zh-CN-XiaoxiaoNeural",
|
|
2890
|
+
// 空 = 用配置里的 openaiTts.voice(服务端音色名各家不同,没有通用默认)。
|
|
2891
|
+
openai: ""
|
|
2880
2892
|
};
|
|
2881
2893
|
function NumberField({
|
|
2882
2894
|
score,
|
|
@@ -3252,7 +3264,7 @@ function VoicePreviewButton({ voice, rate }) {
|
|
|
3252
3264
|
if (res.ok && alive) {
|
|
3253
3265
|
const st = await res.json();
|
|
3254
3266
|
const tts = st.tts;
|
|
3255
|
-
if (tts.engine === "edge") {
|
|
3267
|
+
if (tts.engine === "edge" || tts.engine === "openai") {
|
|
3256
3268
|
setLocalReady(true);
|
|
3257
3269
|
} else {
|
|
3258
3270
|
setLocalReady(!!tts.local?.ready);
|
|
@@ -3452,7 +3464,7 @@ function EngineStatusInline() {
|
|
|
3452
3464
|
}, []);
|
|
3453
3465
|
const tts = st?.tts;
|
|
3454
3466
|
if (!tts) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
|
|
3455
|
-
const engineName = tts.engine === "vits" ? t("engineVits") : tts.engine === "kokoro" ? t("engineKokoro") : t("engineEdge");
|
|
3467
|
+
const engineName = tts.engine === "vits" ? t("engineVits") : tts.engine === "kokoro" ? t("engineKokoro") : tts.engine === "openai" ? t("engineOpenai") : t("engineEdge");
|
|
3456
3468
|
const isLocal = !!tts.local;
|
|
3457
3469
|
const localReady = isLocal ? !!tts.local?.ready : false;
|
|
3458
3470
|
let statusText;
|
|
@@ -3461,7 +3473,7 @@ function EngineStatusInline() {
|
|
|
3461
3473
|
statusText = t("engineLoading");
|
|
3462
3474
|
statusColor = t2.term;
|
|
3463
3475
|
} else if (tts.error) {
|
|
3464
|
-
statusText = t("engineError");
|
|
3476
|
+
statusText = t(tts.engine === "openai" ? "engineRemoteDown" : "engineError");
|
|
3465
3477
|
statusColor = "var(--dsw-alias-state-error-primary)";
|
|
3466
3478
|
} else if (isLocal && !localReady) {
|
|
3467
3479
|
statusText = t("ttsModelsMissing");
|
|
@@ -3492,7 +3504,7 @@ function EngineStatusInline() {
|
|
|
3492
3504
|
borderRadius: 6,
|
|
3493
3505
|
background: "var(--dsw-alias-bg-layer-1)"
|
|
3494
3506
|
},
|
|
3495
|
-
children: t(tts.engine === "edge" ? "engineBadgeCloud" : "engineBadgeLocal")
|
|
3507
|
+
children: t(tts.engine === "edge" ? "engineBadgeCloud" : tts.engine === "openai" ? "engineBadgeRemote" : "engineBadgeLocal")
|
|
3496
3508
|
}
|
|
3497
3509
|
),
|
|
3498
3510
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 12, fontWeight: statusText === t("engineReady") || statusText === t("engineError") ? 600 : 400, color: statusColor }, children: statusText }),
|
|
@@ -3523,7 +3535,7 @@ function EngineStatusInline() {
|
|
|
3523
3535
|
children: acting ? acting === "clean" ? t("ttsDeleting") : t("ttsDownloading") : action === "clean" ? t("ttsDelete") : t("ttsDownload")
|
|
3524
3536
|
}
|
|
3525
3537
|
),
|
|
3526
|
-
tts.error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 11, color: "var(--dsw-alias-state-error-primary)", flexBasis: "100%" }, children: tts.errorCode === "kokoro_needs_node" ? t("errKokoroNeedsNode") : t("engineError") })
|
|
3538
|
+
tts.error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: 11, color: "var(--dsw-alias-state-error-primary)", flexBasis: "100%" }, children: tts.errorCode === "kokoro_needs_node" ? t("errKokoroNeedsNode") : tts.engine === "openai" ? t("errRemoteTts") : t("engineError") })
|
|
3527
3539
|
] });
|
|
3528
3540
|
}
|
|
3529
3541
|
function ModelStatusView() {
|
|
@@ -3631,7 +3643,7 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3631
3643
|
);
|
|
3632
3644
|
const value = snap?.value ?? {};
|
|
3633
3645
|
const unavailable = snap?.status === "unavailable" || snap?.status === "error";
|
|
3634
|
-
const engine = value.ttsEngine === "edge" ? "edge" : value.ttsEngine === "kokoro" ? "kokoro" : "vits";
|
|
3646
|
+
const engine = value.ttsEngine === "edge" ? "edge" : value.ttsEngine === "kokoro" ? "kokoro" : value.ttsEngine === "openai" ? "openai" : "vits";
|
|
3635
3647
|
const [edgeRaw, setEdgeRaw] = (0, import_react2.useState)(null);
|
|
3636
3648
|
(0, import_react2.useEffect)(() => {
|
|
3637
3649
|
if (engine !== "edge") return;
|
|
@@ -3643,7 +3655,7 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3643
3655
|
alive = false;
|
|
3644
3656
|
};
|
|
3645
3657
|
}, [engine]);
|
|
3646
|
-
const voiceOptions = engine === "edge" ? edgeRaw ? edgeAllOptions(edgeRaw, activeLocale()) : edgeCommonOptions() : engine === "kokoro" ? kokoroOptions() : vitsOptions();
|
|
3658
|
+
const voiceOptions = engine === "edge" ? edgeRaw ? edgeAllOptions(edgeRaw, activeLocale()) : edgeCommonOptions() : engine === "kokoro" ? kokoroOptions() : engine === "openai" ? [] : vitsOptions();
|
|
3647
3659
|
if (unavailable) {
|
|
3648
3660
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-dshvm-settings": "card", style: { color: t2.term, fontSize: 12, padding: "14px 16px", ...cardStyle }, children: [
|
|
3649
3661
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "var(--dsw-alias-state-error-primary)" }, children: t("configUnavailable") }),
|
|
@@ -3672,7 +3684,8 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3672
3684
|
options: [
|
|
3673
3685
|
{ v: "vits", label: t("engineVits") },
|
|
3674
3686
|
{ v: "kokoro", label: t("engineKokoro") },
|
|
3675
|
-
{ v: "edge", label: t("engineEdge") }
|
|
3687
|
+
{ v: "edge", label: t("engineEdge") },
|
|
3688
|
+
{ v: "openai", label: t("engineOpenai") }
|
|
3676
3689
|
],
|
|
3677
3690
|
onSelect: (v) => {
|
|
3678
3691
|
if (v !== engine) {
|
|
@@ -3698,7 +3711,7 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3698
3711
|
Row,
|
|
3699
3712
|
{
|
|
3700
3713
|
name: "voice",
|
|
3701
|
-
desc: (engine === "edge" ? t("descVoice") : engine === "kokoro" ? t("descVoiceKokoro") : t("descVoiceLocal")) + voiceLangHint(engine, String(value.voice ?? "")),
|
|
3714
|
+
desc: (engine === "edge" ? t("descVoice") : engine === "kokoro" ? t("descVoiceKokoro") : engine === "openai" ? t("descVoiceOpenai") : t("descVoiceLocal")) + voiceLangHint(engine, String(value.voice ?? "")),
|
|
3702
3715
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3703
3716
|
VoiceSelect,
|
|
3704
3717
|
{
|
|
@@ -3707,7 +3720,7 @@ function VoiceSettingsCard({ scope, defaultOpen = false }) {
|
|
|
3707
3720
|
value: value.voice ?? "",
|
|
3708
3721
|
options: voiceOptions,
|
|
3709
3722
|
placeholder: ENGINE_DEFAULT_VOICE[engine] ?? "zh-CN-XiaoxiaoNeural",
|
|
3710
|
-
showCustom: engine === "edge",
|
|
3723
|
+
showCustom: engine === "edge" || engine === "openai",
|
|
3711
3724
|
footer: (v) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VoicePreviewButton, { voice: v, rate: Number(value.rate ?? 1.1) })
|
|
3712
3725
|
}
|
|
3713
3726
|
)
|
|
@@ -4011,7 +4024,7 @@ function telemetryDeltas(tel) {
|
|
|
4011
4024
|
}
|
|
4012
4025
|
return out;
|
|
4013
4026
|
}
|
|
4014
|
-
var BUILD_TAG = "
|
|
4027
|
+
var BUILD_TAG = "b2fa61b";
|
|
4015
4028
|
var TELEMETRY_FLAG = "dsh-voice-mode.telemetry";
|
|
4016
4029
|
var telemetryEnabled = typeof localStorage !== "undefined" && localStorage.getItem(TELEMETRY_FLAG) === "1";
|
|
4017
4030
|
console.log("[dsh-voice] build=" + BUILD_TAG);
|
package/lib/index.js
CHANGED
|
@@ -2500,10 +2500,14 @@ var en = {
|
|
|
2500
2500
|
voiceNext: "Next voice",
|
|
2501
2501
|
descVoice: "Edge cloud voices (auto-loads all Microsoft voices; common Chinese voices pinned on top; \u25C0\u25B6 or dropdown; custom ShortName allowed)",
|
|
2502
2502
|
descVoiceLocal: "Local voice (vits, all 5 speakers listed; dropdown or \u25C0\u25B6; no custom needed)",
|
|
2503
|
-
descTtsEngine: "Local VITS (Chinese only) / Local Kokoro (Chinese + English) / Edge cloud (most natural, text sent to Microsoft)",
|
|
2503
|
+
descTtsEngine: "Local VITS (Chinese only) / Local Kokoro (Chinese + English) / Edge cloud (most natural, text sent to Microsoft) / OpenAI-compatible server (self-hosted or hosted, text sent to the configured URL)",
|
|
2504
2504
|
engineVits: "Local VITS",
|
|
2505
2505
|
engineKokoro: "Local Kokoro",
|
|
2506
2506
|
engineEdge: "Edge cloud",
|
|
2507
|
+
engineOpenai: "OpenAI-compatible",
|
|
2508
|
+
descVoiceOpenai: "Voice name on the server (empty = openaiTts.voice from the config)",
|
|
2509
|
+
engineRemoteDown: "server unavailable",
|
|
2510
|
+
errRemoteTts: "The TTS server is unreachable, failing or too slow; the local fallback reads aloud meanwhile if one is configured",
|
|
2507
2511
|
descVoiceKokoro: "Kokoro zh-en voices (103; \u25C0\u25B6 to cycle; 48-51 named Chinese, others numbered with measured gender; mixed zh-en supported)",
|
|
2508
2512
|
descRate: "Speech rate (0.5 slow \u2013 2.0 fast, 1.1 default; more compact replies)",
|
|
2509
2513
|
descInterrupt: "Interrupt sensitivity (0 high \u22480.3 s confirm / 1 medium \u22480.2 s / 2 low \u22480.1 s, most responsive); lower = higher barrier = harder to interrupt",
|
|
@@ -2694,6 +2698,7 @@ var en = {
|
|
|
2694
2698
|
hostOfficial: "Official",
|
|
2695
2699
|
hostMirror: "Mirror (CN)",
|
|
2696
2700
|
engineBadgeCloud: "ASR local \xB7 TTS cloud",
|
|
2701
|
+
engineBadgeRemote: "ASR local \xB7 TTS on your configured server",
|
|
2697
2702
|
engineBadgeLocal: "ASR local \xB7 TTS local",
|
|
2698
2703
|
errRateLimited: "Too many requests \u2014 try again shortly",
|
|
2699
2704
|
errUnknownSession: "Voice session expired \u2014 re-enter voice mode",
|
|
@@ -2787,6 +2792,160 @@ async function correctText(ctx, text, lang) {
|
|
|
2787
2792
|
}
|
|
2788
2793
|
}
|
|
2789
2794
|
|
|
2795
|
+
// src/tts-openai.ts
|
|
2796
|
+
var MIME = { mp3: "audio/mpeg", wav: "audio/wav" };
|
|
2797
|
+
var OpenAiTtsError = class extends Error {
|
|
2798
|
+
code;
|
|
2799
|
+
constructor(code, message) {
|
|
2800
|
+
super(message);
|
|
2801
|
+
this.name = "OpenAiTtsError";
|
|
2802
|
+
this.code = code;
|
|
2803
|
+
}
|
|
2804
|
+
};
|
|
2805
|
+
function speechUrl(baseUrl) {
|
|
2806
|
+
const url = new URL(baseUrl.trim());
|
|
2807
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
2808
|
+
throw new OpenAiTtsError("openai_bad_url", "baseUrl must be http(s)");
|
|
2809
|
+
}
|
|
2810
|
+
const noSlash = url.pathname.replace(/\/+$/, "");
|
|
2811
|
+
const base = noSlash.endsWith("/audio/speech") ? noSlash.slice(0, -"/audio/speech".length) : noSlash;
|
|
2812
|
+
url.pathname = `${base}/audio/speech`;
|
|
2813
|
+
return url.toString();
|
|
2814
|
+
}
|
|
2815
|
+
var OpenAiTtsEngine = class {
|
|
2816
|
+
voice;
|
|
2817
|
+
rate;
|
|
2818
|
+
url;
|
|
2819
|
+
configError;
|
|
2820
|
+
format;
|
|
2821
|
+
timeoutMs;
|
|
2822
|
+
cooldownMs;
|
|
2823
|
+
fetchImpl;
|
|
2824
|
+
now;
|
|
2825
|
+
fallbackEngine = null;
|
|
2826
|
+
inflight = /* @__PURE__ */ new Set();
|
|
2827
|
+
downUntil = 0;
|
|
2828
|
+
lastError;
|
|
2829
|
+
lastMime;
|
|
2830
|
+
options;
|
|
2831
|
+
constructor(options) {
|
|
2832
|
+
this.options = options;
|
|
2833
|
+
let url = null;
|
|
2834
|
+
try {
|
|
2835
|
+
if (!options.baseUrl.trim() || !options.model.trim()) throw new OpenAiTtsError("openai_not_configured", "openaiTts.baseUrl and openaiTts.model are required");
|
|
2836
|
+
url = speechUrl(options.baseUrl);
|
|
2837
|
+
} catch (e) {
|
|
2838
|
+
this.configError = e instanceof OpenAiTtsError ? e : new OpenAiTtsError("openai_bad_url", String(e));
|
|
2839
|
+
}
|
|
2840
|
+
this.url = url;
|
|
2841
|
+
this.lastError = this.configError;
|
|
2842
|
+
this.voice = options.voice;
|
|
2843
|
+
this.format = options.responseFormat ?? "mp3";
|
|
2844
|
+
this.timeoutMs = options.timeoutMs ?? 8e3;
|
|
2845
|
+
this.cooldownMs = options.cooldownMs ?? 3e4;
|
|
2846
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
2847
|
+
this.now = options.now ?? Date.now;
|
|
2848
|
+
this.lastMime = MIME[this.format];
|
|
2849
|
+
}
|
|
2850
|
+
/** 最近一次成功合成所用格式(远程或回退引擎的 MIME 可能不同;队列在 synthesize 之后读取)。 */
|
|
2851
|
+
get mime() {
|
|
2852
|
+
return this.lastMime;
|
|
2853
|
+
}
|
|
2854
|
+
updateVoice(voice, rate) {
|
|
2855
|
+
this.voice = voice || this.options.voice;
|
|
2856
|
+
if (rate !== void 0 && Number.isFinite(rate)) this.rate = rate;
|
|
2857
|
+
}
|
|
2858
|
+
async synthesize(text, options = {}) {
|
|
2859
|
+
const input = stripEmotionTags(text).replace(/\s+/g, " ").trim();
|
|
2860
|
+
if (input === "") return Buffer.alloc(0);
|
|
2861
|
+
if (this.now() >= this.downUntil) {
|
|
2862
|
+
try {
|
|
2863
|
+
const buf = await this.remote(input, options);
|
|
2864
|
+
this.lastError = void 0;
|
|
2865
|
+
this.lastMime = MIME[this.format];
|
|
2866
|
+
return buf;
|
|
2867
|
+
} catch (e) {
|
|
2868
|
+
if (e.name === "AbortError" && !(e instanceof OpenAiTtsError)) throw e;
|
|
2869
|
+
const err = e instanceof OpenAiTtsError ? e : new OpenAiTtsError("openai_unreachable", String(e));
|
|
2870
|
+
this.lastError = err;
|
|
2871
|
+
this.downUntil = this.now() + this.cooldownMs;
|
|
2872
|
+
if (!this.options.fallback) throw err;
|
|
2873
|
+
console.warn(`[dsh-voice-mode] remote TTS failed, using the local fallback for ${this.cooldownMs} ms: ${err.message}`);
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
return this.viaFallback(text, options);
|
|
2877
|
+
}
|
|
2878
|
+
async remote(input, options) {
|
|
2879
|
+
if (this.url === null) throw this.configError;
|
|
2880
|
+
const body = {
|
|
2881
|
+
model: this.options.model,
|
|
2882
|
+
input,
|
|
2883
|
+
voice: options.voice || this.voice,
|
|
2884
|
+
response_format: this.format
|
|
2885
|
+
};
|
|
2886
|
+
const rate = options.rate ?? this.rate;
|
|
2887
|
+
if (rate !== void 0 && rate > 0 && rate !== 1) body.speed = rate;
|
|
2888
|
+
if (this.options.instructions) body.instructions = this.options.instructions;
|
|
2889
|
+
const headers = { "content-type": "application/json" };
|
|
2890
|
+
if (this.options.apiKey) headers.authorization = `Bearer ${this.options.apiKey}`;
|
|
2891
|
+
const ac = new AbortController();
|
|
2892
|
+
let timedOut = false;
|
|
2893
|
+
const timer = setTimeout(() => {
|
|
2894
|
+
timedOut = true;
|
|
2895
|
+
ac.abort();
|
|
2896
|
+
}, this.timeoutMs);
|
|
2897
|
+
this.inflight.add(ac);
|
|
2898
|
+
try {
|
|
2899
|
+
const res = await this.fetchImpl(this.url, { method: "POST", headers, body: JSON.stringify(body), signal: ac.signal });
|
|
2900
|
+
if (!res.ok) {
|
|
2901
|
+
const detail = (await res.text().catch(() => "")).slice(0, 200);
|
|
2902
|
+
throw new OpenAiTtsError("openai_http_error", `HTTP ${res.status}${detail ? `: ${detail}` : ""}`);
|
|
2903
|
+
}
|
|
2904
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
2905
|
+
if (buf.length === 0) throw new OpenAiTtsError("openai_empty_audio", "empty audio");
|
|
2906
|
+
return buf;
|
|
2907
|
+
} catch (e) {
|
|
2908
|
+
if (timedOut) throw new OpenAiTtsError("openai_timeout", `no audio within ${this.timeoutMs} ms`);
|
|
2909
|
+
throw e;
|
|
2910
|
+
} finally {
|
|
2911
|
+
clearTimeout(timer);
|
|
2912
|
+
this.inflight.delete(ac);
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
async viaFallback(text, options) {
|
|
2916
|
+
if (!this.options.fallback) {
|
|
2917
|
+
throw this.lastError ?? new OpenAiTtsError("openai_unreachable", "remote TTS unavailable");
|
|
2918
|
+
}
|
|
2919
|
+
this.fallbackEngine ??= this.options.fallback();
|
|
2920
|
+
const buf = await this.fallbackEngine.synthesize(text, { rate: options.rate ?? this.rate });
|
|
2921
|
+
this.lastMime = this.fallbackEngine.mime;
|
|
2922
|
+
return buf;
|
|
2923
|
+
}
|
|
2924
|
+
interrupt() {
|
|
2925
|
+
for (const ac of this.inflight) ac.abort();
|
|
2926
|
+
this.inflight.clear();
|
|
2927
|
+
this.fallbackEngine?.interrupt?.();
|
|
2928
|
+
}
|
|
2929
|
+
status() {
|
|
2930
|
+
const fallingBack = this.now() < this.downUntil;
|
|
2931
|
+
return {
|
|
2932
|
+
engine: "openai",
|
|
2933
|
+
// 未配置(baseUrl/model 缺失)即非就绪:ready 与 error 必须一致,
|
|
2934
|
+
// 不得出现 ready=true 却带 openai_not_configured 的矛盾态。
|
|
2935
|
+
ready: !fallingBack && !this.configError,
|
|
2936
|
+
loading: false,
|
|
2937
|
+
error: this.lastError?.message,
|
|
2938
|
+
errorCode: this.lastError?.code
|
|
2939
|
+
};
|
|
2940
|
+
}
|
|
2941
|
+
async close() {
|
|
2942
|
+
this.interrupt();
|
|
2943
|
+
const fb = this.fallbackEngine;
|
|
2944
|
+
this.fallbackEngine = null;
|
|
2945
|
+
await fb?.close();
|
|
2946
|
+
}
|
|
2947
|
+
};
|
|
2948
|
+
|
|
2790
2949
|
// src/prompts.ts
|
|
2791
2950
|
var ZH = "\u3010\u8BED\u97F3\u6A21\u5F0F\u3011\u5F53\u524D\u56DE\u590D\u4F1A\u88AB\u8BED\u97F3\u6717\u8BFB\uFF0C\u8BF7\u59CB\u7EC8\u7528\u7528\u6237\u6240\u7528\u8BED\u8A00\u3001\u4EE5\u53E3\u8BED\u5316\u7684\u77ED\u53E5\u76F4\u63A5\u56DE\u7B54\uFF0C\u50CF\u9762\u5BF9\u9762\u804A\u5929\u4E00\u6837\u81EA\u7136\uFF0C\u907F\u514D\u4E66\u9762\u8BED\u548C\u957F\u96BE\u53E5\u3002\u4E0D\u8981\u4F7F\u7528\u4EFB\u4F55 Markdown \u6216\u6392\u7248\u7B26\u53F7\uFF08\u661F\u53F7\u3001\u4E0B\u5212\u7EBF\u3001\u53CD\u5F15\u53F7\u3001\u4E95\u53F7\u3001\u5217\u8868\u4E0E\u8868\u683C\u6807\u8BB0\u3001\u4EE3\u7801\u5757\u7B49\uFF09\u3002\u9700\u8981\u5206\u70B9\u8BF4\u660E\u65F6\u7528\u300C\u7B2C\u4E00\u3001\u7B2C\u4E8C\u300D\u6216\u8FDE\u8D2F\u7684\u77ED\u53E5\u8868\u8FBE\uFF1B\u9664\u975E\u7528\u6237\u660E\u786E\u8981\u6C42\uFF0C\u4E0D\u8981\u8F93\u51FA\u4EE3\u7801\u7247\u6BB5\u3001\u5B8C\u6574 URL \u6216\u5197\u957F\u5B9A\u4E49\uFF0C\u7528\u4E00\u4E24\u53E5\u8BDD\u6982\u62EC\u542B\u4E49\u5373\u53EF\u3002\u56DE\u7B54\u7B80\u6D01\u76F4\u63A5\uFF0C\u4E0D\u8981\u91CD\u590D\u548C\u5BD2\u6684\u3002\u5982\u679C\u7528\u6237\u5728\u4F60\u6717\u8BFB\u65F6\u63D2\u8BDD\uFF08\u54EA\u6015\u53EA\u662F\u300C\u55EF/\u5BF9\u300D\u8FD9\u6837\u7684\u77ED\u5E94\u7B54\uFF09\uFF0C\u7ACB\u5373\u505C\u6B62\u5F53\u524D\u53E5\uFF0C\u628A\u8BDD\u8F6E\u8BA9\u7ED9\u7528\u6237\uFF1B\u56DE\u7B54\u540E\u7559\u51FA\u505C\u987F\uFF0C\u4E0D\u8981\u8FDE\u95EE\u4E24\u4E2A\u95EE\u9898\uFF1B\u7528\u6237\u6C89\u9ED8\u65F6\u4E0D\u8981\u4E3B\u52A8\u627E\u65B0\u8BDD\u9898\u3002";
|
|
2792
2951
|
var EN = '[Voice mode] Your reply will be read aloud. Always answer in the language the user is using, in short conversational sentences, directly and naturally, as if talking face to face; avoid written-style phrasing and long, complex sentences. Do not use any Markdown or formatting symbols (asterisks, underscores, backticks, hash signs, list or table markup, code blocks, etc.). When you need to list points, say them as "first, second" or as connected short sentences; unless the user explicitly asks, do not output code snippets, full URLs or lengthy definitions \u2014 summarize the meaning in a sentence or two. Keep answers concise and direct; no repetition or pleasantries. If the user interrupts while you are being read aloud (even with a short acknowledgment like "uh-huh" or "yeah"), stop the current sentence immediately and yield the turn; leave a pause after answering and never ask two questions in a row; when the user is silent, do not bring up a new topic on your own.';
|
|
@@ -2810,7 +2969,7 @@ var SAMPLE_BY_LANG = {
|
|
|
2810
2969
|
ru: "\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u0434\u043E\u0431\u0440\u043E \u043F\u043E\u0436\u0430\u043B\u043E\u0432\u0430\u0442\u044C \u0432 \u0433\u043E\u043B\u043E\u0441\u043E\u0432\u043E\u0439 \u0440\u0435\u0436\u0438\u043C."
|
|
2811
2970
|
};
|
|
2812
2971
|
function previewSample(engine, voice) {
|
|
2813
|
-
if (engine === "kokoro") return `${SAMPLE_ZH}${SAMPLE_EN}`;
|
|
2972
|
+
if (engine === "kokoro" || engine === "openai") return `${SAMPLE_ZH}${SAMPLE_EN}`;
|
|
2814
2973
|
if (engine === "vits") return SAMPLE_ZH;
|
|
2815
2974
|
const m = /^([a-z]{2,3})-/i.exec(voice);
|
|
2816
2975
|
return m && SAMPLE_BY_LANG[m[1].toLowerCase()] || SAMPLE_EN;
|
|
@@ -3011,7 +3170,7 @@ var DESC = {
|
|
|
3011
3170
|
function createVoiceSettingsSchema(defs) {
|
|
3012
3171
|
const d = { ...VOICE_SETTINGS_DEFAULTS, ...defs };
|
|
3013
3172
|
return z.object({
|
|
3014
|
-
ttsEngine: z.union([z.const("vits"), z.const("kokoro"), z.const("edge")]).default(d.ttsEngine).description(
|
|
3173
|
+
ttsEngine: z.union([z.const("vits"), z.const("kokoro"), z.const("edge"), z.const("openai")]).default(d.ttsEngine).description(
|
|
3015
3174
|
DESC.ttsEngine
|
|
3016
3175
|
),
|
|
3017
3176
|
kokoroModel: z.union([z.const("int8"), z.const("fp32")]).default(d.kokoroModel).description(
|
|
@@ -3068,11 +3227,23 @@ function createVoiceSettingsSchema(defs) {
|
|
|
3068
3227
|
});
|
|
3069
3228
|
}
|
|
3070
3229
|
var VoiceSettingsSchema = createVoiceSettingsSchema();
|
|
3230
|
+
var OpenAiTtsConfig = z.object({
|
|
3231
|
+
baseUrl: z.string().default("").description("API base URL, e.g. https://api.openai.com/v1, https://openrouter.ai/api/v1 or a self-hosted server."),
|
|
3232
|
+
apiKey: z.string().role("secret").default("").description("Bearer key; leave empty for servers without auth."),
|
|
3233
|
+
model: z.string().default("").description("Model name sent to the server."),
|
|
3234
|
+
voice: z.string().default("").description("Default voice name on the server (the voice setting overrides it)."),
|
|
3235
|
+
instructions: z.string().default("").description("Optional style instructions for models that accept them."),
|
|
3236
|
+
responseFormat: z.union([z.const("mp3"), z.const("wav")]).default("mp3"),
|
|
3237
|
+
timeoutMs: z.number().min(1e3).max(6e4).default(8e3).description("Per-sentence timeout; slower counts as unavailable."),
|
|
3238
|
+
fallback: z.union([z.const("none"), z.const("vits"), z.const("kokoro")]).default("none").description("Local engine used while the server is unreachable or slow."),
|
|
3239
|
+
fallbackVoice: z.string().default("").description("Voice for the fallback engine (empty = its default).")
|
|
3240
|
+
});
|
|
3071
3241
|
var Config = z.object({
|
|
3072
3242
|
enabled: z.boolean().default(true),
|
|
3073
3243
|
cacheDir: z.string().default(defaultModelCacheDir()),
|
|
3074
3244
|
modelHost: z.string().default("https://huggingface.co"),
|
|
3075
|
-
ttsEngine: z.union([z.const("edge"), z.const("vits"), z.const("kokoro")]).default("edge"),
|
|
3245
|
+
ttsEngine: z.union([z.const("edge"), z.const("vits"), z.const("kokoro"), z.const("openai")]).default("edge"),
|
|
3246
|
+
openaiTts: OpenAiTtsConfig,
|
|
3076
3247
|
kokoroModel: z.union([z.const("int8"), z.const("fp32")]).default("int8"),
|
|
3077
3248
|
allowLan: z.boolean().default(false),
|
|
3078
3249
|
allowCustomModelHost: z.boolean().default(false),
|
|
@@ -3373,6 +3544,24 @@ function apply(ctx, config) {
|
|
|
3373
3544
|
warmupAsrIfCached();
|
|
3374
3545
|
const makeEngine = (kind) => {
|
|
3375
3546
|
if (kind === "edge") return new EdgeTtsEngine(config.voice, config.rate);
|
|
3547
|
+
if (kind === "openai") {
|
|
3548
|
+
const o = config.openaiTts;
|
|
3549
|
+
const fallbackKind = o.fallback;
|
|
3550
|
+
return new OpenAiTtsEngine({
|
|
3551
|
+
baseUrl: o.baseUrl,
|
|
3552
|
+
apiKey: o.apiKey || void 0,
|
|
3553
|
+
model: o.model,
|
|
3554
|
+
voice: o.voice,
|
|
3555
|
+
instructions: o.instructions || void 0,
|
|
3556
|
+
responseFormat: o.responseFormat,
|
|
3557
|
+
timeoutMs: o.timeoutMs,
|
|
3558
|
+
fallback: fallbackKind === "none" ? void 0 : () => {
|
|
3559
|
+
const local = makeEngine(fallbackKind);
|
|
3560
|
+
if (o.fallbackVoice) local.updateVoice(o.fallbackVoice, vset.rate);
|
|
3561
|
+
return local;
|
|
3562
|
+
}
|
|
3563
|
+
});
|
|
3564
|
+
}
|
|
3376
3565
|
if (kind === "kokoro") {
|
|
3377
3566
|
return createSherpaKokoroEngine({
|
|
3378
3567
|
cacheDir: config.cacheDir,
|
|
@@ -4249,6 +4438,7 @@ async function* tapActiveStream(sessionId, inner, queue, broadcast, onTurn, spea
|
|
|
4249
4438
|
}
|
|
4250
4439
|
export {
|
|
4251
4440
|
Config,
|
|
4441
|
+
OpenAiTtsConfig,
|
|
4252
4442
|
VoiceSettingsSchema,
|
|
4253
4443
|
apply,
|
|
4254
4444
|
createVoiceSettingsSchema,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-voice-mode",
|
|
3
3
|
"description": "Voice plugin for DeepSeek Harness: local streaming speech recognition into editable drafts, sentence-by-sentence read-aloud with captions, and voice interruption. Edge online or local VITS/Kokoro TTS; host compatibility is bounded by engines.dsh.",
|
|
4
4
|
"icon": "./icon.svg",
|
|
5
|
-
"version": "0.7.
|
|
5
|
+
"version": "0.7.39",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"repository": {
|