@goodandready/dsh-tts 0.3.22 → 0.4.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/README.md +12 -12
- package/README.ru.md +13 -10
- package/README.zh.md +10 -10
- package/lib/cache.js +4 -5
- package/lib/client.js +105 -88
- 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 +70 -467
- package/lib/providers.js +105 -25
- package/lib/routes.js +400 -0
- package/lib/stream-hub.js +31 -0
- package/lib/text.js +46 -19
- package/package.json +6 -3
- package/scripts/f5_daemon.py +40 -0
- package/lib/client/worklet.js +0 -71
- package/lib/router.js +0 -4
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
|
+
}
|