dsh-laivox-tts 0.7.25 → 0.7.26
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 +1 -1
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/host/edge.mjs +162 -170
package/README.en.md
CHANGED
|
@@ -38,7 +38,7 @@ This installs the prebuilt package from npm—nothing is compiled locally and no
|
|
|
38
38
|
|
|
39
39
|
### Install from GitHub Release or offline package
|
|
40
40
|
|
|
41
|
-
If npm is unavailable or you prefer pinning a release tarball, install via URL or download `dsh-laivox-tts.tgz` from [Releases](https://github.com/xiaolai181/dsh_laivox_tts/releases) (replace `latest/download` with `download/v0.7.
|
|
41
|
+
If npm is unavailable or you prefer pinning a release tarball, install via URL or download `dsh-laivox-tts.tgz` from [Releases](https://github.com/xiaolai181/dsh_laivox_tts/releases) (replace `latest/download` with `download/v0.7.26` to pin a version):
|
|
42
42
|
|
|
43
43
|
```sh
|
|
44
44
|
dsh plugin --profile desktop add "https://github.com/xiaolai181/dsh_laivox_tts/releases/latest/download/dsh-laivox-tts.tgz"
|
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ dsh plugin --profile desktop add dsh-laivox-tts
|
|
|
40
40
|
|
|
41
41
|
### GitHub Release 链接或离线安装包安装
|
|
42
42
|
|
|
43
|
-
如需锁定版本或无法直连 npm,可使用 Release 下载链接(将 `latest/download` 替换为 `download/v0.7.
|
|
43
|
+
如需锁定版本或无法直连 npm,可使用 Release 下载链接(将 `latest/download` 替换为 `download/v0.7.26` 可锁定版本),或从 [Releases](https://github.com/xiaolai181/dsh_laivox_tts/releases) 下载 `dsh-laivox-tts.tgz` 到本地后安装:
|
|
44
44
|
|
|
45
45
|
```sh
|
|
46
46
|
dsh plugin --profile desktop add "https://github.com/xiaolai181/dsh_laivox_tts/releases/latest/download/dsh-laivox-tts.tgz"
|
package/package.json
CHANGED
package/src/host/edge.mjs
CHANGED
|
@@ -1,170 +1,162 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process'
|
|
2
|
-
import { setTimeout as delay } from 'node:timers/promises'
|
|
3
|
-
import { fileURLToPath } from 'node:url'
|
|
4
|
-
import { hasSpeakable } from '../domain/segment.mjs'
|
|
5
|
-
|
|
6
|
-
// Order matters: chooseVoices hands out the first unused voice of a matching
|
|
7
|
-
// gender, so new voices are only ever appended. Appending leaves every role that
|
|
8
|
-
// already had its own voice untouched. auto: false voices (regional accents)
|
|
9
|
-
// are offered in the picker but never assigned automatically.
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{ id: 'zh-CN-
|
|
17
|
-
{ id: 'zh-CN-
|
|
18
|
-
{ id: 'zh-CN-
|
|
19
|
-
{ id: 'zh-
|
|
20
|
-
{ id: 'zh-TW-
|
|
21
|
-
{ id: 'zh-
|
|
22
|
-
{ id: 'zh-CN-
|
|
23
|
-
{ id: 'zh-CN-
|
|
24
|
-
{ id: '
|
|
25
|
-
{ id: '
|
|
26
|
-
{ id: '
|
|
27
|
-
{ id: '
|
|
28
|
-
{ id: '
|
|
29
|
-
{ id: '
|
|
30
|
-
{ id: 'zh-CN-
|
|
31
|
-
{ id: '
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
child.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// An empty turn is its own failure: it is a content result, not an outage.
|
|
164
|
-
const error = failure ?? (reported === 'EDGE_EMPTY_AUDIO' ? new Error('EDGE_EMPTY_AUDIO') : new Error('EDGE_UNAVAILABLE'))
|
|
165
|
-
if (detail && !error.detail) error.detail = detail
|
|
166
|
-
reject(error)
|
|
167
|
-
})
|
|
168
|
-
child.stdin.end(JSON.stringify(input))
|
|
169
|
-
})
|
|
170
|
-
}
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { hasSpeakable } from '../domain/segment.mjs'
|
|
5
|
+
|
|
6
|
+
// Order matters: chooseVoices hands out the first unused voice of a matching
|
|
7
|
+
// gender, so new voices are only ever appended. Appending leaves every role that
|
|
8
|
+
// already had its own voice untouched. auto: false voices (regional accents)
|
|
9
|
+
// are offered in the picker but never assigned automatically.
|
|
10
|
+
// Use only IDs listed by the Edge Read Aloud voice directory.
|
|
11
|
+
// Added after 10/10 real synthesis runs each (5 simplified, 5
|
|
12
|
+
// traditional); zh-TW-YunJheNeural failed 4/10 with truncated streams and is excluded.
|
|
13
|
+
// Later voices are appended. Chinese automatic assignment still walks the
|
|
14
|
+
// original zh-CN / zh-TW entries first, so roles that already had a voice keep it.
|
|
15
|
+
export const edgeVoices = [
|
|
16
|
+
{ id: 'zh-CN-XiaoxiaoNeural', name: '晓晓', gender: 'female', age: 'adult', auto: true },
|
|
17
|
+
{ id: 'zh-CN-YunxiNeural', name: '云希', gender: 'male', age: 'adult', auto: true },
|
|
18
|
+
{ id: 'zh-CN-YunjianNeural', name: '云健', gender: 'male', age: 'adult', auto: true },
|
|
19
|
+
{ id: 'zh-CN-XiaoyiNeural', name: '晓伊', gender: 'female', age: 'adult', auto: true },
|
|
20
|
+
{ id: 'zh-TW-HsiaoChenNeural', name: '曉臻', gender: 'female', age: 'adult', auto: true },
|
|
21
|
+
{ id: 'zh-TW-HsiaoYuNeural', name: '曉雨', gender: 'female', age: 'adult', auto: true },
|
|
22
|
+
{ id: 'zh-CN-YunyangNeural', name: '云扬', gender: 'male', age: 'adult', auto: true },
|
|
23
|
+
{ id: 'zh-CN-YunxiaNeural', name: '云夏', gender: 'male', age: 'child', auto: true },
|
|
24
|
+
{ id: 'en-US-AriaNeural', name: 'Aria(美式英语)', gender: 'female', age: 'adult', auto: true },
|
|
25
|
+
{ id: 'en-US-JennyNeural', name: 'Jenny(美式英语)', gender: 'female', age: 'adult', auto: true },
|
|
26
|
+
{ id: 'en-US-GuyNeural', name: 'Guy(美式英语)', gender: 'male', age: 'adult', auto: true },
|
|
27
|
+
{ id: 'en-GB-SoniaNeural', name: 'Sonia(英式英语)', gender: 'female', age: 'adult', auto: true },
|
|
28
|
+
{ id: 'en-GB-RyanNeural', name: 'Ryan(英式英语)', gender: 'male', age: 'adult', auto: true },
|
|
29
|
+
{ id: 'en-US-AnaNeural', name: 'Ana(美式英语)', gender: 'female', age: 'child', auto: true },
|
|
30
|
+
{ id: 'zh-CN-liaoning-XiaobeiNeural', name: '晓北(东北口音)', gender: 'female', age: 'adult', auto: false },
|
|
31
|
+
{ id: 'zh-CN-shaanxi-XiaoniNeural', name: '晓妮(陕西口音)', gender: 'female', age: 'adult', auto: false },
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
const workerFile = fileURLToPath(new URL('./edge-worker.mjs', import.meta.url))
|
|
35
|
+
const DETAIL_LIMIT = 600
|
|
36
|
+
const STDERR_LIMIT = 8 * 1024
|
|
37
|
+
|
|
38
|
+
// Pauses between attempts. Three attempts in total ride out short network
|
|
39
|
+
// blips before the job pauses with the last error.
|
|
40
|
+
export const EDGE_RETRY_WAITS = [800, 2500]
|
|
41
|
+
|
|
42
|
+
export async function retryEdge(once, signal, waits = EDGE_RETRY_WAITS, wait = delay) {
|
|
43
|
+
for (let attempt = 0; ; attempt++) {
|
|
44
|
+
signal.throwIfAborted()
|
|
45
|
+
try {
|
|
46
|
+
return await once()
|
|
47
|
+
} catch (error) {
|
|
48
|
+
signal.throwIfAborted()
|
|
49
|
+
if (attempt >= waits.length) throw error
|
|
50
|
+
await wait(waits[attempt], undefined, { signal })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function synthesizeEdge(input, signal, options = {}) {
|
|
56
|
+
if (!edgeVoices.some(voice => voice.id === input.voiceId)) throw new Error('EDGE_INVALID_VOICE')
|
|
57
|
+
if (![...input.text].length || [...input.text].length > 500) throw new Error('EDGE_INVALID_TEXT')
|
|
58
|
+
return retryEdge(() => synthesizeOnce(input, signal, options), signal, edgeRetryWaits(input.text))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Text with nothing to pronounce comes back empty on every attempt, so a second
|
|
62
|
+
// try only costs another connection and another few seconds of the job.
|
|
63
|
+
export function edgeRetryWaits(text) {
|
|
64
|
+
return hasSpeakable(text) ? EDGE_RETRY_WAITS : []
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const strip = value => String(value ?? '').replace(/\u001b\[[0-9;]*m/gu, '').replace(/\r/gu, '').trim()
|
|
68
|
+
|
|
69
|
+
// Turn the child's stderr into one short line. The worker writes a JSON error
|
|
70
|
+
// line for expected msedge-tts failures; crashes fall back to the last lines.
|
|
71
|
+
// The reported code lets the parent pick a concrete error instead of always
|
|
72
|
+
// calling it an outage.
|
|
73
|
+
function edgeFailure(stderr) {
|
|
74
|
+
const raw = strip(stderr)
|
|
75
|
+
if (!raw) return { detail: '', code: null }
|
|
76
|
+
const lines = raw.split('\n').map(line => line.trim()).filter(Boolean)
|
|
77
|
+
for (let index = lines.length - 1; index >= 0; index--) {
|
|
78
|
+
if (!lines[index].startsWith('{')) continue
|
|
79
|
+
try {
|
|
80
|
+
const value = JSON.parse(lines[index])
|
|
81
|
+
if (value && typeof value.message === 'string' && value.message) {
|
|
82
|
+
const name = typeof value.error === 'string' && value.error ? value.error + ': ' : ''
|
|
83
|
+
const code = value.code ? ' (' + value.code + ')' : ''
|
|
84
|
+
return {
|
|
85
|
+
detail: (name + value.message + code).slice(0, DETAIL_LIMIT),
|
|
86
|
+
code: typeof value.code === 'string' && value.code ? value.code : null,
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} catch { /* not the structured line */ }
|
|
90
|
+
}
|
|
91
|
+
return { detail: lines.slice(-4).join(' | ').slice(0, DETAIL_LIMIT), code: null }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function edgeFailureDetail(stderr) {
|
|
95
|
+
return edgeFailure(stderr).detail
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const TIMING_LIMIT = 512 * 1024
|
|
99
|
+
|
|
100
|
+
// Words as { o: start ms, d: duration ms, t: text } in speaking order; anything unreadable yields none.
|
|
101
|
+
export function parseTiming(raw) {
|
|
102
|
+
const line = String(raw ?? '').trim().split('\n').at(-1)
|
|
103
|
+
if (!line) return []
|
|
104
|
+
try {
|
|
105
|
+
const words = JSON.parse(line)
|
|
106
|
+
return Array.isArray(words) ? words.filter(word => Number.isFinite(word?.o) && Number.isFinite(word?.d) && typeof word?.t === 'string' && word.t) : []
|
|
107
|
+
} catch { return [] }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function synthesizeOnce(input, signal, { timeout = 23_000, command = process.execPath, args = [workerFile] } = {}) {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
const child = spawn(command, args, {
|
|
113
|
+
// fd 3 carries word timing from the worker (one JSON line).
|
|
114
|
+
windowsHide: true, stdio: ['pipe', 'pipe', 'pipe', 'pipe'],
|
|
115
|
+
env: { ...process.env, NODE_OPTIONS: '', ELECTRON_RUN_AS_NODE: '1' },
|
|
116
|
+
})
|
|
117
|
+
const chunks = []
|
|
118
|
+
let size = 0
|
|
119
|
+
let stderr = ''
|
|
120
|
+
let timing = ''
|
|
121
|
+
let failure
|
|
122
|
+
function terminate(error) {
|
|
123
|
+
failure ??= error
|
|
124
|
+
child.kill()
|
|
125
|
+
}
|
|
126
|
+
const abort = () => terminate(signal.reason)
|
|
127
|
+
const timer = setTimeout(() => terminate(new Error('EDGE_TIMEOUT')), timeout)
|
|
128
|
+
signal.addEventListener('abort', abort, { once: true })
|
|
129
|
+
if (signal.aborted) abort()
|
|
130
|
+
child.stdout.on('data', chunk => {
|
|
131
|
+
size += chunk.length
|
|
132
|
+
if (size <= 8 * 1024 * 1024) chunks.push(chunk)
|
|
133
|
+
else terminate(new Error('EDGE_AUDIO_TOO_LARGE'))
|
|
134
|
+
})
|
|
135
|
+
child.stderr.on('data', chunk => {
|
|
136
|
+
if (stderr.length < STDERR_LIMIT) stderr += chunk.toString('utf8')
|
|
137
|
+
})
|
|
138
|
+
child.stdio[3]?.on('data', chunk => { if (timing.length < TIMING_LIMIT) timing += chunk.toString('utf8') })
|
|
139
|
+
child.stdio[3]?.on('error', () => {})
|
|
140
|
+
child.stdin.on('error', () => {})
|
|
141
|
+
child.on('error', error => {
|
|
142
|
+
failure ??= Object.assign(new Error('EDGE_WORKER_START_FAILED'), { detail: strip(error?.message ?? error) || null })
|
|
143
|
+
})
|
|
144
|
+
child.on('close', code => {
|
|
145
|
+
clearTimeout(timer)
|
|
146
|
+
signal.removeEventListener('abort', abort)
|
|
147
|
+
if (!failure && code === 0 && size > 0) {
|
|
148
|
+
// The audio stays a Buffer for every caller; timing rides along as a property.
|
|
149
|
+
const audio = Buffer.concat(chunks)
|
|
150
|
+
audio.marks = parseTiming(timing)
|
|
151
|
+
resolve(audio)
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
const { detail, code: reported } = edgeFailure(stderr)
|
|
155
|
+
// An empty turn is its own failure: it is a content result, not an outage.
|
|
156
|
+
const error = failure ?? (reported === 'EDGE_EMPTY_AUDIO' ? new Error('EDGE_EMPTY_AUDIO') : new Error('EDGE_UNAVAILABLE'))
|
|
157
|
+
if (detail && !error.detail) error.detail = detail
|
|
158
|
+
reject(error)
|
|
159
|
+
})
|
|
160
|
+
child.stdin.end(JSON.stringify(input))
|
|
161
|
+
})
|
|
162
|
+
}
|