@eslaykey/dsh-breeze-tts 1.0.4 → 1.0.7
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/CHANGELOG.md +55 -0
- package/README.md +2 -0
- package/client.js +632 -324
- package/index.js +181 -237
- package/package.json +3 -2
- package/plan.js +242 -0
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
|
3
3
|
import { homedir } from 'node:os'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import { createHash, randomUUID } from 'node:crypto'
|
|
6
|
+
import { buildPlan, EMOTION_MARKERS } from './plan.js'
|
|
6
7
|
|
|
7
8
|
const API_BASE = 'https://api.breeze.blue/v1'
|
|
8
9
|
const ROUTE_PREFIX = '/breeze-tts'
|
|
@@ -42,6 +43,51 @@ const DEFAULTS = {
|
|
|
42
43
|
|
|
43
44
|
export const inject = ['tools', 'webServer']
|
|
44
45
|
|
|
46
|
+
const inflight = new Map()
|
|
47
|
+
const synthQueue = []
|
|
48
|
+
let activeSynthCalls = 0
|
|
49
|
+
const MAX_CONCURRENT_SYNTH = 1
|
|
50
|
+
|
|
51
|
+
function resolveToneInstructions(settings, toneId) {
|
|
52
|
+
const custom = String((settings && settings.customMood) || '').trim()
|
|
53
|
+
const tone = ((settings && settings.tones) || []).find((item) => item.id === toneId)
|
|
54
|
+
return custom || (tone ? tone.instructions : '')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function resolveSpeakOptions(input) {
|
|
58
|
+
const source = input && typeof input === 'object' ? input : {}
|
|
59
|
+
const savePath = typeof source.save_path === 'string' ? source.save_path : ''
|
|
60
|
+
const plays = source.play !== false
|
|
61
|
+
const wantsFile = savePath !== ''
|
|
62
|
+
const wantsMp3 = wantsFile && /\.mp3$/i.test(savePath)
|
|
63
|
+
if (plays && wantsMp3) {
|
|
64
|
+
return {
|
|
65
|
+
error: 'mp3 files cannot be played back; use a save_path ending in .wav, or set play:false to only write the file',
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
savePath,
|
|
70
|
+
plays,
|
|
71
|
+
wantsFile,
|
|
72
|
+
format: !plays && wantsMp3 ? 'mp3_24000_96' : 'wav_24000',
|
|
73
|
+
toneId: typeof source.mood === 'string' ? source.mood : '',
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function withSynthSlot(task) {
|
|
78
|
+
if (activeSynthCalls >= MAX_CONCURRENT_SYNTH) {
|
|
79
|
+
await new Promise((resolve) => synthQueue.push(resolve))
|
|
80
|
+
}
|
|
81
|
+
activeSynthCalls += 1
|
|
82
|
+
try {
|
|
83
|
+
return await task()
|
|
84
|
+
} finally {
|
|
85
|
+
activeSynthCalls -= 1
|
|
86
|
+
const next = synthQueue.shift()
|
|
87
|
+
if (next) next()
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
45
91
|
function parseJson(text) {
|
|
46
92
|
try {
|
|
47
93
|
return JSON.parse(text)
|
|
@@ -60,12 +106,29 @@ async function readStore() {
|
|
|
60
106
|
}
|
|
61
107
|
}
|
|
62
108
|
|
|
109
|
+
const storeQueue = []
|
|
110
|
+
let storeBusy = false
|
|
111
|
+
|
|
112
|
+
async function withStoreLock(task) {
|
|
113
|
+
if (storeBusy) await new Promise((resolve) => storeQueue.push(resolve))
|
|
114
|
+
storeBusy = true
|
|
115
|
+
try {
|
|
116
|
+
return await task()
|
|
117
|
+
} finally {
|
|
118
|
+
storeBusy = false
|
|
119
|
+
const next = storeQueue.shift()
|
|
120
|
+
if (next) next()
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
63
124
|
async function writeStore(patch) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
125
|
+
return withStoreLock(async () => {
|
|
126
|
+
const current = await readStore()
|
|
127
|
+
const next = { ...current, ...patch }
|
|
128
|
+
await mkdir(path.dirname(SETTINGS_PATH), { recursive: true })
|
|
129
|
+
await writeFile(SETTINGS_PATH, JSON.stringify(next, null, 2), 'utf8')
|
|
130
|
+
return next
|
|
131
|
+
})
|
|
69
132
|
}
|
|
70
133
|
|
|
71
134
|
function usageKey() {
|
|
@@ -79,172 +142,6 @@ function creditsOf(chars) {
|
|
|
79
142
|
return Math.round(chars * 0.19 * 10) / 10
|
|
80
143
|
}
|
|
81
144
|
|
|
82
|
-
const CJK = /[\u3400-\u4DBF\u4E00-\u9FFF\u3040-\u30FF\uAC00-\uD7AF]/g
|
|
83
|
-
const LATIN = /[A-Za-z]/g
|
|
84
|
-
|
|
85
|
-
const SENTENCE_MARKS = [0x3002, 0xFF01, 0xFF1F, 0x2026, 0xFF1B, 0x21, 0x3F, 0x3B, 0x0A].map((code) => String.fromCharCode(code)).join('')
|
|
86
|
-
|
|
87
|
-
function countMatches(text, pattern) {
|
|
88
|
-
const found = String(text).match(pattern)
|
|
89
|
-
return found ? found.length : 0
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function stripEmoji(text) {
|
|
93
|
-
let out = ''
|
|
94
|
-
for (const ch of String(text ?? '')) {
|
|
95
|
-
const cp = ch.codePointAt(0)
|
|
96
|
-
if (cp >= 0x1f000 && cp <= 0x1faff) continue
|
|
97
|
-
if (cp >= 0x2600 && cp <= 0x27bf) continue
|
|
98
|
-
if (cp === 0xfe0f || cp === 0x200d || cp === 0x2b50) continue
|
|
99
|
-
out += ch
|
|
100
|
-
}
|
|
101
|
-
return out
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function cleanSpeech(text, keepTags) {
|
|
105
|
-
let value = String(text ?? '')
|
|
106
|
-
if (!keepTags) value = value.replace(/<!--[\s\S]*?-->/g, ' ')
|
|
107
|
-
value = value.replace(/!\[[^\]]*\]\([^)]*\)/g, ' ')
|
|
108
|
-
value = value.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
109
|
-
value = value.replace(/https?:\/\/[^\s)]+/g, ' ')
|
|
110
|
-
value = value.replace(/`{1,3}[^`]*`{1,3}/g, ' ')
|
|
111
|
-
value = value.replace(/[*_~#>|]+/g, ' ')
|
|
112
|
-
value = stripEmoji(value)
|
|
113
|
-
value = value.replace(/\s+([:,。!?;、)】」》])/g, '$1')
|
|
114
|
-
value = value.replace(/([(【「《])\s+/g, '$1')
|
|
115
|
-
value = value.replace(/\s+/g, ' ')
|
|
116
|
-
return value.trim()
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function detectLanguage(text) {
|
|
120
|
-
const cjk = countMatches(text, CJK)
|
|
121
|
-
const latin = countMatches(text, LATIN)
|
|
122
|
-
if (cjk === 0) return latin > 0 ? "en" : ""
|
|
123
|
-
return cjk * 2 >= latin ? "zh" : "en"
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function splitSentences(text) {
|
|
127
|
-
const value = String(text ?? '').trim()
|
|
128
|
-
if (!value) return []
|
|
129
|
-
const parts = []
|
|
130
|
-
let buffer = ''
|
|
131
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
132
|
-
const ch = value[index]
|
|
133
|
-
buffer += ch
|
|
134
|
-
const next = value[index + 1]
|
|
135
|
-
const asciiStop = ch === '.' && (next === undefined || next === ' ' || next === String.fromCharCode(10) || next === String.fromCharCode(9) || next === '"' || next === "'" || next === ')' || next === ']')
|
|
136
|
-
if (SENTENCE_MARKS.includes(ch) || asciiStop) {
|
|
137
|
-
parts.push(buffer)
|
|
138
|
-
buffer = ''
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (buffer.trim()) parts.push(buffer)
|
|
142
|
-
return parts.map((part) => part.trim()).filter(Boolean)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const EMOTIONS = {
|
|
146
|
-
curious: 'TONE_CURIOUS',
|
|
147
|
-
excited: 'TONE_EXCITED',
|
|
148
|
-
sad: 'TONE_SAD',
|
|
149
|
-
gentle: 'TONE_GENTLE',
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function emotionInstruction(emotion) {
|
|
153
|
-
if (emotion === 'curious') return '语气带着好奇和疑问,句尾略微上扬。'
|
|
154
|
-
if (emotion === 'excited') return '语气兴奋,语速稍快,音调偏高。'
|
|
155
|
-
if (emotion === 'happy') return '语气愉快,带着笑意,句尾轻轻上扬。'
|
|
156
|
-
if (emotion === 'angry') return '语气生气,音量略高,语速偏快,带着一点压迫感。'
|
|
157
|
-
if (emotion === 'down') return '语气沮丧,声音发闷,语速放慢。'
|
|
158
|
-
if (emotion === 'sad') return '语气低落,语速放慢,尾音下沉。'
|
|
159
|
-
if (emotion === 'whisper') return '压低声音像耳语,气息多,音量小。'
|
|
160
|
-
if (emotion === 'surprised') return '语气惊讶,语调突然抬高,语速略快。'
|
|
161
|
-
if (emotion === 'afraid') return '语气带着紧张和不安,声音发抖,语速不稳。'
|
|
162
|
-
if (emotion === 'serious') return '语气严肃克制,吐字清楚,节奏稳定。'
|
|
163
|
-
if (emotion === 'tired') return '语气疲惫,声音有气无力,语速偏慢。'
|
|
164
|
-
if (emotion === 'gentle') return '语气轻柔,像在轻声安慰对方。'
|
|
165
|
-
return ''
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function guessEmotion(sentence) {
|
|
169
|
-
const value = String(sentence).trim()
|
|
170
|
-
if (!value) return ''
|
|
171
|
-
if (/[??]\s*$/.test(value)) return 'curious'
|
|
172
|
-
if (/[!!]\s*$/.test(value)) return 'excited'
|
|
173
|
-
if (/(…|\.\.\.)\s*$/.test(value)) return 'sad'
|
|
174
|
-
return ''
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function splitByMarker(text) {
|
|
178
|
-
const parts = []
|
|
179
|
-
const pattern = /<!--\s*mood:\s*([a-z-]+)\s*-->/gi
|
|
180
|
-
let lastIndex = 0
|
|
181
|
-
let current = ''
|
|
182
|
-
let match = pattern.exec(text)
|
|
183
|
-
while (match) {
|
|
184
|
-
const before = text.slice(lastIndex, match.index)
|
|
185
|
-
if (before.trim()) parts.push({ text: before, emotion: current })
|
|
186
|
-
current = String(match[1] || '').toLowerCase()
|
|
187
|
-
lastIndex = match.index + match[0].length
|
|
188
|
-
match = pattern.exec(text)
|
|
189
|
-
}
|
|
190
|
-
const tail = text.slice(lastIndex)
|
|
191
|
-
if (tail.trim()) parts.push({ text: tail, emotion: current })
|
|
192
|
-
return parts
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function planSegments(text, mode, baseInstructions) {
|
|
196
|
-
const sentences = splitSentences(text)
|
|
197
|
-
const segments = []
|
|
198
|
-
let pendingEmotion = ''
|
|
199
|
-
|
|
200
|
-
let carry = ''
|
|
201
|
-
for (const sentence of sentences) {
|
|
202
|
-
let emotion = mode === 'infer' ? guessEmotion(sentence) : ''
|
|
203
|
-
if (!emotion && carry && sentence.length <= 40) emotion = carry
|
|
204
|
-
if (emotion) carry = emotion
|
|
205
|
-
const instructions = emotion ? emotionInstruction(emotion) : baseInstructions
|
|
206
|
-
const last = segments[segments.length - 1]
|
|
207
|
-
if (last && last.instructions === instructions && last.text.length + sentence.length <= 900) {
|
|
208
|
-
last.text += sentence
|
|
209
|
-
continue
|
|
210
|
-
}
|
|
211
|
-
segments.push({ text: sentence, instructions, emotion: emotion || pendingEmotion })
|
|
212
|
-
}
|
|
213
|
-
if (mode === 'marker') {
|
|
214
|
-
const parts = splitByMarker(text)
|
|
215
|
-
if (parts.length > 1) {
|
|
216
|
-
const merged = []
|
|
217
|
-
for (const part of parts) {
|
|
218
|
-
const piece = cleanSpeech(part.text)
|
|
219
|
-
if (!piece) continue
|
|
220
|
-
const instructions = part.emotion ? (emotionInstruction(part.emotion) || baseInstructions) : baseInstructions
|
|
221
|
-
const last = merged[merged.length - 1]
|
|
222
|
-
if (last && last.instructions === instructions && last.text.length + piece.length <= 900) {
|
|
223
|
-
last.text += piece
|
|
224
|
-
continue
|
|
225
|
-
}
|
|
226
|
-
merged.push({ text: piece, instructions, emotion: part.emotion })
|
|
227
|
-
}
|
|
228
|
-
return merged
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return segments
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function chunkByLanguage(text, limit = 900) {
|
|
235
|
-
const chunks = []
|
|
236
|
-
for (const part of splitSentences(text)) {
|
|
237
|
-
const lang = detectLanguage(part)
|
|
238
|
-
const last = chunks[chunks.length - 1]
|
|
239
|
-
if (last && last.lang === lang && last.text.length + part.length <= limit) {
|
|
240
|
-
last.text += part
|
|
241
|
-
continue
|
|
242
|
-
}
|
|
243
|
-
chunks.push({ text: part, lang })
|
|
244
|
-
}
|
|
245
|
-
return chunks
|
|
246
|
-
}
|
|
247
|
-
|
|
248
145
|
function concatWav(buffers, gapMs = 260) {
|
|
249
146
|
let fmt = null
|
|
250
147
|
const frames = []
|
|
@@ -424,8 +321,8 @@ export function apply(ctx, config) {
|
|
|
424
321
|
}
|
|
425
322
|
}
|
|
426
323
|
|
|
427
|
-
async function usage() {
|
|
428
|
-
|
|
324
|
+
async function usage(store) {
|
|
325
|
+
store ??= await readStore()
|
|
429
326
|
const today = usageKey()
|
|
430
327
|
if (store.usageDate !== today) return { chars: 0, calls: 0 }
|
|
431
328
|
return { chars: Number(store.usageChars ?? 0), calls: Number(store.usageCalls ?? 0) }
|
|
@@ -446,24 +343,39 @@ export function apply(ctx, config) {
|
|
|
446
343
|
if (!s.apiKey) throw new Error('missing Breeze API key: write it into ~/.dsh/breeze.json')
|
|
447
344
|
const voiceId = options.voiceId || s.voiceId
|
|
448
345
|
if (!voiceId) throw new Error('missing voice id')
|
|
449
|
-
const
|
|
450
|
-
const
|
|
451
|
-
const mood = moodId
|
|
452
|
-
const customTone = String(s.customMood || '').trim()
|
|
453
|
-
const instructions = options.instructions ?? (customTone || (tone ? tone.instructions : ''))
|
|
346
|
+
const mood = options.toneId || s.moodId || 'normal'
|
|
347
|
+
const instructions = options.instructions ?? resolveToneInstructions(s, mood)
|
|
454
348
|
const format = options.format || 'wav_24000'
|
|
455
|
-
const
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
349
|
+
const languageMode = String(s.languageMode || 'auto')
|
|
350
|
+
const fixedLanguage = languageMode !== 'auto' ? languageMode : ''
|
|
351
|
+
const plan = buildPlan(text, {
|
|
352
|
+
emotionMode: s.emotionMode || 'fixed',
|
|
353
|
+
baseInstructions: instructions,
|
|
354
|
+
})
|
|
355
|
+
if (!plan.segments.length) throw new Error('empty text')
|
|
356
|
+
const segments = plan.segments.map((segment) => ({
|
|
357
|
+
...segment,
|
|
358
|
+
language_code: fixedLanguage || segment.language || String(s.languageCode || ''),
|
|
359
|
+
}))
|
|
360
|
+
|
|
361
|
+
const cacheKey = createHash('sha1').update([
|
|
362
|
+
voiceId,
|
|
363
|
+
mood,
|
|
364
|
+
s.emotionMode || 'fixed',
|
|
365
|
+
instructions,
|
|
366
|
+
s.modelId || '',
|
|
367
|
+
format,
|
|
368
|
+
plan.segments.map((seg) => seg.language_code + '#' + seg.instructions + '#' + seg.text).join('#|#'),
|
|
369
|
+
].join('#|#')).digest('hex').slice(0, 16)
|
|
459
370
|
const cachePath = path.join(CACHE_DIR, `cache-${cacheKey}.wav`)
|
|
371
|
+
|
|
460
372
|
if (format.startsWith('wav')) {
|
|
461
373
|
try {
|
|
462
374
|
const hit = await readFile(cachePath)
|
|
463
375
|
if (hit.length > 44) {
|
|
464
376
|
return {
|
|
465
377
|
audio: hit,
|
|
466
|
-
langs:
|
|
378
|
+
langs: plan.segments.map((seg) => seg.emotion || seg.language || ''),
|
|
467
379
|
chars: 0,
|
|
468
380
|
credits: 0,
|
|
469
381
|
mood,
|
|
@@ -476,47 +388,57 @@ export function apply(ctx, config) {
|
|
|
476
388
|
/* cache miss */
|
|
477
389
|
}
|
|
478
390
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
const
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
const chunk = piece.text
|
|
488
|
-
const segInstructions = piece.instructions || instructions
|
|
489
|
-
const segLang = detectLanguage(chunk) || s.languageCode
|
|
490
|
-
const body = {
|
|
491
|
-
text: chunk,
|
|
492
|
-
model_id: s.modelId,
|
|
493
|
-
language_code: fixed || segLang,
|
|
391
|
+
|
|
392
|
+
const pending = inflight.get(cacheKey)
|
|
393
|
+
if (pending) return pending
|
|
394
|
+
|
|
395
|
+
const job = withSynthSlot(async () => {
|
|
396
|
+
const current = await usage()
|
|
397
|
+
if (current.chars + plan.chars > Number(s.dailyChars ?? 1500)) {
|
|
398
|
+
throw new Error(`daily limit reached (${current.chars}/${s.dailyChars} chars)`)
|
|
494
399
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
body
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
400
|
+
const buffers = []
|
|
401
|
+
let charged = 0
|
|
402
|
+
for (const segment of segments) {
|
|
403
|
+
const body = {
|
|
404
|
+
text: segment.text,
|
|
405
|
+
model_id: s.modelId,
|
|
406
|
+
language_code: segment.language_code,
|
|
407
|
+
}
|
|
408
|
+
if (segment.instructions) body.instructions = segment.instructions
|
|
409
|
+
const audio = await callApi(`/text-to-speech/${encodeURIComponent(voiceId)}`, {
|
|
410
|
+
method: 'POST',
|
|
411
|
+
body,
|
|
412
|
+
query: { output_format: format, delivery: 'sync' },
|
|
413
|
+
apiKey: s.apiKey,
|
|
414
|
+
binary: true,
|
|
415
|
+
})
|
|
416
|
+
buffers.push(audio)
|
|
417
|
+
const size = Array.from(segment.text).length
|
|
418
|
+
charged += size
|
|
419
|
+
await accountUsage(size)
|
|
420
|
+
}
|
|
421
|
+
const merged = format.startsWith('wav') && buffers.length > 1 ? concatWav(buffers) : Buffer.concat(buffers)
|
|
422
|
+
if (format.startsWith('wav')) {
|
|
423
|
+
await mkdir(CACHE_DIR, { recursive: true }).catch(() => {})
|
|
424
|
+
await writeFile(cachePath, merged).catch(() => {})
|
|
425
|
+
}
|
|
426
|
+
return {
|
|
427
|
+
audio: merged,
|
|
428
|
+
langs: plan.segments.map((seg) => seg.emotion || seg.language || ''),
|
|
429
|
+
chars: charged,
|
|
430
|
+
credits: creditsOf(charged),
|
|
431
|
+
mood,
|
|
432
|
+
voiceId,
|
|
433
|
+
format: format.startsWith('wav') ? 'wav' : 'mp3',
|
|
434
|
+
}
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
inflight.set(cacheKey, job)
|
|
438
|
+
try {
|
|
439
|
+
return await job
|
|
440
|
+
} finally {
|
|
441
|
+
inflight.delete(cacheKey)
|
|
520
442
|
}
|
|
521
443
|
}
|
|
522
444
|
|
|
@@ -534,13 +456,11 @@ export function apply(ctx, config) {
|
|
|
534
456
|
text: () => {
|
|
535
457
|
if (emotionModeCache !== 'marker') return ''
|
|
536
458
|
return [
|
|
537
|
-
'Voice emotion
|
|
538
|
-
'
|
|
539
|
-
'
|
|
540
|
-
'
|
|
541
|
-
'
|
|
542
|
-
'The tag only affects speech synthesis. Use them sparingly, only where the',
|
|
543
|
-
'emotional shift matters.',
|
|
459
|
+
'Voice emotion markers: put one of the exact Markdown markers below at the start',
|
|
460
|
+
'of a segment whose spoken tone should change. Keep its emoji and destination together.',
|
|
461
|
+
EMOTION_MARKERS.join(', ') + '.',
|
|
462
|
+
'Separate markers from nearby prose with spaces. Continue with the reply as normal prose.',
|
|
463
|
+
'Do not wrap markers in code, turn them into images, or use HTML comments. Use them sparingly.',
|
|
544
464
|
].join(' ')
|
|
545
465
|
},
|
|
546
466
|
}), 'breeze-tts: emotion prompt section')
|
|
@@ -556,7 +476,7 @@ export function apply(ctx, config) {
|
|
|
556
476
|
type: 'object',
|
|
557
477
|
properties: {
|
|
558
478
|
text: { type: 'string', description: 'Text to synthesize. Long text is split on sentence marks.' },
|
|
559
|
-
mood: { type: 'string', description: '
|
|
479
|
+
mood: { type: 'string', description: 'Tone id from the configured tones (normal, warm, formal, lively, or a custom id). Defaults to the configured tone.' },
|
|
560
480
|
voice_id: { type: 'string', description: 'Voice id override. Defaults to the configured voice.' },
|
|
561
481
|
play: { type: 'boolean', description: 'Play through the speakers. Set false to only produce the file.' },
|
|
562
482
|
save_path: { type: 'string', description: 'Absolute path to also write the audio to.' },
|
|
@@ -579,11 +499,14 @@ export function apply(ctx, config) {
|
|
|
579
499
|
},
|
|
580
500
|
async execute(args) {
|
|
581
501
|
const input = args ?? {}
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
const plays
|
|
585
|
-
const
|
|
586
|
-
|
|
502
|
+
const options = resolveSpeakOptions(input)
|
|
503
|
+
if (options.error) throw new Error(options.error)
|
|
504
|
+
const { plays, format, savePath } = options
|
|
505
|
+
const result = await synth(input.text, {
|
|
506
|
+
toneId: options.toneId || undefined,
|
|
507
|
+
voiceId: input.voice_id,
|
|
508
|
+
format,
|
|
509
|
+
})
|
|
587
510
|
await mkdir(CACHE_DIR, { recursive: true })
|
|
588
511
|
const file = path.join(CACHE_DIR, `${Date.now()}-${randomUUID().slice(0, 8)}.${format.startsWith('wav') ? 'wav' : 'mp3'}`)
|
|
589
512
|
await saveAudio(result, file)
|
|
@@ -690,6 +613,17 @@ export function apply(ctx, config) {
|
|
|
690
613
|
return parseJson(Buffer.concat(chunks).toString('utf8')) ?? {}
|
|
691
614
|
}
|
|
692
615
|
try {
|
|
616
|
+
if (route === '/usage' && req.method === 'GET') {
|
|
617
|
+
const s = await withStoreLock(settings)
|
|
618
|
+
const current = await usage(s)
|
|
619
|
+
res.setHeader('cache-control', 'no-store')
|
|
620
|
+
return json(200, {
|
|
621
|
+
chars: current.chars,
|
|
622
|
+
limit: Number(s.dailyChars ?? 0),
|
|
623
|
+
hasKey: Boolean(s.apiKey),
|
|
624
|
+
autoSpeak: Boolean(s.autoSpeak),
|
|
625
|
+
})
|
|
626
|
+
}
|
|
693
627
|
if (route === '/status' && req.method === 'GET') {
|
|
694
628
|
const s = await settings()
|
|
695
629
|
const current = await usage()
|
|
@@ -980,7 +914,7 @@ export function apply(ctx, config) {
|
|
|
980
914
|
}))
|
|
981
915
|
.slice(0, 40)
|
|
982
916
|
}
|
|
983
|
-
if (typeof body.previewText === 'string'
|
|
917
|
+
if (typeof body.previewText === 'string') patch.previewText = body.previewText
|
|
984
918
|
if (typeof body.dailyChars === 'number' && body.dailyChars > 0) patch.dailyChars = Math.floor(body.dailyChars)
|
|
985
919
|
if (typeof body.autoSpeak === 'boolean') patch.autoSpeak = body.autoSpeak
|
|
986
920
|
if (typeof body.backgroundPlay === 'boolean') patch.backgroundPlay = body.backgroundPlay
|
|
@@ -1027,3 +961,13 @@ export function apply(ctx, config) {
|
|
|
1027
961
|
|
|
1028
962
|
ctx.logger?.info?.(`breeze-tts ready (voice ${cfg.voiceId}, ${clip(cfg.modelId)})`)
|
|
1029
963
|
}
|
|
964
|
+
|
|
965
|
+
/** Exposed for offline tests only; the harness ignores extra exports. */
|
|
966
|
+
export const __test = {
|
|
967
|
+
withSynthSlot,
|
|
968
|
+
inflight,
|
|
969
|
+
buildPlan,
|
|
970
|
+
resolveSpeakOptions,
|
|
971
|
+
resolveToneInstructions,
|
|
972
|
+
DEFAULT_TONES,
|
|
973
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslaykey/dsh-breeze-tts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Breeze Blue text-to-speech for DeepSeek Harness: agent tools, reply playback, voice design and a settings page.",
|
|
5
5
|
"author": "eslaykey",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"icon.svg",
|
|
20
20
|
"README.md",
|
|
21
21
|
"LICENSE",
|
|
22
|
-
"CHANGELOG.md"
|
|
22
|
+
"CHANGELOG.md",
|
|
23
|
+
"plan.js"
|
|
23
24
|
],
|
|
24
25
|
"publishConfig": {
|
|
25
26
|
"access": "public"
|