@goodandready/dsh-tts 0.3.23 → 0.4.1
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.md +22 -12
- package/README.ru.md +23 -10
- package/README.zh.md +18 -10
- package/lib/cache.js +4 -5
- package/lib/client-src/00-open.js +85 -0
- package/lib/client-src/10-styles.js +54 -0
- package/lib/client-src/20-player.js +290 -0
- package/lib/client-src/30-locales.js +325 -0
- package/lib/client-src/40-editors.js +410 -0
- package/lib/client-src/50-settings.js +341 -0
- package/lib/client-src/60-card-dock.js +229 -0
- package/lib/client.js +651 -506
- package/lib/engines/f5.js +45 -33
- package/lib/engines/kokoro.js +21 -29
- package/lib/engines/types.js +26 -13
- package/lib/http-util.js +27 -0
- package/lib/index.js +43 -455
- package/lib/providers.js +29 -18
- package/lib/routes.js +403 -0
- package/lib/stream-hub.js +31 -0
- package/lib/text.js +19 -19
- package/package.json +8 -3
- package/scripts/build-client.mjs +19 -0
- package/scripts/f5_daemon.py +40 -0
package/lib/engines/f5.js
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process'
|
|
2
2
|
|
|
3
|
+
function collectPing(pythonBin, daemonPath) {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
const proc = spawn(pythonBin, [daemonPath, '--ping'])
|
|
6
|
+
let out = ''
|
|
7
|
+
let settled = false
|
|
8
|
+
const done = (ok) => {
|
|
9
|
+
if (settled) return
|
|
10
|
+
settled = true
|
|
11
|
+
resolve(ok)
|
|
12
|
+
}
|
|
13
|
+
proc.stdout.on('data', (c) => { out += c })
|
|
14
|
+
proc.on('error', () => done(false))
|
|
15
|
+
proc.on('close', (code) => {
|
|
16
|
+
if (code !== 0) {
|
|
17
|
+
done(false)
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const res = JSON.parse(out)
|
|
22
|
+
done(!!res.ok)
|
|
23
|
+
} catch {
|
|
24
|
+
done(false)
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
3
30
|
export class F5Engine {
|
|
4
31
|
constructor({ daemonPath = 'scripts/f5_daemon.py', pythonBin = 'python3', modelPath = '' } = {}) {
|
|
5
32
|
this.daemonPath = daemonPath
|
|
@@ -7,39 +34,24 @@ export class F5Engine {
|
|
|
7
34
|
this.modelPath = modelPath
|
|
8
35
|
}
|
|
9
36
|
|
|
37
|
+
/** Resolve true only after a successful daemon handshake. */
|
|
10
38
|
async ping() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
resolve(code === 0)
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
resolve(true)
|
|
34
|
-
})
|
|
35
|
-
proc.on('close', (code) => {
|
|
36
|
-
try {
|
|
37
|
-
const res = JSON.parse(out)
|
|
38
|
-
resolve(!!res.ok)
|
|
39
|
-
} catch {
|
|
40
|
-
resolve(code === 0)
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
})
|
|
39
|
+
const primary = await collectPing(this.pythonBin, this.daemonPath)
|
|
40
|
+
if (primary) return true
|
|
41
|
+
if (this.pythonBin === 'python3') {
|
|
42
|
+
return collectPing('python', this.daemonPath)
|
|
43
|
+
}
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
isRuntimeAvailable() {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async synthesize() {
|
|
52
|
+
throw new Error(
|
|
53
|
+
'F5-TTS runtime is not bundled in @goodandready/dsh-tts. ' +
|
|
54
|
+
'Use Edge, Piper, or eSpeak for offline TTS.',
|
|
55
|
+
)
|
|
44
56
|
}
|
|
45
57
|
}
|
package/lib/engines/kokoro.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Local Kokoro engine wrapper.
|
|
5
|
+
*
|
|
6
|
+
* Real ONNX inference is intentionally not bundled in this package: shipping
|
|
7
|
+
* onnxruntime + voice tensors would blow the DSH Store size budget and couple
|
|
8
|
+
* the plugin to native binaries. Until a supported external runtime is wired,
|
|
9
|
+
* synthesis must fail honestly — never emit a synthetic tone.
|
|
10
|
+
*/
|
|
3
11
|
export class KokoroEngine {
|
|
4
12
|
constructor({ modelPath = '' } = {}) {
|
|
5
13
|
this.modelPath = modelPath
|
|
@@ -10,39 +18,23 @@ export class KokoroEngine {
|
|
|
10
18
|
return !!(this.modelPath && fs.existsSync(this.modelPath))
|
|
11
19
|
}
|
|
12
20
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @returns {AsyncGenerator<Float32Array>}
|
|
18
|
-
*/
|
|
19
|
-
async *synthesize(text, voice = 'af_bella') {
|
|
20
|
-
if (!text || !text.trim()) return
|
|
21
|
+
/** True only when a real inference backend can produce speech. */
|
|
22
|
+
isRuntimeAvailable() {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
chunk[i] = Math.sin((i * 440 * 2 * Math.PI) / this.sampleRate) * 0.2 * (1 - i / samples)
|
|
28
|
-
}
|
|
29
|
-
yield chunk
|
|
26
|
+
async *synthesize() {
|
|
27
|
+
throw new Error(
|
|
28
|
+
'Kokoro ONNX runtime is not bundled in @goodandready/dsh-tts. ' +
|
|
29
|
+
'Install weights does not enable speech. Use Edge, Piper, or eSpeak for offline TTS.',
|
|
30
|
+
)
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
async synthesizeWav(
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
chunks.push(chunk)
|
|
36
|
-
}
|
|
37
|
-
let totalLen = 0
|
|
38
|
-
for (const c of chunks) totalLen += c.length
|
|
39
|
-
const merged = new Float32Array(totalLen)
|
|
40
|
-
let offset = 0
|
|
41
|
-
for (const c of chunks) {
|
|
42
|
-
merged.set(c, offset)
|
|
43
|
-
offset += c.length
|
|
33
|
+
async synthesizeWav() {
|
|
34
|
+
for await (const _ of this.synthesize()) {
|
|
35
|
+
// unreachable: synthesize always throws
|
|
44
36
|
}
|
|
45
|
-
|
|
37
|
+
throw new Error('Kokoro synthesis unavailable')
|
|
46
38
|
}
|
|
47
39
|
}
|
|
48
40
|
|
package/lib/engines/types.js
CHANGED
|
@@ -1,46 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from 'node:child_process'
|
|
2
|
+
import { promisify } from 'node:util'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
const execFileAsync = promisify(execFile)
|
|
5
|
+
|
|
6
|
+
let gpuCache
|
|
7
|
+
|
|
8
|
+
export async function detectGPU() {
|
|
9
|
+
if (typeof gpuCache === 'boolean') return gpuCache
|
|
4
10
|
try {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
const { stdout } = await execFileAsync(
|
|
12
|
+
'nvidia-smi',
|
|
13
|
+
['--query-gpu=name', '--format=csv,noheader'],
|
|
14
|
+
{ timeout: 2000 },
|
|
15
|
+
)
|
|
16
|
+
gpuCache = !!(stdout && stdout.trim())
|
|
11
17
|
} catch {
|
|
12
|
-
|
|
18
|
+
gpuCache = false
|
|
13
19
|
}
|
|
20
|
+
return gpuCache
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
export class EngineRegistry {
|
|
17
|
-
constructor({ gpu, installed, manager } = {}) {
|
|
18
|
-
this.gpu =
|
|
24
|
+
constructor({ gpu = false, installed = [], manager = null } = {}) {
|
|
25
|
+
this.gpu = !!gpu
|
|
19
26
|
this.installed = Array.isArray(installed) ? installed : []
|
|
20
27
|
this.manager = manager || null
|
|
21
28
|
}
|
|
22
29
|
|
|
30
|
+
static async create({ installed, manager } = {}) {
|
|
31
|
+
const gpu = await detectGPU()
|
|
32
|
+
return new EngineRegistry({ gpu, installed, manager })
|
|
33
|
+
}
|
|
34
|
+
|
|
23
35
|
isInstalled(engineId) {
|
|
24
36
|
return this.installed.includes(engineId)
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
list() {
|
|
28
40
|
const list = []
|
|
29
|
-
// Kokoro
|
|
41
|
+
// Kokoro weights may be present, but inference is not bundled.
|
|
30
42
|
if (this.installed.includes('kokoro')) {
|
|
31
43
|
list.push({
|
|
32
44
|
id: 'kokoro',
|
|
33
45
|
name: 'Kokoro-82M',
|
|
34
46
|
type: 'local-cpu',
|
|
47
|
+
runtimeAvailable: false,
|
|
35
48
|
supports: (lang) => !lang || ['en', 'ru', 'ja', 'zh'].includes(String(lang).slice(0, 2).toLowerCase()),
|
|
36
49
|
})
|
|
37
50
|
}
|
|
38
|
-
// F5-TTS requires GPU
|
|
39
51
|
if (this.gpu && this.installed.includes('f5')) {
|
|
40
52
|
list.push({
|
|
41
53
|
id: 'f5',
|
|
42
54
|
name: 'F5-TTS',
|
|
43
55
|
type: 'local-gpu',
|
|
56
|
+
runtimeAvailable: false,
|
|
44
57
|
supports: () => true,
|
|
45
58
|
})
|
|
46
59
|
}
|
package/lib/http-util.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Shared HTTP helpers for dsh-tts host routes.
|
|
2
|
+
|
|
3
|
+
export function writeJson(res, code, body) {
|
|
4
|
+
try {
|
|
5
|
+
res.writeHead(code, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' })
|
|
6
|
+
res.end(JSON.stringify(body))
|
|
7
|
+
} catch { /* socket closed */ }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function readBody(req, maxBytes) {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const chunks = []
|
|
13
|
+
let size = 0
|
|
14
|
+
req.on('data', (c) => {
|
|
15
|
+
size += c.length
|
|
16
|
+
if (size > maxBytes) { reject(new Error('body too large')); req.destroy(); return }
|
|
17
|
+
chunks.push(c)
|
|
18
|
+
})
|
|
19
|
+
req.on('end', () => resolve(Buffer.concat(chunks)))
|
|
20
|
+
req.on('error', reject)
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Reject cross-site POSTs. Do not require loopback or Origin==Host: the Web UI is used over LAN and reverse proxies. */
|
|
25
|
+
export function isTrustedSettingsRequest(request) {
|
|
26
|
+
return request.headers['sec-fetch-site'] !== 'cross-site'
|
|
27
|
+
}
|