@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.
@@ -1,46 +1,59 @@
1
- import { execSync } from 'node:child_process'
1
+ import { execFile } from 'node:child_process'
2
+ import { promisify } from 'node:util'
2
3
 
3
- export function detectGPU() {
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 out = execSync('nvidia-smi --query-gpu=name --format=csv,noheader', {
6
- stdio: ['ignore', 'pipe', 'ignore'],
7
- timeout: 2000,
8
- encoding: 'utf8',
9
- })
10
- return !!(out && out.trim())
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
- return false
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 = typeof gpu === 'boolean' ? gpu : detectGPU()
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 works on CPU everywhere
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
  }
@@ -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
+ }