@qvac/tts-ggml 0.12.0 → 0.14.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.
Files changed (80) hide show
  1. package/README.md +127 -6
  2. package/docs/pocket-tts.md +12 -10
  3. package/examples/moss-sfx-fit.js +14 -7
  4. package/index.d.ts +43 -1130
  5. package/index.js +127 -3042
  6. package/lib/addonEvents.d.ts +26 -0
  7. package/lib/addonEvents.js +51 -0
  8. package/lib/conditioning.d.ts +50 -0
  9. package/lib/conditioning.js +184 -0
  10. package/lib/engineDetection.d.ts +14 -0
  11. package/lib/engineDetection.js +110 -0
  12. package/lib/engineIds.d.ts +15 -0
  13. package/lib/engineIds.js +39 -0
  14. package/lib/engineParams.d.ts +3 -0
  15. package/lib/engineParams.js +34 -0
  16. package/lib/engineSetup.d.ts +153 -0
  17. package/lib/engineSetup.js +2 -0
  18. package/lib/engines/audio8.d.ts +83 -0
  19. package/lib/engines/audio8.js +262 -0
  20. package/lib/engines/chatterbox.d.ts +10 -0
  21. package/lib/engines/chatterbox.js +112 -0
  22. package/lib/engines/cosyvoice.d.ts +87 -0
  23. package/lib/engines/cosyvoice.js +267 -0
  24. package/lib/engines/moss.d.ts +26 -0
  25. package/lib/engines/moss.js +177 -0
  26. package/lib/engines/mossSoundEffect.d.ts +41 -0
  27. package/lib/engines/mossSoundEffect.js +117 -0
  28. package/lib/engines/mossSpeech.d.ts +86 -0
  29. package/lib/engines/mossSpeech.js +228 -0
  30. package/lib/engines/parler.d.ts +71 -0
  31. package/lib/engines/parler.js +287 -0
  32. package/lib/engines/supertonic.d.ts +11 -0
  33. package/lib/engines/supertonic.js +115 -0
  34. package/lib/exclusiveQueue.d.ts +16 -0
  35. package/lib/exclusiveQueue.js +45 -0
  36. package/lib/fit.d.ts +3 -3
  37. package/lib/fit.js +4 -4
  38. package/lib/jobFields.d.ts +20 -0
  39. package/lib/jobFields.js +73 -0
  40. package/lib/modelFiles.d.ts +207 -0
  41. package/lib/modelFiles.js +117 -0
  42. package/lib/nativeParams.d.ts +12 -0
  43. package/lib/nativeParams.js +73 -0
  44. package/lib/optionValidation.d.ts +2 -0
  45. package/lib/optionValidation.js +103 -0
  46. package/lib/options.d.ts +4 -0
  47. package/lib/options.js +17 -0
  48. package/lib/pocketLifecycle.d.ts +67 -0
  49. package/lib/pocketLifecycle.js +170 -0
  50. package/lib/reload.d.ts +12 -0
  51. package/lib/reload.js +76 -0
  52. package/lib/sentenceStream.d.ts +85 -0
  53. package/lib/sentenceStream.js +367 -0
  54. package/lib/setup.d.ts +7 -0
  55. package/lib/setup.js +169 -0
  56. package/lib/streamingSupport.d.ts +8 -0
  57. package/lib/streamingSupport.js +77 -0
  58. package/lib/types.d.ts +465 -0
  59. package/lib/types.js +2 -0
  60. package/lib/voiceControls.d.ts +12 -0
  61. package/lib/voiceControls.js +23 -0
  62. package/package.json +17 -11
  63. package/test/integration/audio8.test.js +6 -12
  64. package/test/integration/fit.test.js +115 -18
  65. package/test/integration/gpu-smoke.test.js +2 -11
  66. package/test/integration/lavasr-enhancer.test.js +2 -15
  67. package/test/integration/moss-fit.test.js +13 -13
  68. package/test/integration/moss-sfx-fit.test.js +14 -14
  69. package/test/integration/moss-sfx.test.js +29 -4
  70. package/test/integration/moss-speech.test.js +19 -5
  71. package/test/integration/moss.test.js +93 -56
  72. package/test/mobile/integration.auto.cjs +10 -0
  73. package/test/mobile/test-groups.json +6 -2
  74. package/test/utils/desktopGpuBackend.js +21 -0
  75. package/test/utils/gpuOnly.js +15 -0
  76. package/test/utils/mossBackend.js +34 -0
  77. package/test/utils/mossGpuValidation.js +70 -0
  78. package/test/utils/perf-helper.js +275 -0
  79. package/test/utils/runTTS.js +1 -1
  80. package/test/utils/testThreads.js +5 -0
@@ -12,6 +12,12 @@ const { resolveRefWavPath } = require('../utils/runChatterboxTTS')
12
12
  const { readWavAsFloat32, createWav, resampleLinear } = require('../utils/wav-helper')
13
13
  const { TTS_TEST_THREADS } = require('../utils/testThreads')
14
14
  const { NO_GPU, GPU_ONLY_USE_GPU } = require('../utils/gpuOnly')
15
+ const { assertMossBackend } = require('../utils/mossBackend')
16
+ const {
17
+ createMossGpuValidation,
18
+ ENCODER_RE,
19
+ DIALOGUE_BACKBONE_RE
20
+ } = require('../utils/mossGpuValidation')
15
21
 
16
22
  const MOSS_SAMPLE_RATE = 24000
17
23
  const MOSS_STREAM_FRAMES = 10
@@ -19,8 +25,6 @@ const MOSS_SAMPLES_PER_FRAME = 1920
19
25
  const TEST_TIMEOUT_MS = 1800000
20
26
  const SYNTHESIS_TEXT = 'The MOSS integration test checks this generated voice.'
21
27
  const MODEL_DIR_ENV = 'QVAC_TEST_MOSS_MODEL_DIR'
22
- const ENCODER_RE = /^moss-codec-encoder(-[a-z0-9_]+)?\.gguf$/i
23
- const DIALOGUE_BACKBONE_RE = /^moss-ttsd(-[a-z0-9_]+)?\.gguf$/i
24
28
  const DIALOGUE_TEXT =
25
29
  '[S1] And so, my fellow Americans, [S2] ask what you can do for your country. ' +
26
30
  '[S1] Did the build finish this morning? [S2] Yes, every single test passed.'
@@ -29,12 +33,12 @@ const SPEAKER_TWO_SECONDS = [7.6, 10.6]
29
33
  const SHORT_DURATION_TOKENS = 25
30
34
  const LONG_DURATION_TOKENS = 100
31
35
  const INT16_FULL_SCALE = 32767
32
- const CPU_DEVICE = 0
33
- const CPU_BACKEND = 0
34
- const GPU_DEVICE = 1
36
+ const PINNED_GPU_BACKEND = (proc.env && proc.env.TTS_CPP_GPU_BACKEND) || ''
35
37
 
36
38
  const modelDir = (proc.env && proc.env[MODEL_DIR_ENV]) || ''
37
39
  const skipWithoutModels = modelDir === ''
40
+ const sourceAudio = resolveRefWavPath({})
41
+ const validation = createMossGpuValidation(proc.env || {}, sourceAudio, GPU_ONLY_USE_GPU)
38
42
 
39
43
  function createMossModel(extra = {}, useGPU = false) {
40
44
  return new TTSGgml({
@@ -133,9 +137,8 @@ function recordMoss(t, label, result, wallMs) {
133
137
  )
134
138
  }
135
139
 
136
- function assertCpuBackend(t, label, stats) {
137
- t.is(stats.backendDevice, CPU_DEVICE, `${label} reports a CPU device`)
138
- t.is(stats.backendId, CPU_BACKEND, `${label} reports the CPU backend`)
140
+ function assertBackend(t, label, stats, useGPU = false) {
141
+ assertMossBackend(t, label, stats, useGPU, PINNED_GPU_BACKEND)
139
142
  }
140
143
 
141
144
  async function withLoadedModel(extra, body, useGPU = false) {
@@ -156,31 +159,40 @@ test(
156
159
  const started = Date.now()
157
160
  const result = await synthesize(model, SYNTHESIS_TEXT)
158
161
  assertAudio(t, 'MOSS batch', result)
159
- assertCpuBackend(t, 'MOSS batch', result.stats)
162
+ assertBackend(t, 'MOSS batch', result.stats)
160
163
  t.is(nonEmptyChunks(result).length, 1, 'batch synthesis emits one buffer')
161
164
  recordMoss(t, 'moss batch', result, Date.now() - started)
162
165
  })
166
+ validation.completed('CPU batch')
163
167
  }
164
168
  )
165
169
 
166
- test(
167
- 'MOSS TTS: native chunk streaming emits frame-sized chunks',
168
- { timeout: TEST_TIMEOUT_MS, skip: skipWithoutModels },
169
- async (t) => {
170
- await withLoadedModel({ streamChunkTokens: MOSS_STREAM_FRAMES }, async (model) => {
171
- const started = Date.now()
172
- const result = await synthesize(model, SYNTHESIS_TEXT)
173
- assertAudio(t, 'MOSS stream', result)
174
- const chunks = nonEmptyChunks(result)
175
- t.ok(chunks.length > 1, `streaming emits several chunks (got ${chunks.length})`)
176
- t.ok(
177
- chunks.every((length) => length <= MOSS_STREAM_FRAMES * MOSS_SAMPLES_PER_FRAME),
178
- 'no chunk exceeds the configured frame count'
170
+ for (const useGPU of [false, true]) {
171
+ test(
172
+ `MOSS TTS: native chunk streaming emits frame-sized chunks (${useGPU ? 'GPU' : 'CPU'})`,
173
+ { timeout: TEST_TIMEOUT_MS, skip: skipWithoutModels || (useGPU && NO_GPU) },
174
+ async (t) => {
175
+ await withLoadedModel(
176
+ { streamChunkTokens: MOSS_STREAM_FRAMES },
177
+ async (model) => {
178
+ const started = Date.now()
179
+ const result = await synthesize(model, SYNTHESIS_TEXT)
180
+ assertAudio(t, 'MOSS stream', result)
181
+ assertBackend(t, 'MOSS stream', result.stats, useGPU)
182
+ const chunks = nonEmptyChunks(result)
183
+ t.ok(chunks.length > 1, `streaming emits several chunks (got ${chunks.length})`)
184
+ t.ok(
185
+ chunks.every((length) => length <= MOSS_STREAM_FRAMES * MOSS_SAMPLES_PER_FRAME),
186
+ 'no chunk exceeds the configured frame count'
187
+ )
188
+ recordMoss(t, 'moss stream', result, Date.now() - started)
189
+ },
190
+ useGPU
179
191
  )
180
- recordMoss(t, 'moss stream', result, Date.now() - started)
181
- })
182
- }
183
- )
192
+ validation.completed(`${useGPU ? 'GPU' : 'CPU'} streaming`)
193
+ }
194
+ )
195
+ }
184
196
 
185
197
  test(
186
198
  'MOSS TTS: useGPU=true synthesizes on a GPU backend',
@@ -192,42 +204,48 @@ test(
192
204
  const started = Date.now()
193
205
  const result = await synthesize(model, SYNTHESIS_TEXT)
194
206
  assertAudio(t, 'MOSS GPU', result)
195
- t.is(result.stats.backendDevice, GPU_DEVICE, 'MOSS GPU reports a GPU device')
196
- t.not(result.stats.backendId, CPU_BACKEND, 'MOSS GPU does not report the CPU backend')
197
- t.is(result.stats.gpuUnsupported, 0, 'MOSS GPU does not report a GPU fallback')
207
+ assertBackend(t, 'MOSS GPU', result.stats, true)
198
208
  recordMoss(t, 'moss gpu', result, Date.now() - started)
199
209
  },
200
210
  true
201
211
  )
212
+ validation.completed('GPU batch')
202
213
  }
203
214
  )
204
215
 
205
- test(
206
- 'MOSS TTS: voice cloning synthesizes from a reference recording',
207
- { timeout: TEST_TIMEOUT_MS, skip: skipWithoutModels },
208
- async (t) => {
209
- const sourceAudio = resolveRefWavPath({})
210
- if (!hasEncoder()) {
211
- t.comment(`skipping: no moss-codec-encoder GGUF in ${modelDir}`)
212
- return
213
- }
214
- if (!fs.existsSync(sourceAudio)) {
215
- t.fail(`MOSS reference audio is missing: ${sourceAudio}`)
216
- return
217
- }
218
- const referenceAudio = writeReferenceAtMossRate(sourceAudio)
219
- try {
220
- await withLoadedModel({ referenceAudio, seed: 7 }, async (model) => {
221
- const started = Date.now()
222
- const result = await synthesize(model, SYNTHESIS_TEXT)
223
- assertAudio(t, 'MOSS clone', result)
224
- recordMoss(t, 'moss clone', result, Date.now() - started)
225
- })
226
- } finally {
227
- fs.unlinkSync(referenceAudio)
216
+ for (const useGPU of [false, true]) {
217
+ test(
218
+ `MOSS TTS: voice cloning synthesizes from a reference recording (${useGPU ? 'GPU' : 'CPU'})`,
219
+ { timeout: TEST_TIMEOUT_MS, skip: skipWithoutModels || (useGPU && NO_GPU) },
220
+ async (t) => {
221
+ if (!hasEncoder()) {
222
+ t.comment(`skipping: no moss-codec-encoder GGUF in ${modelDir}`)
223
+ return
224
+ }
225
+ if (!fs.existsSync(sourceAudio)) {
226
+ t.fail(`MOSS reference audio is missing: ${sourceAudio}`)
227
+ return
228
+ }
229
+ const referenceAudio = writeReferenceAtMossRate(sourceAudio)
230
+ try {
231
+ await withLoadedModel(
232
+ { referenceAudio, seed: 7 },
233
+ async (model) => {
234
+ const started = Date.now()
235
+ const result = await synthesize(model, SYNTHESIS_TEXT)
236
+ assertAudio(t, 'MOSS clone', result)
237
+ assertBackend(t, 'MOSS clone', result.stats, useGPU)
238
+ recordMoss(t, 'moss clone', result, Date.now() - started)
239
+ },
240
+ useGPU
241
+ )
242
+ } finally {
243
+ fs.unlinkSync(referenceAudio)
244
+ }
245
+ validation.completed(`${useGPU ? 'GPU' : 'CPU'} cloning`)
228
246
  }
229
- }
230
- )
247
+ )
248
+ }
231
249
 
232
250
  test(
233
251
  'MOSS TTS: durationTokens steers the length of the synthesized speech',
@@ -238,9 +256,11 @@ test(
238
256
  async (model) => {
239
257
  const short = await synthesize(model, SYNTHESIS_TEXT)
240
258
  assertAudio(t, 'MOSS short target', short)
259
+ assertBackend(t, 'MOSS short target', short.stats, GPU_ONLY_USE_GPU)
241
260
  await model.reload({ durationTokens: LONG_DURATION_TOKENS })
242
261
  const long = await synthesize(model, SYNTHESIS_TEXT)
243
262
  assertAudio(t, 'MOSS long target', long)
263
+ assertBackend(t, 'MOSS long target', long.stats, GPU_ONLY_USE_GPU)
244
264
  t.ok(
245
265
  long.samples.length > short.samples.length,
246
266
  `a longer target yields longer speech (${short.samples.length} -> ${long.samples.length} samples)`
@@ -248,6 +268,7 @@ test(
248
268
  },
249
269
  GPU_ONLY_USE_GPU
250
270
  )
271
+ validation.completed('GPU duration/reload')
251
272
  }
252
273
  )
253
274
 
@@ -259,7 +280,6 @@ test(
259
280
  t.comment(`skipping: the TTSD backbone or the codec encoder is not in ${modelDir}`)
260
281
  return
261
282
  }
262
- const sourceAudio = resolveRefWavPath({})
263
283
  if (!fs.existsSync(sourceAudio)) {
264
284
  t.fail(`MOSS reference audio is missing: ${sourceAudio}`)
265
285
  return
@@ -270,12 +290,13 @@ test(
270
290
  { dialogueReferences: references, seed: 7, files: { modelDir: path.resolve(modelDir) } },
271
291
  async (model) => {
272
292
  t.ok(
273
- DIALOGUE_BACKBONE_RE.test(path.basename(model._mossBackbonePath)),
293
+ DIALOGUE_BACKBONE_RE.test(path.basename(model._setup.paths.mossBackbonePath)),
274
294
  'dialogue picks the TTSD backbone'
275
295
  )
276
296
  const started = Date.now()
277
297
  const result = await synthesize(model, DIALOGUE_TEXT)
278
298
  assertAudio(t, 'MOSS dialogue', result)
299
+ assertBackend(t, 'MOSS dialogue', result.stats, GPU_ONLY_USE_GPU)
279
300
  recordMoss(t, 'moss dialogue', result, Date.now() - started)
280
301
  },
281
302
  GPU_ONLY_USE_GPU
@@ -283,5 +304,21 @@ test(
283
304
  } finally {
284
305
  removeFiles(references)
285
306
  }
307
+ validation.completed('GPU TTSD dialogue')
286
308
  }
287
309
  )
310
+
311
+ if (validation.enabled) {
312
+ test('MOSS TTS: full GPU validation completed every required case', (t) => {
313
+ validation.assertComplete(t, [
314
+ 'CPU batch',
315
+ 'CPU streaming',
316
+ 'GPU streaming',
317
+ 'GPU batch',
318
+ 'CPU cloning',
319
+ 'GPU cloning',
320
+ 'GPU duration/reload',
321
+ 'GPU TTSD dialogue'
322
+ ])
323
+ })
324
+ }
@@ -50,6 +50,14 @@ async function runLavasrEnhancerTest (options = {}) { // eslint-disable-line no-
50
50
  return runIntegrationModule('../integration/lavasr-enhancer.test.js', options)
51
51
  }
52
52
 
53
+ async function runMossFitTest (options = {}) { // eslint-disable-line no-unused-vars
54
+ return runIntegrationModule('../integration/moss-fit.test.js', options)
55
+ }
56
+
57
+ async function runMossSfxFitTest (options = {}) { // eslint-disable-line no-unused-vars
58
+ return runIntegrationModule('../integration/moss-sfx-fit.test.js', options)
59
+ }
60
+
53
61
  async function runMossSfxTest (options = {}) { // eslint-disable-line no-unused-vars
54
62
  return runIntegrationModule('../integration/moss-sfx.test.js', options)
55
63
  }
@@ -118,6 +126,8 @@ module.exports = {
118
126
  runFitTest,
119
127
  runGpuSmokeTest,
120
128
  runLavasrEnhancerTest,
129
+ runMossFitTest,
130
+ runMossSfxFitTest,
121
131
  runMossSfxTest,
122
132
  runMossSpeechTest,
123
133
  runMossTest,
@@ -33,7 +33,9 @@
33
33
  "runMultipleRunsTest",
34
34
  "runGpuSmokeTest",
35
35
  "runOutputSampleRateTest",
36
- "runVoiceControlsTest"
36
+ "runVoiceControlsTest",
37
+ "runMossFitTest",
38
+ "runMossSfxFitTest"
37
39
  ]
38
40
  },
39
41
  "android": {
@@ -69,7 +71,9 @@
69
71
  "runMultipleRunsTest",
70
72
  "runGpuSmokeTest",
71
73
  "runOutputSampleRateTest",
72
- "runVoiceControlsTest"
74
+ "runVoiceControlsTest",
75
+ "runMossFitTest",
76
+ "runMossSfxFitTest"
73
77
  ]
74
78
  }
75
79
  }
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ const GPU_DEVICE = 1
4
+ const GPU_BACKEND_IDS = { metal: 1, cuda: 2, vulkan: 3, opencl: 4 }
5
+ const AUTOMATIC_BACKEND_IDS = [GPU_BACKEND_IDS.cuda, GPU_BACKEND_IDS.vulkan]
6
+
7
+ function expectedBackendIds(pinnedBackend) {
8
+ if (!pinnedBackend) return AUTOMATIC_BACKEND_IDS
9
+ const name = pinnedBackend.toLowerCase()
10
+ return Object.prototype.hasOwnProperty.call(GPU_BACKEND_IDS, name) ? [GPU_BACKEND_IDS[name]] : []
11
+ }
12
+
13
+ function assertDesktopGpuBackend(t, label, device, backendId, pinnedBackend = '') {
14
+ t.is(device, GPU_DEVICE, `${label}: GPU device required`)
15
+ t.ok(
16
+ expectedBackendIds(pinnedBackend).includes(backendId),
17
+ `${label}: expected ${pinnedBackend || 'CUDA or Vulkan'} backend, got backendId=${backendId}`
18
+ )
19
+ }
20
+
21
+ module.exports = { assertDesktopGpuBackend }
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ const os = require('bare-os')
4
+ const proc = require('bare-process')
5
+
6
+ const platform = os.platform()
7
+ const isMobile = platform === 'ios' || platform === 'android'
8
+ const isApple = platform === 'darwin' || platform === 'ios'
9
+
10
+ const NO_GPU = !!proc.env && proc.env.NO_GPU === 'true'
11
+ const GPU_ONLY_USE_GPU = !isMobile
12
+ const SKIP_PARLER_GPU_ONLY = NO_GPU || (!isMobile && !isApple)
13
+ const PARLER_GPU_ONLY_USE_GPU = isApple && !isMobile
14
+
15
+ module.exports = { NO_GPU, GPU_ONLY_USE_GPU, SKIP_PARLER_GPU_ONLY, PARLER_GPU_ONLY_USE_GPU }
@@ -0,0 +1,34 @@
1
+ 'use strict'
2
+
3
+ const GPU_BACKEND_IDS = { metal: 1, cuda: 2, vulkan: 3, opencl: 4 }
4
+
5
+ // The native engine reads TTS_CPP_GPU_BACKEND. Check its reported backend as
6
+ // well: a different GPU must not make a CUDA/Vulkan validation lane pass.
7
+ function assertMossBackend(t, label, stats, useGPU, pinnedBackend = '') {
8
+ if (!stats) {
9
+ t.fail(`${label}: missing runtime stats; cannot verify the backend`)
10
+ return
11
+ }
12
+ t.is(stats.backendDevice, useGPU ? 1 : 0, `${label}: requested compute device`)
13
+ if (!useGPU) {
14
+ t.is(stats.backendId, 0, `${label}: CPU requested explicitly`)
15
+ return
16
+ }
17
+ t.is(stats.gpuUnsupported, 0, `${label}: no GPU fallback`)
18
+ pinnedBackend = pinnedBackend.toLowerCase()
19
+ if (pinnedBackend) {
20
+ if (!Object.prototype.hasOwnProperty.call(GPU_BACKEND_IDS, pinnedBackend)) {
21
+ t.fail(`${label}: unknown TTS_CPP_GPU_BACKEND=${pinnedBackend}`)
22
+ return
23
+ }
24
+ t.is(
25
+ stats.backendId,
26
+ GPU_BACKEND_IDS[pinnedBackend],
27
+ `${label}: TTS_CPP_GPU_BACKEND=${pinnedBackend}`
28
+ )
29
+ } else {
30
+ t.ok(Object.values(GPU_BACKEND_IDS).includes(stats.backendId), `${label}: known GPU backend`)
31
+ }
32
+ }
33
+
34
+ module.exports = { assertMossBackend }
@@ -0,0 +1,70 @@
1
+ 'use strict'
2
+
3
+ const fs = require('bare-fs')
4
+ const path = require('bare-path')
5
+
6
+ const ENCODER_RE = /^moss-codec-encoder(-[a-z0-9_]+)?\.gguf$/i
7
+ const DIALOGUE_BACKBONE_RE = /^moss-ttsd(-[a-z0-9_]+)?\.gguf$/i
8
+ const REQUIRED_MODELS = {
9
+ QVAC_TEST_MOSS_MODEL_DIR: [
10
+ ['TTS backbone', /^moss-tts-delay(-[a-z0-9_]+)?\.gguf$/i],
11
+ ['TTSD backbone', DIALOGUE_BACKBONE_RE],
12
+ ['codec decoder', /^moss-codec-decoder(-[a-z0-9_]+)?\.gguf$/i],
13
+ ['codec encoder', ENCODER_RE]
14
+ ],
15
+ QVAC_TEST_MOSS_SPEECH_MODEL_DIR: [
16
+ ['Speech backbone', /^moss-speech(-(?!codec)[a-z0-9_]+)?\.gguf$/i],
17
+ ['Speech codec', /^moss-speech-codec(-[a-z0-9_]+)?\.gguf$/i]
18
+ ]
19
+ }
20
+
21
+ function requireValidation(condition, message) {
22
+ if (!condition) throw new Error(`MOSS full GPU validation: ${message}`)
23
+ }
24
+
25
+ function isFile(file) {
26
+ return fs.existsSync(file) && fs.statSync(file).isFile()
27
+ }
28
+
29
+ // Called before either suite registers tests. Reuse each suite's reference WAV
30
+ // resolver so preflight and inference cannot silently select different audio.
31
+ function createMossGpuValidation(env, referenceAudio, gpuOnlyUseGPU = true) {
32
+ const enabled = env.QVAC_TEST_MOSS_FULL_GPU === 'true'
33
+ const completed = new Set()
34
+ if (enabled) {
35
+ requireValidation(env.NO_GPU !== 'true', 'NO_GPU=true conflicts with full GPU validation')
36
+ requireValidation(gpuOnlyUseGPU, 'full GPU validation requires the desktop GPU cases')
37
+ requireValidation(
38
+ ['cuda', 'vulkan', 'metal', 'opencl'].includes((env.TTS_CPP_GPU_BACKEND || '').toLowerCase()),
39
+ 'set TTS_CPP_GPU_BACKEND to cuda, vulkan, metal or opencl'
40
+ )
41
+ for (const [variable, requirements] of Object.entries(REQUIRED_MODELS)) {
42
+ const directory = env[variable]
43
+ requireValidation(
44
+ directory && fs.existsSync(directory) && fs.statSync(directory).isDirectory(),
45
+ `${variable} must name an existing model directory`
46
+ )
47
+ const files = fs.readdirSync(directory).filter((entry) => isFile(path.join(directory, entry)))
48
+ for (const [label, pattern] of requirements) {
49
+ requireValidation(
50
+ files.some((file) => pattern.test(file)),
51
+ `${variable}: missing ${label}`
52
+ )
53
+ }
54
+ }
55
+ requireValidation(isFile(referenceAudio), `reference WAV is missing: ${referenceAudio}`)
56
+ }
57
+ return {
58
+ enabled,
59
+ completed(caseName) {
60
+ completed.add(caseName)
61
+ },
62
+ assertComplete(t, expected) {
63
+ for (const caseName of expected) {
64
+ t.ok(completed.has(caseName), `full GPU validation executed ${caseName}`)
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ module.exports = { createMossGpuValidation, ENCODER_RE, DIALOGUE_BACKBONE_RE }