@eslaykey/dsh-breeze-tts 1.0.5 → 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 +47 -0
- package/README.md +2 -0
- package/client.js +629 -339
- package/index.js +181 -237
- package/package.json +3 -2
- package/plan.js +242 -0
package/client.js
CHANGED
|
@@ -22,10 +22,11 @@ window.__ModuleLoader__.load({
|
|
|
22
22
|
},
|
|
23
23
|
|
|
24
24
|
label: {
|
|
25
|
-
voice: '音色', mood: '
|
|
26
|
-
balance: '
|
|
25
|
+
voice: '音色', mood: '默认语气', previewText: '试听文案', dailyLimit: '每日字数上限',
|
|
26
|
+
balance: 'Breeze 余额', todayUsage: '今日朗读字数', preview: '试听', save: '保存设置',
|
|
27
27
|
saving: '保存中…', synthesizing: '合成中…', refresh: '刷新', designed: '自捏',
|
|
28
28
|
readAloud: '朗读这条', replay: '重播上一条', replayEmpty: '还没有可重播的音频', saved: '已保存 ✓',
|
|
29
|
+
unsaved: '有未保存的更改', invalidDailyLimit: '每日字数上限至少为 1 字',
|
|
29
30
|
},
|
|
30
31
|
status: { ready: '就绪', missingKey: '缺少 API key', credits: 'credits', chars: '字' },
|
|
31
32
|
hint: { key: '把 Breeze API key 写进 ~/.dsh/breeze.json 的 apiKey 字段。', limit: '超过上限会拒绝合成,避免意外烧额度。' },
|
|
@@ -36,13 +37,17 @@ window.__ModuleLoader__.load({
|
|
|
36
37
|
voiceManageHint: '只有你自己生成的音色可以在这里改名或删除',
|
|
37
38
|
apiKey: 'API Key',
|
|
38
39
|
keyBound: '已连接',
|
|
40
|
+
keyUnverified: '已保存,暂无法验证',
|
|
39
41
|
keyMissing: '尚未连接,填入 Breeze 的 API key 后点连接',
|
|
40
42
|
keyRequired: '请先填入 API key',
|
|
41
43
|
keyConnected: '连接成功',
|
|
42
44
|
keyDisconnected: '已断开',
|
|
43
45
|
connect: '连接',
|
|
46
|
+
changeKey: '更换 API Key',
|
|
47
|
+
manageKey: '管理',
|
|
48
|
+
closeKey: '收起',
|
|
44
49
|
disconnect: '断开',
|
|
45
|
-
cloneNotice: '
|
|
50
|
+
cloneNotice: '在 Breeze 官网克隆的音色会出现在音色列表中。',
|
|
46
51
|
renameVoice: '重命名',
|
|
47
52
|
renamePlaceholder: '新的音色名称',
|
|
48
53
|
saveName: '保存名称',
|
|
@@ -54,15 +59,16 @@ window.__ModuleLoader__.load({
|
|
|
54
59
|
voiceRemoved: '已从音色库移除',
|
|
55
60
|
emotionMode: '语气模式',
|
|
56
61
|
emotionSaved: '语气模式已切换',
|
|
62
|
+
emotionImmediate: '切换后立即生效',
|
|
57
63
|
emotionFixed: '固定',
|
|
58
64
|
emotionInfer: '智能推断',
|
|
59
65
|
emotionMarker: '模型标注',
|
|
60
66
|
emotionFixedHint: '全程使用上面选中的语气朗读,不做任何切换',
|
|
61
67
|
emotionInferHint: '按标点自动切换:问号→好奇、感叹号→兴奋、省略号→失落;分段变多会拖慢生成',
|
|
62
|
-
emotionMarkerHint: '
|
|
63
|
-
emotionMarkerNote: '
|
|
68
|
+
emotionMarkerHint: '回复中的表情标记指定接下来一段的朗读语气。分段越多,合成越慢。',
|
|
69
|
+
emotionMarkerNote: '模型标注是实验功能。模型可能漏标、选错语气或输出不完整的标记。',
|
|
64
70
|
publicVoices: '公开音色',
|
|
65
|
-
publicVoicesHint: '
|
|
71
|
+
publicVoicesHint: '从 Breeze 公共音色库添加音色。',
|
|
66
72
|
openLibrary: '更多公开音色',
|
|
67
73
|
collapseLibrary: '收起音色库',
|
|
68
74
|
libraryTitle: '官方音色库',
|
|
@@ -126,27 +132,32 @@ window.__ModuleLoader__.load({
|
|
|
126
132
|
},
|
|
127
133
|
|
|
128
134
|
label: {
|
|
129
|
-
voice: 'Voice', mood: '
|
|
130
|
-
balance: '
|
|
135
|
+
voice: 'Voice', mood: 'Default tone', previewText: 'Preview line', dailyLimit: 'Daily character limit',
|
|
136
|
+
balance: 'Breeze balance', todayUsage: 'Characters read today', preview: 'Preview', save: 'Save settings',
|
|
131
137
|
saving: 'Saving…', synthesizing: 'Synthesizing…', refresh: 'Refresh', designed: 'Designed',
|
|
132
138
|
readAloud: 'Read aloud', replay: 'Replay', replayEmpty: 'Nothing to replay yet', saved: 'Saved ✓',
|
|
139
|
+
unsaved: 'Unsaved changes', invalidDailyLimit: 'Set a daily limit of at least 1 character',
|
|
133
140
|
},
|
|
134
141
|
status: { ready: 'Ready', missingKey: 'Missing API key', credits: 'credits', chars: 'chars' },
|
|
135
142
|
hint: { key: 'Write the Breeze API key into apiKey of ~/.dsh/breeze.json.', limit: 'Synthesis is refused past the limit so credits cannot run away.' },
|
|
136
143
|
extra: {
|
|
137
144
|
apiKey: 'API key',
|
|
138
145
|
keyBound: 'Connected',
|
|
146
|
+
keyUnverified: 'Key saved, connection unverified',
|
|
139
147
|
keyMissing: 'Not connected. Paste your Breeze API key and press Connect.',
|
|
140
148
|
keyRequired: 'Enter an API key first',
|
|
141
149
|
keyConnected: 'Connected',
|
|
142
150
|
keyDisconnected: 'Disconnected',
|
|
143
151
|
connect: 'Connect',
|
|
152
|
+
changeKey: 'Replace API key',
|
|
153
|
+
manageKey: 'Manage',
|
|
154
|
+
closeKey: 'Close',
|
|
144
155
|
disconnect: 'Disconnect',
|
|
145
156
|
autoSpeak: 'Auto speak',
|
|
146
157
|
autoSpeakHint: 'Automatically read new replies within the configured character limit. Off by default.',
|
|
147
158
|
renameBlocked: 'Built-in and public voices cannot be renamed',
|
|
148
159
|
voiceManageHint: 'Only voices you created can be renamed or deleted here',
|
|
149
|
-
cloneNotice: '
|
|
160
|
+
cloneNotice: 'Voices cloned on the Breeze website appear in the voice list.',
|
|
150
161
|
renameVoice: 'Rename',
|
|
151
162
|
renamePlaceholder: 'New voice name',
|
|
152
163
|
saveName: 'Save name',
|
|
@@ -158,15 +169,16 @@ window.__ModuleLoader__.load({
|
|
|
158
169
|
voiceRemoved: 'Removed from your voices',
|
|
159
170
|
emotionMode: 'Tone mode',
|
|
160
171
|
emotionSaved: 'Tone mode switched',
|
|
172
|
+
emotionImmediate: 'Applies immediately',
|
|
161
173
|
emotionFixed: 'Fixed',
|
|
162
174
|
emotionInfer: 'Infer',
|
|
163
175
|
emotionMarker: 'Model tagged',
|
|
164
176
|
emotionFixedHint: 'Speak everything with the tone selected above, no switching',
|
|
165
177
|
emotionInferHint: 'Switch by punctuation: question → curious, exclamation → excited, ellipsis → sad; more segments means slower synthesis',
|
|
166
|
-
emotionMarkerHint: '
|
|
167
|
-
emotionMarkerNote: 'Model tagging is experimental
|
|
178
|
+
emotionMarkerHint: 'Emoji markers in the reply select the spoken tone for the next segment. More segments take longer to synthesize.',
|
|
179
|
+
emotionMarkerNote: 'Model tagging is experimental. The model may omit a marker, pick the wrong tone, or emit an incomplete marker.',
|
|
168
180
|
publicVoices: 'Public voices',
|
|
169
|
-
publicVoicesHint: '
|
|
181
|
+
publicVoicesHint: 'Add voices from the Breeze public library.',
|
|
170
182
|
openLibrary: 'Browse public voices',
|
|
171
183
|
collapseLibrary: 'Collapse library',
|
|
172
184
|
libraryTitle: 'Public voice library',
|
|
@@ -252,21 +264,31 @@ window.__ModuleLoader__.load({
|
|
|
252
264
|
idle: 'var(--dsw-alias-state-idle-primary)',
|
|
253
265
|
}
|
|
254
266
|
|
|
267
|
+
const usageListeners = new Set()
|
|
268
|
+
const usageChangingRoutes = new Set(['/synth', '/settings', '/connect', '/disconnect'])
|
|
269
|
+
|
|
255
270
|
async function api(route, options) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
271
|
+
try {
|
|
272
|
+
const response = await fetch(ENDPOINT + route, options)
|
|
273
|
+
const type = response.headers.get('content-type') || ''
|
|
274
|
+
if (type.includes('application/json')) {
|
|
275
|
+
const data = await response.json()
|
|
276
|
+
if (!response.ok) {
|
|
277
|
+
const failure = new Error(data.error || `HTTP ${response.status}`)
|
|
278
|
+
failure.code = data.code || ''
|
|
279
|
+
failure.status = data.status || response.status
|
|
280
|
+
throw failure
|
|
281
|
+
}
|
|
282
|
+
return data
|
|
283
|
+
}
|
|
284
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
285
|
+
return response.blob()
|
|
286
|
+
} finally {
|
|
287
|
+
// Some segments can count towards usage even when synthesis fails.
|
|
288
|
+
if (options?.method === 'POST' && usageChangingRoutes.has(route)) {
|
|
289
|
+
for (const refresh of usageListeners) refresh()
|
|
265
290
|
}
|
|
266
|
-
return data
|
|
267
291
|
}
|
|
268
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
269
|
-
return response.blob()
|
|
270
292
|
}
|
|
271
293
|
|
|
272
294
|
function humanError(t, error) {
|
|
@@ -395,6 +417,8 @@ window.__ModuleLoader__.load({
|
|
|
395
417
|
'.dsh-breeze-row:first-of-type{border-top:0}',
|
|
396
418
|
'.dsh-breeze-key{flex:0 0 132px;font-size:13px;color:' + COLOR.secondary + '}',
|
|
397
419
|
'.dsh-breeze-value{flex:1;min-width:0;display:flex;align-items:center;gap:8px;flex-wrap:wrap}',
|
|
420
|
+
'.dsh-breeze-key-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;width:100%}',
|
|
421
|
+
'.dsh-breeze-savebar{position:sticky;bottom:0;z-index:1;display:flex;align-items:center;gap:10px;flex-wrap:wrap;border-top:1px solid ' + COLOR.border + ';background:' + COLOR.surface + ';box-shadow:0 32px 0 ' + COLOR.surface + ';padding:10px 0;margin-top:16px}',
|
|
398
422
|
'.dsh-breeze-control{font:inherit;font-size:13px;height:30px;padding:0 10px;border-radius:8px;border:1px solid ' + COLOR.borderStrong + ';background:' + COLOR.nested + ';color:' + COLOR.primary + ';min-width:0}',
|
|
399
423
|
'.dsh-breeze-control:focus-visible{outline:2px solid ' + COLOR.brand + ';outline-offset:1px}',
|
|
400
424
|
'.dsh-breeze-chip{font:inherit;font-size:12px;height:26px;padding:0 10px;border-radius:999px;border:0;background:color-mix(in srgb,' + COLOR.primary + ' 9%,transparent);color:' + COLOR.secondary + ';cursor:pointer}',
|
|
@@ -417,19 +441,23 @@ window.__ModuleLoader__.load({
|
|
|
417
441
|
|
|
418
442
|
function useStatus() {
|
|
419
443
|
const [state, setState] = React.useState({ loading: true, data: null, error: null })
|
|
420
|
-
const load = React.useCallback(async (
|
|
444
|
+
const load = React.useCallback(async () => {
|
|
421
445
|
try {
|
|
422
446
|
const data = await api('/status')
|
|
423
447
|
setState({ loading: false, data, error: null })
|
|
424
448
|
return data
|
|
425
449
|
} catch (error) {
|
|
426
|
-
setState({ loading: false,
|
|
427
|
-
if (rethrow) throw error
|
|
450
|
+
setState((previous) => ({ ...previous, loading: false, error: error instanceof Error ? error.message : String(error) }))
|
|
428
451
|
return null
|
|
429
452
|
}
|
|
430
453
|
}, [])
|
|
454
|
+
const update = React.useCallback((patch) => {
|
|
455
|
+
setState((previous) => previous.data
|
|
456
|
+
? { ...previous, data: { ...previous.data, ...patch } }
|
|
457
|
+
: previous)
|
|
458
|
+
}, [])
|
|
431
459
|
React.useEffect(() => { load() }, [load])
|
|
432
|
-
return [state, load]
|
|
460
|
+
return [state, load, update]
|
|
433
461
|
}
|
|
434
462
|
|
|
435
463
|
const SKIP_TYPES = ["reasoning", "thinking", "reasoning-delta", "thinking-delta", "redacted-thinking"]
|
|
@@ -481,7 +509,9 @@ function stripEmoji(text) {
|
|
|
481
509
|
}
|
|
482
510
|
|
|
483
511
|
function cleanForSpeech(text, keepTags) {
|
|
512
|
+
// Convert Markdown markers before stripping links and emoji from the speech text.
|
|
484
513
|
let value = String(text ?? '')
|
|
514
|
+
.replace(/(?<![!\\])\[\p{Extended_Pictographic}\uFE0F?\]\(breeze-mood:([a-z-]+)\)/giu, '<!--mood:$1-->')
|
|
485
515
|
const tags = []
|
|
486
516
|
if (keepTags) {
|
|
487
517
|
value = value.replace(/<!--[\s\S]*?-->/g, (match) => {
|
|
@@ -526,10 +556,84 @@ function cleanForSpeech(text, keepTags) {
|
|
|
526
556
|
if (!target) return ""
|
|
527
557
|
const message = target.message && typeof target.message === "object" ? target.message : target
|
|
528
558
|
const direct = textBlocks(message.content, [])
|
|
529
|
-
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
559
|
+
const typed = direct.length ? direct : collectText(message, [], 0)
|
|
560
|
+
const blocks = typed.length ? typed : collectAnyText(message, [], 0)
|
|
561
|
+
return cleanForSpeech(blocks.join('\n'), true)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* One pending auto-speak timer bound to a generation token.
|
|
566
|
+
* A session switch invalidates the token, so a stale timer or a late
|
|
567
|
+
* /status response from the previous session can never speak.
|
|
568
|
+
*/
|
|
569
|
+
function createTurnTimer() {
|
|
570
|
+
let generation = 0
|
|
571
|
+
let handle = null
|
|
572
|
+
const clear = () => {
|
|
573
|
+
if (handle !== null) {
|
|
574
|
+
window.clearTimeout(handle)
|
|
575
|
+
handle = null
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return {
|
|
579
|
+
generation: () => generation,
|
|
580
|
+
invalidate() {
|
|
581
|
+
generation += 1
|
|
582
|
+
clear()
|
|
583
|
+
},
|
|
584
|
+
clear,
|
|
585
|
+
schedule(token, delay, run) {
|
|
586
|
+
clear()
|
|
587
|
+
handle = window.setTimeout(() => {
|
|
588
|
+
handle = null
|
|
589
|
+
if (generation === token) run()
|
|
590
|
+
}, delay)
|
|
591
|
+
},
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Decide what the auto-speaker may do with one chat view state.
|
|
597
|
+
* Pure: no timers, no requests, so it can be tested offline.
|
|
598
|
+
*/
|
|
599
|
+
function decideAutoSpeak(view) {
|
|
600
|
+
const legacy = view && view.legacy
|
|
601
|
+
if (!legacy || !legacy.turnEnds || typeof legacy.turnEnds.has !== "function") {
|
|
602
|
+
return { action: "skip", reason: "no-turn-signal" }
|
|
603
|
+
}
|
|
604
|
+
if (legacy.partial) return { action: "wait", reason: "streaming" }
|
|
605
|
+
if (Array.isArray(legacy.runningCalls) && legacy.runningCalls.length > 0) {
|
|
606
|
+
return { action: "wait", reason: "tool-running" }
|
|
607
|
+
}
|
|
608
|
+
const turns = view.timeline && view.timeline.turns
|
|
609
|
+
const nodes = Array.isArray(legacy.nodes) ? legacy.nodes : []
|
|
610
|
+
for (let index = nodes.length - 1; index >= 0; index -= 1) {
|
|
611
|
+
const node = nodes[index]
|
|
612
|
+
if (!node || typeof node !== "object") continue
|
|
613
|
+
if (String(node.kind || "") !== "assistant") continue
|
|
614
|
+
if (node.interrupted === true) continue
|
|
615
|
+
if (node.turn === undefined || node.turn === null) continue
|
|
616
|
+
if (!legacy.turnEnds.has(node.turn)) continue
|
|
617
|
+
const turn = turns && typeof turns.get === "function" ? turns.get(node.turn) : undefined
|
|
618
|
+
const reason = turn && turn.end && turn.end.data ? turn.end.data.reason : undefined
|
|
619
|
+
const kind = reason && typeof reason.kind === "string" ? reason.kind : ""
|
|
620
|
+
if (kind !== "completed") {
|
|
621
|
+
return { action: "skip", reason: "turn-" + (kind || "unknown"), turn: node.turn }
|
|
622
|
+
}
|
|
623
|
+
const id = node.id || node.messageId || (node.message && node.message.id) || ""
|
|
624
|
+
if (!id) continue
|
|
625
|
+
let text = ""
|
|
626
|
+
try {
|
|
627
|
+
const message = node.message && typeof node.message === "object" ? node.message : node
|
|
628
|
+
text = textBlocks(message.content, []).join(" ")
|
|
629
|
+
if (!text) text = collectText(node, [], 0).join(" ")
|
|
630
|
+
} catch (error) {
|
|
631
|
+
text = ""
|
|
632
|
+
}
|
|
633
|
+
if (!text) continue
|
|
634
|
+
return { action: "candidate", id, turn: node.turn, kind, text }
|
|
635
|
+
}
|
|
636
|
+
return { action: "none", reason: "no-candidate" }
|
|
533
637
|
}
|
|
534
638
|
|
|
535
639
|
function SpeakButton(props) {
|
|
@@ -549,7 +653,11 @@ function cleanForSpeech(text, keepTags) {
|
|
|
549
653
|
const speak = async () => {
|
|
550
654
|
setPhase('busy')
|
|
551
655
|
try {
|
|
552
|
-
const
|
|
656
|
+
const limit = 600
|
|
657
|
+
const markerStart = text.lastIndexOf('<!--', limit - 1)
|
|
658
|
+
const cut = markerStart >= 0 && text.indexOf('-->', markerStart) + 3 > limit
|
|
659
|
+
? markerStart : limit
|
|
660
|
+
const data = await speakRemotely({ text: text.slice(0, cut) })
|
|
553
661
|
setPhase('playing')
|
|
554
662
|
const wait = Math.max(1200, Number(data.chars || 0) * 260)
|
|
555
663
|
window.setTimeout(() => setPhase('idle'), wait)
|
|
@@ -576,38 +684,45 @@ function cleanForSpeech(text, keepTags) {
|
|
|
576
684
|
|
|
577
685
|
function AutoSpeakChip(props) {
|
|
578
686
|
const t = props.t
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
if (!played.current) {
|
|
582
|
-
const key = 'breeze-tts:spoken:' + (props.sessionId || 'global')
|
|
687
|
+
const playedFor = (sessionId) => {
|
|
688
|
+
const key = 'breeze-tts:spoken:' + (sessionId || 'global')
|
|
583
689
|
let stored = null
|
|
584
690
|
try {
|
|
585
691
|
stored = JSON.parse(window.localStorage.getItem(key) || 'null')
|
|
586
692
|
} catch {
|
|
587
693
|
stored = null
|
|
588
694
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
695
|
+
const list = Array.isArray(stored) ? stored : (stored && Array.isArray(stored.ids) ? stored.ids : [])
|
|
696
|
+
const skippedList = stored && Array.isArray(stored.skipped) ? stored.skipped : []
|
|
697
|
+
return { key, ids: new Set(list), skipped: new Set(skippedList), texts: new Map() }
|
|
698
|
+
}
|
|
699
|
+
const playedSession = React.useRef(props.sessionId || 'global')
|
|
700
|
+
const played = React.useRef(null)
|
|
701
|
+
if (!played.current) played.current = playedFor(props.sessionId)
|
|
702
|
+
const persist = () => {
|
|
703
|
+
try {
|
|
704
|
+
window.localStorage.setItem(played.current.key, JSON.stringify({
|
|
705
|
+
ids: Array.from(played.current.ids).slice(-400),
|
|
706
|
+
skipped: Array.from(played.current.skipped).slice(-400),
|
|
707
|
+
}))
|
|
708
|
+
} catch (error) {
|
|
709
|
+
/* storage full or disabled */
|
|
593
710
|
}
|
|
594
711
|
}
|
|
595
712
|
const markSpoken = (id, text) => {
|
|
596
713
|
played.current.ids.add(id)
|
|
597
714
|
if (text) played.current.texts.set(text.slice(0, 80), Date.now())
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
715
|
+
persist()
|
|
716
|
+
}
|
|
717
|
+
const markSkipped = (id) => {
|
|
718
|
+
played.current.skipped.add(id)
|
|
719
|
+
persist()
|
|
604
720
|
}
|
|
605
721
|
const primed = React.useRef(false)
|
|
606
|
-
const
|
|
607
|
-
const pendingRef = React.useRef(null)
|
|
722
|
+
const warned = React.useRef(false)
|
|
608
723
|
const focused = React.useRef(true)
|
|
609
724
|
const snapshot = typeof props.useChat === 'function'
|
|
610
|
-
? props.useChat((value) => (value && typeof value === 'object' ? value
|
|
725
|
+
? props.useChat((value) => (value && typeof value === 'object' ? value : undefined))
|
|
611
726
|
: undefined
|
|
612
727
|
|
|
613
728
|
React.useEffect(() => {
|
|
@@ -635,117 +750,216 @@ function cleanForSpeech(text, keepTags) {
|
|
|
635
750
|
}
|
|
636
751
|
}, [])
|
|
637
752
|
|
|
753
|
+
const gate = React.useRef(null)
|
|
754
|
+
const pending = React.useRef({ id: "", token: -1 })
|
|
755
|
+
const retryAt = React.useRef(new Map())
|
|
756
|
+
const retryCounts = React.useRef(new Map())
|
|
757
|
+
const [tick, setTick] = React.useState(0)
|
|
758
|
+
if (!gate.current) gate.current = createTurnTimer()
|
|
759
|
+
|
|
638
760
|
React.useEffect(() => {
|
|
639
|
-
|
|
640
|
-
if (
|
|
761
|
+
gate.current.invalidate()
|
|
762
|
+
if (playedSession.current !== (props.sessionId || "global")) {
|
|
763
|
+
playedSession.current = props.sessionId || "global"
|
|
764
|
+
played.current = playedFor(props.sessionId)
|
|
765
|
+
primed.current = false
|
|
766
|
+
warned.current = false
|
|
767
|
+
}
|
|
768
|
+
return () => {
|
|
769
|
+
gate.current.invalidate()
|
|
770
|
+
pending.current = { id: "", token: -1 }
|
|
771
|
+
}
|
|
772
|
+
}, [props.sessionId])
|
|
773
|
+
|
|
774
|
+
const stillMine = (id, token) => gate.current.generation() === token
|
|
775
|
+
&& pending.current.id === id
|
|
776
|
+
&& pending.current.token === token
|
|
777
|
+
|
|
778
|
+
const release = (id, token) => {
|
|
779
|
+
if (stillMine(id, token)) pending.current = { id: "", token: -1 }
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const attempt = async (id, spokenText, plain, token) => {
|
|
783
|
+
if (!stillMine(id, token)) {
|
|
784
|
+
release(id, token)
|
|
785
|
+
return
|
|
786
|
+
}
|
|
787
|
+
let data = null
|
|
788
|
+
try {
|
|
789
|
+
data = await api("/status")
|
|
790
|
+
} catch (error) {
|
|
791
|
+
data = null
|
|
792
|
+
}
|
|
793
|
+
if (!stillMine(id, token)) {
|
|
794
|
+
release(id, token)
|
|
795
|
+
return
|
|
796
|
+
}
|
|
797
|
+
if (!data) {
|
|
798
|
+
// /status is read-only, so a bounded retry cannot cost anything.
|
|
799
|
+
retryLater(id, token)
|
|
800
|
+
release(id, token)
|
|
801
|
+
return
|
|
802
|
+
}
|
|
803
|
+
const limit = Number(data.autoSpeakMaxChars || 0)
|
|
804
|
+
const refused = !data.autoSpeak
|
|
805
|
+
|| limit <= 0
|
|
806
|
+
|| plain.length > limit
|
|
807
|
+
|| (!data.backgroundPlay && !focused.current)
|
|
808
|
+
if (refused) {
|
|
809
|
+
markSkipped(id)
|
|
810
|
+
release(id, token)
|
|
811
|
+
return
|
|
812
|
+
}
|
|
813
|
+
try {
|
|
814
|
+
await speakRemotely({ text: spokenText }, { host: true })
|
|
815
|
+
} catch (error) {
|
|
816
|
+
// The synthesis (and possibly playback) request was already sent:
|
|
817
|
+
// replaying it could charge and speak twice, so it is recorded as
|
|
818
|
+
// skipped and left to the manual button.
|
|
819
|
+
if (stillMine(id, token)) markSkipped(id)
|
|
820
|
+
release(id, token)
|
|
821
|
+
return
|
|
822
|
+
}
|
|
823
|
+
if (stillMine(id, token)) {
|
|
824
|
+
markSpoken(id, spokenText)
|
|
825
|
+
}
|
|
826
|
+
release(id, token)
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
const retryLater = (id, token) => {
|
|
830
|
+
if (!stillMine(id, token)) return
|
|
831
|
+
const attempts = (retryCounts.current.get(id) || 0) + 1
|
|
832
|
+
retryCounts.current.set(id, attempts)
|
|
833
|
+
if (attempts >= 3) {
|
|
834
|
+
markSkipped(id)
|
|
835
|
+
return
|
|
836
|
+
}
|
|
837
|
+
retryAt.current.set(id, Date.now() + 3000 * attempts)
|
|
838
|
+
window.setTimeout(() => setTick((value) => value + 1), 3000 * attempts + 20)
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
React.useEffect(() => {
|
|
842
|
+
if (!snapshot) {
|
|
843
|
+
gate.current.invalidate()
|
|
844
|
+
pending.current = { id: "", token: -1 }
|
|
845
|
+
return undefined
|
|
846
|
+
}
|
|
847
|
+
const view = snapshot
|
|
848
|
+
const legacy = view.legacy
|
|
849
|
+
const nodes = legacy && Array.isArray(legacy.nodes) ? legacy.nodes : []
|
|
641
850
|
|
|
642
851
|
if (!primed.current) {
|
|
643
|
-
if (!nodes.length) return
|
|
852
|
+
if (!nodes.length) return undefined
|
|
644
853
|
primed.current = true
|
|
645
854
|
for (const node of nodes) {
|
|
646
855
|
const id = node && (node.id || node.messageId || (node.message && node.message.id))
|
|
647
|
-
if (id) markSpoken(id,
|
|
856
|
+
if (id) markSpoken(id, "")
|
|
648
857
|
}
|
|
649
|
-
return
|
|
858
|
+
return undefined
|
|
650
859
|
}
|
|
651
860
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
let raw = ''
|
|
667
|
-
let source = 'content'
|
|
668
|
-
try {
|
|
669
|
-
const message = node.message && typeof node.message === 'object' ? node.message : node
|
|
670
|
-
raw = textBlocks(message.content, []).join(' ')
|
|
671
|
-
if (!raw) {
|
|
672
|
-
raw = collectText(node, [], 0).join(' ')
|
|
673
|
-
source = 'collect'
|
|
861
|
+
const decision = decideAutoSpeak(view)
|
|
862
|
+
if (decision.action === "skip" && decision.reason === "no-turn-signal") {
|
|
863
|
+
gate.current.invalidate()
|
|
864
|
+
pending.current = { id: "", token: -1 }
|
|
865
|
+
if (!warned.current) {
|
|
866
|
+
warned.current = true
|
|
867
|
+
try {
|
|
868
|
+
fetch(ENDPOINT + "/log", {
|
|
869
|
+
method: "POST",
|
|
870
|
+
headers: { "content-type": "application/json" },
|
|
871
|
+
body: JSON.stringify({ msg: "auto-speak disabled: " + decision.reason }),
|
|
872
|
+
}).catch(() => {})
|
|
873
|
+
} catch (error) {
|
|
874
|
+
/* logging must never break the chip */
|
|
674
875
|
}
|
|
675
|
-
} catch {
|
|
676
|
-
raw = ''
|
|
677
876
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
877
|
+
return undefined
|
|
878
|
+
}
|
|
879
|
+
if (decision.action !== "candidate") {
|
|
880
|
+
gate.current.invalidate()
|
|
881
|
+
pending.current = { id: "", token: -1 }
|
|
882
|
+
return undefined
|
|
883
|
+
}
|
|
884
|
+
if (played.current.ids.has(decision.id) || played.current.skipped.has(decision.id)) {
|
|
885
|
+
release(decision.id, pending.current.token)
|
|
886
|
+
return undefined
|
|
887
|
+
}
|
|
888
|
+
if (pending.current.id === decision.id && pending.current.token === gate.current.generation()) {
|
|
889
|
+
return undefined
|
|
890
|
+
}
|
|
891
|
+
if ((retryAt.current.get(decision.id) || 0) > Date.now()) return undefined
|
|
892
|
+
|
|
893
|
+
const spokenText = cleanForSpeech(decision.text, true)
|
|
894
|
+
const plain = cleanForSpeech(decision.text)
|
|
895
|
+
if (!plain) return undefined
|
|
896
|
+
const recent = played.current.texts.get(plain.slice(0, 80))
|
|
897
|
+
if (recent && Date.now() - recent < 60000) {
|
|
898
|
+
markSkipped(decision.id)
|
|
899
|
+
return undefined
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
gate.current.invalidate()
|
|
903
|
+
const token = gate.current.generation()
|
|
904
|
+
pending.current = { id: decision.id, token }
|
|
905
|
+
gate.current.schedule(token, 400, () => {
|
|
906
|
+
void attempt(decision.id, spokenText, plain, token)
|
|
907
|
+
})
|
|
908
|
+
return undefined
|
|
909
|
+
}, [snapshot, tick])
|
|
910
|
+
|
|
911
|
+
return h(QuotaChip, { t })
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function QuotaChip({ t }) {
|
|
915
|
+
const [data, setData] = React.useState(null)
|
|
916
|
+
React.useEffect(() => {
|
|
917
|
+
let active = true
|
|
918
|
+
let loading = false
|
|
919
|
+
let queued = false
|
|
920
|
+
let timer
|
|
921
|
+
|
|
922
|
+
const refresh = async () => {
|
|
923
|
+
window.clearTimeout(timer)
|
|
924
|
+
if (!active || document.visibilityState === 'hidden') return
|
|
925
|
+
if (loading) {
|
|
926
|
+
queued = true
|
|
696
927
|
return
|
|
697
928
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
id = candidateId
|
|
929
|
+
|
|
930
|
+
loading = true
|
|
931
|
+
queued = false
|
|
702
932
|
try {
|
|
703
|
-
const
|
|
704
|
-
|
|
705
|
-
const kinds = blocks.slice(0, 6).map((b) => String((b && (b.type || b.kind)) || '?')).join(',')
|
|
706
|
-
fetch('/breeze-tts/log', {
|
|
707
|
-
method: 'POST',
|
|
708
|
-
headers: { 'content-type': 'application/json' },
|
|
709
|
-
body: JSON.stringify({ msg: 'speak src=' + source + ' id=' + candidateId.slice(0, 18) + ' len=' + plain.length + ' kinds=' + kinds }),
|
|
710
|
-
}).catch(() => {})
|
|
933
|
+
const usage = await api('/usage', { cache: 'no-store', signal: AbortSignal.timeout(5000) })
|
|
934
|
+
if (active) setData(usage)
|
|
711
935
|
} catch {
|
|
712
|
-
|
|
936
|
+
// Keep the last count displayed and retry on the next refresh.
|
|
937
|
+
} finally {
|
|
938
|
+
loading = false
|
|
939
|
+
if (active && document.visibilityState !== 'hidden') {
|
|
940
|
+
if (queued) void refresh()
|
|
941
|
+
else timer = window.setTimeout(refresh, 5000)
|
|
942
|
+
}
|
|
713
943
|
}
|
|
714
|
-
break
|
|
715
|
-
}
|
|
716
|
-
if (!id) {
|
|
717
|
-
const last = nodes[nodes.length - 1]
|
|
718
|
-
const shape = last && typeof last === 'object' ? Object.keys(last).slice(0, 10).join(',') : 'none'
|
|
719
|
-
const kind = last && typeof last === 'object' ? String(last.kind || last.type || '?') : '?'
|
|
720
|
-
const blocks = last && Array.isArray(last.blocks) ? last.blocks : []
|
|
721
|
-
const probe = blocks[0] && typeof blocks[0] === 'object'
|
|
722
|
-
? Object.keys(blocks[0]).slice(0, 8).join(',') + '|type=' + String(blocks[0].type || blocks[0].kind || '?')
|
|
723
|
-
: 'none'
|
|
724
|
-
return
|
|
725
944
|
}
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
.catch(() => {})
|
|
945
|
+
|
|
946
|
+
usageListeners.add(refresh)
|
|
947
|
+
window.addEventListener('focus', refresh)
|
|
948
|
+
document.addEventListener('visibilitychange', refresh)
|
|
949
|
+
void refresh()
|
|
950
|
+
return () => {
|
|
951
|
+
active = false
|
|
952
|
+
window.clearTimeout(timer)
|
|
953
|
+
usageListeners.delete(refresh)
|
|
954
|
+
window.removeEventListener('focus', refresh)
|
|
955
|
+
document.removeEventListener('visibilitychange', refresh)
|
|
738
956
|
}
|
|
739
|
-
}, [
|
|
957
|
+
}, [])
|
|
740
958
|
|
|
741
|
-
const data = state.data
|
|
742
959
|
if (!data) return null
|
|
743
|
-
const
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
const enabled = Boolean(data.autoSpeak)
|
|
747
|
-
const label = data.ok
|
|
748
|
-
? `${used} / ${limit} ${t('status.chars')}${enabled ? ' · ' + t('extra.autoOn') : ''}`
|
|
960
|
+
const tone = data.hasKey ? COLOR.success : COLOR.error
|
|
961
|
+
const label = data.hasKey
|
|
962
|
+
? `${data.chars} / ${data.limit} ${t('status.chars')}${data.autoSpeak ? ' · ' + t('extra.autoOn') : ''}`
|
|
749
963
|
: t('status.missingKey')
|
|
750
964
|
|
|
751
965
|
return h('div', {
|
|
@@ -760,17 +974,14 @@ function cleanForSpeech(text, keepTags) {
|
|
|
760
974
|
|
|
761
975
|
function SettingsPage(props) {
|
|
762
976
|
const t = props.t
|
|
763
|
-
const [state, reload] = useStatus()
|
|
977
|
+
const [state, reload, updateStatus] = useStatus()
|
|
764
978
|
const [voices, setVoices] = React.useState([])
|
|
765
|
-
const [
|
|
766
|
-
const [moodId, setMoodId] = React.useState('normal')
|
|
767
|
-
const [emotionMode, setEmotionMode] = React.useState('fixed')
|
|
768
|
-
const [tones, setTones] = React.useState([])
|
|
769
|
-
const [savedVoices, setSavedVoices] = React.useState([])
|
|
979
|
+
const [draft, setDraft] = React.useState({})
|
|
770
980
|
const [voiceRenameOpen, setVoiceRenameOpen] = React.useState(false)
|
|
771
981
|
const [voiceNameDraft, setVoiceNameDraft] = React.useState('')
|
|
772
982
|
const [designName, setDesignName] = React.useState('')
|
|
773
983
|
const [apiKeyInput, setApiKeyInput] = React.useState('')
|
|
984
|
+
const [manageKeyOpen, setManageKeyOpen] = React.useState(false)
|
|
774
985
|
const [connectNote, setConnectNote] = React.useState(null)
|
|
775
986
|
const [voiceNames, setVoiceNames] = React.useState({})
|
|
776
987
|
const [libraryOpen, setLibraryOpen] = React.useState(false)
|
|
@@ -779,38 +990,60 @@ function cleanForSpeech(text, keepTags) {
|
|
|
779
990
|
const [toneEditId, setToneEditId] = React.useState('')
|
|
780
991
|
const [toneDraftName, setToneDraftName] = React.useState('')
|
|
781
992
|
const [toneDraftText, setToneDraftText] = React.useState('')
|
|
782
|
-
const [previewText, setPreviewText] = React.useState('')
|
|
783
|
-
const [dailyChars, setDailyChars] = React.useState(1500)
|
|
784
|
-
const [autoSpeak, setAutoSpeak] = React.useState(false)
|
|
785
|
-
const [autoMax, setAutoMax] = React.useState(120)
|
|
786
|
-
const [backgroundPlay, setBackgroundPlay] = React.useState(false)
|
|
787
|
-
const [customMood, setCustomMood] = React.useState('')
|
|
788
993
|
const [designDesc, setDesignDesc] = React.useState('')
|
|
789
994
|
const [designText, setDesignText] = React.useState('')
|
|
790
995
|
const [candidates, setCandidates] = React.useState([])
|
|
791
996
|
const [phase, setPhase] = React.useState('idle')
|
|
792
997
|
const [notice, setNotice] = React.useState('')
|
|
998
|
+
const [saveNote, setSaveNote] = React.useState(null)
|
|
999
|
+
const [modeNote, setModeNote] = React.useState(null)
|
|
1000
|
+
const [designNote, setDesignNote] = React.useState('')
|
|
793
1001
|
const [refreshNote, setRefreshNote] = React.useState({ text: '', tone: 'muted' })
|
|
794
1002
|
|
|
1003
|
+
const data = state.data
|
|
1004
|
+
const hasKey = Boolean(data?.hasKey)
|
|
1005
|
+
const storedSettings = {
|
|
1006
|
+
voiceId: data?.voiceId || '',
|
|
1007
|
+
moodId: data?.moodId || 'normal',
|
|
1008
|
+
previewText: data?.previewText ?? '',
|
|
1009
|
+
dailyChars: String(data?.today?.limit ?? 1500),
|
|
1010
|
+
autoSpeak: Boolean(data?.autoSpeak),
|
|
1011
|
+
autoSpeakMaxChars: Number(data?.autoSpeakMaxChars ?? 120),
|
|
1012
|
+
backgroundPlay: Boolean(data?.backgroundPlay),
|
|
1013
|
+
}
|
|
1014
|
+
const { voiceId, moodId, previewText, dailyChars, autoSpeak, autoSpeakMaxChars: autoMax, backgroundPlay } = {
|
|
1015
|
+
...storedSettings, ...draft,
|
|
1016
|
+
}
|
|
1017
|
+
const changes = Object.fromEntries(Object.entries(draft).filter(([key, value]) => !Object.is(value, storedSettings[key])))
|
|
1018
|
+
const dirty = Object.keys(changes).length > 0
|
|
1019
|
+
const emotionMode = data?.emotionMode || 'fixed'
|
|
1020
|
+
const tones = Array.isArray(data?.tones) ? data.tones : []
|
|
1021
|
+
const savedVoices = Array.isArray(data?.savedVoices) ? data.savedVoices : []
|
|
1022
|
+
|
|
1023
|
+
const editSetting = (key, value) => {
|
|
1024
|
+
setDraft((previous) => {
|
|
1025
|
+
const next = { ...previous, [key]: value }
|
|
1026
|
+
if (phase !== 'save' && Object.is(value, storedSettings[key])) delete next[key]
|
|
1027
|
+
return next
|
|
1028
|
+
})
|
|
1029
|
+
setSaveNote(null)
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
const clearDraftField = (key) => {
|
|
1033
|
+
setDraft((previous) => {
|
|
1034
|
+
if (!Object.hasOwn(previous, key)) return previous
|
|
1035
|
+
const next = { ...previous }
|
|
1036
|
+
delete next[key]
|
|
1037
|
+
return next
|
|
1038
|
+
})
|
|
1039
|
+
setSaveNote(null)
|
|
1040
|
+
}
|
|
1041
|
+
|
|
795
1042
|
React.useEffect(() => {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
setEmotionMode(data.emotionMode || 'fixed')
|
|
801
|
-
setTones(Array.isArray(data.tones) ? data.tones : [])
|
|
802
|
-
setSavedVoices(Array.isArray(data.savedVoices) ? data.savedVoices : [])
|
|
803
|
-
setPreviewText(data.previewText || '')
|
|
804
|
-
setDailyChars(data.today ? data.today.limit : 1500)
|
|
805
|
-
setAutoSpeak(Boolean(data.autoSpeak))
|
|
806
|
-
setAutoMax(Number(data.autoSpeakMaxChars || 120))
|
|
807
|
-
setBackgroundPlay(Boolean(data.backgroundPlay))
|
|
808
|
-
setCustomMood(String(data.customMood || ''))
|
|
809
|
-
}, [state.data])
|
|
810
|
-
|
|
811
|
-
const hasKey = Boolean(state.data && state.data.hasKey)
|
|
812
|
-
React.useEffect(() => {
|
|
813
|
-
if (!hasKey) return undefined
|
|
1043
|
+
if (!hasKey) {
|
|
1044
|
+
setVoices([])
|
|
1045
|
+
return undefined
|
|
1046
|
+
}
|
|
814
1047
|
let alive = true
|
|
815
1048
|
api('/voices')
|
|
816
1049
|
.then((data) => { if (alive) setVoices(data.voices || []) })
|
|
@@ -818,12 +1051,11 @@ function cleanForSpeech(text, keepTags) {
|
|
|
818
1051
|
return () => { alive = false }
|
|
819
1052
|
}, [hasKey])
|
|
820
1053
|
|
|
821
|
-
const data = state.data
|
|
822
1054
|
const presets = data && Array.isArray(data.voicePresets) ? data.voicePresets : []
|
|
823
1055
|
const extra = voices.filter((voice) => !presets.some((preset) => preset.voiceId === voice.voiceId))
|
|
824
1056
|
const balance = data && typeof data.balance === 'number' ? data.balance : null
|
|
825
1057
|
const used = data && data.today ? data.today.chars : 0
|
|
826
|
-
const limit = data
|
|
1058
|
+
const limit = data?.today?.limit ?? Number(storedSettings.dailyChars)
|
|
827
1059
|
|
|
828
1060
|
const connectKey = async () => {
|
|
829
1061
|
const key = apiKeyInput.trim()
|
|
@@ -840,13 +1072,16 @@ function cleanForSpeech(text, keepTags) {
|
|
|
840
1072
|
body: JSON.stringify({ apiKey: key }),
|
|
841
1073
|
})
|
|
842
1074
|
setApiKeyInput('')
|
|
1075
|
+
setManageKeyOpen(false)
|
|
843
1076
|
setConnectNote({
|
|
844
1077
|
tone: 'ok',
|
|
845
1078
|
text: t('extra.keyConnected') + (typeof result.balance === 'number' ? ' · ' + result.balance.toFixed(1) + ' ' + t('status.credits') : ''),
|
|
846
1079
|
})
|
|
847
|
-
reload()
|
|
848
|
-
|
|
849
|
-
|
|
1080
|
+
await reload()
|
|
1081
|
+
if (hasKey) {
|
|
1082
|
+
const freshVoices = await api('/voices').catch(() => null)
|
|
1083
|
+
if (freshVoices && Array.isArray(freshVoices.voices)) setVoices(freshVoices.voices)
|
|
1084
|
+
}
|
|
850
1085
|
} catch (error) {
|
|
851
1086
|
setConnectNote({ tone: 'error', text: humanError(t, error) })
|
|
852
1087
|
}
|
|
@@ -858,8 +1093,10 @@ function cleanForSpeech(text, keepTags) {
|
|
|
858
1093
|
setConnectNote(null)
|
|
859
1094
|
try {
|
|
860
1095
|
await api('/disconnect', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' })
|
|
1096
|
+
setApiKeyInput('')
|
|
1097
|
+
setManageKeyOpen(false)
|
|
861
1098
|
setConnectNote({ tone: 'muted', text: t('extra.keyDisconnected') })
|
|
862
|
-
reload()
|
|
1099
|
+
await reload()
|
|
863
1100
|
} catch (error) {
|
|
864
1101
|
setConnectNote({ tone: 'error', text: humanError(t, error) })
|
|
865
1102
|
}
|
|
@@ -880,31 +1117,34 @@ function cleanForSpeech(text, keepTags) {
|
|
|
880
1117
|
}
|
|
881
1118
|
|
|
882
1119
|
const save = async () => {
|
|
1120
|
+
if (!data || !dirty || phase !== 'idle') return
|
|
1121
|
+
const patch = { ...changes }
|
|
1122
|
+
if (Object.hasOwn(patch, 'dailyChars')) {
|
|
1123
|
+
const dailyLimit = Math.floor(Number(patch.dailyChars))
|
|
1124
|
+
if (!Number.isFinite(dailyLimit) || dailyLimit < 1) {
|
|
1125
|
+
setSaveNote({ text: t('label.invalidDailyLimit'), error: true })
|
|
1126
|
+
return
|
|
1127
|
+
}
|
|
1128
|
+
patch.dailyChars = dailyLimit
|
|
1129
|
+
}
|
|
883
1130
|
setPhase('save')
|
|
884
|
-
|
|
1131
|
+
setSaveNote(null)
|
|
885
1132
|
try {
|
|
886
|
-
await api('/settings', {
|
|
1133
|
+
const result = await api('/settings', {
|
|
887
1134
|
method: 'POST',
|
|
888
1135
|
headers: { 'content-type': 'application/json' },
|
|
889
|
-
body: JSON.stringify(
|
|
890
|
-
voiceId,
|
|
891
|
-
moodId,
|
|
892
|
-
emotionMode,
|
|
893
|
-
tones: tones.filter((tone) => !tone.builtin),
|
|
894
|
-
previewText,
|
|
895
|
-
dailyChars: Number(dailyChars),
|
|
896
|
-
autoSpeak,
|
|
897
|
-
autoSpeakMaxChars: Number(autoMax),
|
|
898
|
-
backgroundPlay,
|
|
899
|
-
customMood,
|
|
900
|
-
}),
|
|
1136
|
+
body: JSON.stringify(patch),
|
|
901
1137
|
})
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
1138
|
+
const { dailyChars: savedLimit, ...saved } = result.saved
|
|
1139
|
+
if (savedLimit !== undefined) saved.today = { ...data.today, limit: savedLimit }
|
|
1140
|
+
updateStatus(saved)
|
|
1141
|
+
setDraft((current) => Object.fromEntries(Object.entries(current).filter(([key, value]) =>
|
|
1142
|
+
!Object.hasOwn(result.saved, key) || !Object.is(value, changes[key]))))
|
|
1143
|
+
setSaveNote({ text: t('label.saved'), error: false })
|
|
905
1144
|
} catch (error) {
|
|
1145
|
+
setSaveNote({ text: humanError(t, error), error: true })
|
|
1146
|
+
} finally {
|
|
906
1147
|
setPhase('idle')
|
|
907
|
-
setNotice(humanError(t, error))
|
|
908
1148
|
}
|
|
909
1149
|
}
|
|
910
1150
|
|
|
@@ -912,19 +1152,39 @@ function cleanForSpeech(text, keepTags) {
|
|
|
912
1152
|
setPhase('refresh')
|
|
913
1153
|
setRefreshNote({ text: '', tone: 'muted' })
|
|
914
1154
|
try {
|
|
915
|
-
const fresh = await
|
|
916
|
-
|
|
1155
|
+
const fresh = await api('/status')
|
|
1156
|
+
updateStatus({ today: fresh.today, balance: fresh.error ? balance : fresh.balance })
|
|
1157
|
+
if (fresh.error) throw new Error(fresh.error)
|
|
917
1158
|
const credits = fresh && typeof fresh.balance === 'number' ? ' · ' + fresh.balance.toFixed(1) + ' ' + t('status.credits') : ''
|
|
918
1159
|
setRefreshNote({ text: t('extra.refreshed') + credits, tone: 'ok' })
|
|
919
1160
|
} catch (error) {
|
|
920
|
-
setPhase('idle')
|
|
921
1161
|
setRefreshNote({ text: t('extra.refreshFailed') + ': ' + humanError(t, error), tone: 'error' })
|
|
1162
|
+
} finally {
|
|
1163
|
+
setPhase('idle')
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
const changeEmotionMode = async (next) => {
|
|
1168
|
+
setPhase('emotionMode')
|
|
1169
|
+
setModeNote(null)
|
|
1170
|
+
try {
|
|
1171
|
+
const result = await api('/settings', {
|
|
1172
|
+
method: 'POST',
|
|
1173
|
+
headers: { 'content-type': 'application/json' },
|
|
1174
|
+
body: JSON.stringify({ emotionMode: next }),
|
|
1175
|
+
})
|
|
1176
|
+
updateStatus({ emotionMode: result.saved.emotionMode })
|
|
1177
|
+
setModeNote({ text: t('extra.emotionSaved'), error: false })
|
|
1178
|
+
} catch (error) {
|
|
1179
|
+
setModeNote({ text: humanError(t, error), error: true })
|
|
1180
|
+
} finally {
|
|
1181
|
+
setPhase('idle')
|
|
922
1182
|
}
|
|
923
1183
|
}
|
|
924
1184
|
|
|
925
1185
|
const generate = async () => {
|
|
926
1186
|
setPhase('design')
|
|
927
|
-
|
|
1187
|
+
setDesignNote('')
|
|
928
1188
|
setCandidates([])
|
|
929
1189
|
try {
|
|
930
1190
|
const result = await api('/design', {
|
|
@@ -934,16 +1194,16 @@ function cleanForSpeech(text, keepTags) {
|
|
|
934
1194
|
})
|
|
935
1195
|
setCandidates(result.candidates || [])
|
|
936
1196
|
setPhase('idle')
|
|
937
|
-
if (!result.candidates || !result.candidates.length)
|
|
1197
|
+
if (!result.candidates || !result.candidates.length) setDesignNote(t('extra.designEmpty'))
|
|
938
1198
|
} catch (error) {
|
|
939
1199
|
setPhase('idle')
|
|
940
|
-
|
|
1200
|
+
setDesignNote(humanError(t, error))
|
|
941
1201
|
}
|
|
942
1202
|
}
|
|
943
1203
|
|
|
944
1204
|
const saveCandidate = async (candidate) => {
|
|
945
1205
|
setPhase('saveVoice')
|
|
946
|
-
|
|
1206
|
+
setDesignNote('')
|
|
947
1207
|
try {
|
|
948
1208
|
const result = await api('/save-voice', {
|
|
949
1209
|
method: 'POST',
|
|
@@ -954,17 +1214,18 @@ function cleanForSpeech(text, keepTags) {
|
|
|
954
1214
|
description: designDesc,
|
|
955
1215
|
}),
|
|
956
1216
|
})
|
|
957
|
-
setPhase('idle')
|
|
958
1217
|
if (result.voiceId) {
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1218
|
+
updateStatus({ voiceId: result.voiceId })
|
|
1219
|
+
clearDraftField('voiceId')
|
|
1220
|
+
setDesignNote(t('extra.voiceSaved'))
|
|
1221
|
+
await reload()
|
|
962
1222
|
const fresh = await api('/voices').catch(() => null)
|
|
963
1223
|
if (fresh && Array.isArray(fresh.voices)) setVoices(fresh.voices)
|
|
964
1224
|
}
|
|
965
1225
|
} catch (error) {
|
|
1226
|
+
setDesignNote(humanError(t, error))
|
|
1227
|
+
} finally {
|
|
966
1228
|
setPhase('idle')
|
|
967
|
-
setNotice(humanError(t, error))
|
|
968
1229
|
}
|
|
969
1230
|
}
|
|
970
1231
|
|
|
@@ -986,17 +1247,21 @@ function cleanForSpeech(text, keepTags) {
|
|
|
986
1247
|
language: voice.language || '',
|
|
987
1248
|
description: voice.description || '',
|
|
988
1249
|
}])
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
setNotice(t('extra.voiceAdded'))
|
|
1250
|
+
setPhase('loadVoice')
|
|
1251
|
+
setNotice('')
|
|
992
1252
|
try {
|
|
993
|
-
await api('/settings', {
|
|
1253
|
+
const result = await api('/settings', {
|
|
994
1254
|
method: 'POST',
|
|
995
1255
|
headers: { 'content-type': 'application/json' },
|
|
996
1256
|
body: JSON.stringify({ savedVoices: next }),
|
|
997
1257
|
})
|
|
1258
|
+
updateStatus({ savedVoices: result.saved.savedVoices })
|
|
1259
|
+
editSetting('voiceId', voice.voiceId)
|
|
1260
|
+
setNotice(t('extra.voiceAdded'))
|
|
998
1261
|
} catch (error) {
|
|
999
1262
|
setNotice(humanError(t, error))
|
|
1263
|
+
} finally {
|
|
1264
|
+
setPhase('idle')
|
|
1000
1265
|
}
|
|
1001
1266
|
}
|
|
1002
1267
|
|
|
@@ -1099,8 +1364,8 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1099
1364
|
headers: { 'content-type': 'application/json' },
|
|
1100
1365
|
body: JSON.stringify({ moodId: id, tones: next.filter((tone) => !tone.builtin) }),
|
|
1101
1366
|
})
|
|
1102
|
-
|
|
1103
|
-
|
|
1367
|
+
updateStatus({ tones: next, moodId: id })
|
|
1368
|
+
clearDraftField('moodId')
|
|
1104
1369
|
setToneEditor(false)
|
|
1105
1370
|
setPhase('idle')
|
|
1106
1371
|
setNotice(t('extra.toneSaved'))
|
|
@@ -1121,8 +1386,8 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1121
1386
|
headers: { 'content-type': 'application/json' },
|
|
1122
1387
|
body: JSON.stringify({ moodId: 'normal', tones: next.filter((tone) => !tone.builtin) }),
|
|
1123
1388
|
})
|
|
1124
|
-
|
|
1125
|
-
|
|
1389
|
+
updateStatus({ tones: next, moodId: 'normal' })
|
|
1390
|
+
clearDraftField('moodId')
|
|
1126
1391
|
setPhase('idle')
|
|
1127
1392
|
setNotice(t('extra.toneDeleted'))
|
|
1128
1393
|
} catch (error) {
|
|
@@ -1143,8 +1408,16 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1143
1408
|
})
|
|
1144
1409
|
setPhase('idle')
|
|
1145
1410
|
setNotice(savedVoice ? t('extra.voiceRemoved') : t('extra.voiceDeleted'))
|
|
1146
|
-
|
|
1147
|
-
|
|
1411
|
+
const fallback = presets[0]?.voiceId || ''
|
|
1412
|
+
const patch = {}
|
|
1413
|
+
if (savedVoice) patch.savedVoices = savedVoices.filter((item) => item.voiceId !== voiceId)
|
|
1414
|
+
if (voiceId === storedSettings.voiceId) {
|
|
1415
|
+
patch.voiceId = fallback
|
|
1416
|
+
clearDraftField('voiceId')
|
|
1417
|
+
} else {
|
|
1418
|
+
editSetting('voiceId', fallback)
|
|
1419
|
+
}
|
|
1420
|
+
updateStatus(patch)
|
|
1148
1421
|
const fresh = await api('/voices').catch(() => null)
|
|
1149
1422
|
if (fresh && Array.isArray(fresh.voices)) setVoices(fresh.voices)
|
|
1150
1423
|
} catch (error) {
|
|
@@ -1178,39 +1451,56 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1178
1451
|
|
|
1179
1452
|
h('div', { style: { display: 'flex', flexDirection: 'column' } },
|
|
1180
1453
|
row(t('extra.apiKey'),
|
|
1181
|
-
h('
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1454
|
+
hasKey ? h('span', {
|
|
1455
|
+
style: { fontSize: 12, color: data.ok ? COLOR.success : COLOR.secondary },
|
|
1456
|
+
}, data.ok ? t('extra.keyBound') : t('extra.keyUnverified')) : null,
|
|
1457
|
+
hasKey ? h('button', {
|
|
1458
|
+
type: 'button', className: 'dsh-breeze-btn',
|
|
1459
|
+
'aria-expanded': manageKeyOpen,
|
|
1460
|
+
disabled: phase === 'connect' || phase === 'disconnect',
|
|
1461
|
+
onClick: () => {
|
|
1462
|
+
setManageKeyOpen(!manageKeyOpen)
|
|
1463
|
+
setApiKeyInput('')
|
|
1464
|
+
setConnectNote(null)
|
|
1465
|
+
},
|
|
1466
|
+
}, t(manageKeyOpen ? 'extra.closeKey' : 'extra.manageKey')) : null,
|
|
1467
|
+
!state.loading && (!hasKey || manageKeyOpen)
|
|
1468
|
+
? h('div', { className: 'dsh-breeze-key-actions' },
|
|
1469
|
+
h('input', {
|
|
1470
|
+
className: 'dsh-breeze-control',
|
|
1471
|
+
style: { flex: '1 1 180px', maxWidth: 360 },
|
|
1472
|
+
type: 'password',
|
|
1473
|
+
'aria-label': t('extra.apiKey'),
|
|
1474
|
+
placeholder: 'brz_...',
|
|
1475
|
+
value: apiKeyInput,
|
|
1476
|
+
onChange: (event) => setApiKeyInput(event.target.value),
|
|
1477
|
+
}),
|
|
1478
|
+
h('button', {
|
|
1479
|
+
type: 'button', className: 'dsh-breeze-btn', 'data-primary': hasKey ? 'false' : 'true',
|
|
1480
|
+
onClick: connectKey, disabled: phase !== 'idle',
|
|
1481
|
+
}, phase === 'connect' ? Spinner(12) : t(hasKey ? 'extra.changeKey' : 'extra.connect')),
|
|
1482
|
+
hasKey ? h('button', {
|
|
1483
|
+
type: 'button', className: 'dsh-breeze-btn',
|
|
1484
|
+
onClick: disconnectKey, disabled: phase !== 'idle',
|
|
1485
|
+
}, phase === 'disconnect' ? Spinner(12) : t('extra.disconnect')) : null)
|
|
1198
1486
|
: null,
|
|
1199
|
-
h('span', {
|
|
1487
|
+
connectNote || (!hasKey && !state.loading) ? h('span', {
|
|
1488
|
+
role: 'status',
|
|
1200
1489
|
style: {
|
|
1201
1490
|
fontSize: 12,
|
|
1202
1491
|
color: connectNote
|
|
1203
1492
|
? (connectNote.tone === 'error' ? COLOR.error : connectNote.tone === 'ok' ? COLOR.success : COLOR.secondary)
|
|
1204
1493
|
: COLOR.secondary,
|
|
1205
1494
|
},
|
|
1206
|
-
}, connectNote ? connectNote.text :
|
|
1495
|
+
}, connectNote ? connectNote.text : t('extra.keyMissing')) : null),
|
|
1207
1496
|
|
|
1208
1497
|
row(t('label.voice'),
|
|
1209
1498
|
h('select', {
|
|
1210
1499
|
className: 'dsh-breeze-control',
|
|
1211
|
-
style: { maxWidth:
|
|
1500
|
+
style: { maxWidth: 'min(100%, 340px)' },
|
|
1501
|
+
'aria-label': t('label.voice'),
|
|
1212
1502
|
value: voiceId,
|
|
1213
|
-
onChange: (event) =>
|
|
1503
|
+
onChange: (event) => editSetting('voiceId', event.target.value),
|
|
1214
1504
|
},
|
|
1215
1505
|
presets.map((preset) => h('option', { key: preset.voiceId, value: preset.voiceId }, optionLabel(preset))),
|
|
1216
1506
|
extra.filter((voice) => voice.private).map((voice) => h('option', { key: voice.voiceId, value: voice.voiceId }, optionLabel(voice))),
|
|
@@ -1224,13 +1514,13 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1224
1514
|
type: 'button',
|
|
1225
1515
|
className: 'dsh-breeze-btn',
|
|
1226
1516
|
onClick: startRenameVoice,
|
|
1227
|
-
disabled: !canRenameVoice || phase
|
|
1517
|
+
disabled: !canRenameVoice || phase !== 'idle',
|
|
1228
1518
|
}, t('extra.renameVoice')),
|
|
1229
1519
|
h('button', {
|
|
1230
1520
|
type: 'button',
|
|
1231
1521
|
className: 'dsh-breeze-btn',
|
|
1232
1522
|
onClick: removeVoice,
|
|
1233
|
-
disabled: !canDeleteVoice || phase
|
|
1523
|
+
disabled: !canDeleteVoice || phase !== 'idle',
|
|
1234
1524
|
}, phase === 'deleteVoice' ? Spinner(12) : t('extra.deleteVoice'))),
|
|
1235
1525
|
|
|
1236
1526
|
voiceRenameOpen
|
|
@@ -1244,72 +1534,18 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1244
1534
|
}),
|
|
1245
1535
|
h('button', {
|
|
1246
1536
|
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1247
|
-
onClick: renameVoice, disabled: phase
|
|
1537
|
+
onClick: renameVoice, disabled: phase !== 'idle',
|
|
1248
1538
|
}, phase === 'renameVoice' ? Spinner(12) : t('extra.saveName')),
|
|
1249
1539
|
h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: () => setVoiceRenameOpen(false) }, t('extra.cancel')))
|
|
1250
1540
|
: null,
|
|
1251
1541
|
|
|
1252
|
-
row(t('extra.publicVoices'),
|
|
1253
|
-
h('button', {
|
|
1254
|
-
type: 'button',
|
|
1255
|
-
className: 'dsh-breeze-btn',
|
|
1256
|
-
onClick: () => setLibraryOpen(!libraryOpen),
|
|
1257
|
-
}, libraryOpen ? t('extra.collapseLibrary') : t('extra.openLibrary')),
|
|
1258
|
-
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.publicVoicesHint'))),
|
|
1259
|
-
|
|
1260
|
-
libraryOpen
|
|
1261
|
-
? h('div', {
|
|
1262
|
-
style: {
|
|
1263
|
-
border: '1px solid ' + COLOR.border, borderRadius: 10, background: COLOR.surface,
|
|
1264
|
-
padding: 12, margin: '2px 0 10px',
|
|
1265
|
-
},
|
|
1266
|
-
},
|
|
1267
|
-
h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 8 } },
|
|
1268
|
-
h('div', { style: { fontSize: 13, fontWeight: 600, color: COLOR.primary } }, t('extra.libraryTitle')),
|
|
1269
|
-
h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.librarySubtitle'))),
|
|
1270
|
-
h('input', {
|
|
1271
|
-
className: 'dsh-breeze-control',
|
|
1272
|
-
style: { width: '100%', marginBottom: 8 },
|
|
1273
|
-
placeholder: t('extra.librarySearch'),
|
|
1274
|
-
value: libraryQuery,
|
|
1275
|
-
onChange: (event) => setLibraryQuery(event.target.value),
|
|
1276
|
-
}),
|
|
1277
|
-
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, maxHeight: 260, overflowY: 'auto' } },
|
|
1278
|
-
publicVoices.map((voice) => h('div', {
|
|
1279
|
-
key: voice.voiceId,
|
|
1280
|
-
style: {
|
|
1281
|
-
display: 'flex', alignItems: 'center', gap: 10, padding: '6px 0',
|
|
1282
|
-
borderTop: '1px solid ' + COLOR.border,
|
|
1283
|
-
},
|
|
1284
|
-
},
|
|
1285
|
-
h('div', { style: { flex: 1, minWidth: 0 } },
|
|
1286
|
-
h('div', { style: { fontSize: 13, color: COLOR.primary } }, voice.name + ' · ' + (voice.language || '')),
|
|
1287
|
-
h('div', {
|
|
1288
|
-
style: {
|
|
1289
|
-
fontSize: 12, color: COLOR.secondary, lineHeight: '17px',
|
|
1290
|
-
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
1291
|
-
},
|
|
1292
|
-
}, voice.description || '')),
|
|
1293
|
-
h('button', {
|
|
1294
|
-
type: 'button', className: 'dsh-breeze-btn',
|
|
1295
|
-
onClick: () => audioPreview(voice.voiceId),
|
|
1296
|
-
}, t('label.preview')),
|
|
1297
|
-
h('button', {
|
|
1298
|
-
type: 'button',
|
|
1299
|
-
className: 'dsh-breeze-btn',
|
|
1300
|
-
'data-primary': savedVoices.some((item) => item.voiceId === voice.voiceId) ? 'false' : 'true',
|
|
1301
|
-
disabled: savedVoices.some((item) => item.voiceId === voice.voiceId),
|
|
1302
|
-
onClick: () => loadPublicVoice(voice),
|
|
1303
|
-
}, savedVoices.some((item) => item.voiceId === voice.voiceId) ? t('extra.voiceLoadedTag') : t('extra.loadVoice'))))),
|
|
1304
|
-
publicVoices.length ? null : h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.libraryEmpty')))
|
|
1305
|
-
: null,
|
|
1306
|
-
|
|
1307
1542
|
row(t('label.mood'),
|
|
1308
1543
|
h('select', {
|
|
1309
1544
|
className: 'dsh-breeze-control',
|
|
1310
1545
|
style: { maxWidth: 240 },
|
|
1546
|
+
'aria-label': t('label.mood'),
|
|
1311
1547
|
value: moodId,
|
|
1312
|
-
onChange: (event) =>
|
|
1548
|
+
onChange: (event) => editSetting('moodId', event.target.value),
|
|
1313
1549
|
},
|
|
1314
1550
|
tones.map((tone) => h('option', { key: tone.id, value: tone.id },
|
|
1315
1551
|
(tone.builtin ? t('tone.' + tone.id) : tone.name)
|
|
@@ -1319,7 +1555,7 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1319
1555
|
? h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: startEditTone }, t('extra.editTone'))
|
|
1320
1556
|
: null,
|
|
1321
1557
|
activeTone && !activeTone.builtin
|
|
1322
|
-
? h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: removeTone, disabled: phase
|
|
1558
|
+
? h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: removeTone, disabled: phase !== 'idle' }, t('extra.deleteTone'))
|
|
1323
1559
|
: null),
|
|
1324
1560
|
|
|
1325
1561
|
activeTone
|
|
@@ -1351,7 +1587,7 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1351
1587
|
h('div', { style: { display: 'flex', gap: 8 } },
|
|
1352
1588
|
h('button', {
|
|
1353
1589
|
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1354
|
-
onClick: saveTone, disabled: phase
|
|
1590
|
+
onClick: saveTone, disabled: phase !== 'idle',
|
|
1355
1591
|
}, phase === 'saveTone' ? Spinner(12) : t('extra.saveTone')),
|
|
1356
1592
|
h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: cancelTone }, t('extra.cancel'))))
|
|
1357
1593
|
: null,
|
|
@@ -1360,25 +1596,17 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1360
1596
|
h('select', {
|
|
1361
1597
|
className: 'dsh-breeze-control',
|
|
1362
1598
|
style: { maxWidth: 200 },
|
|
1599
|
+
'aria-label': t('extra.emotionMode'),
|
|
1363
1600
|
value: emotionMode,
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
setEmotionMode(next)
|
|
1367
|
-
try {
|
|
1368
|
-
await api('/settings', {
|
|
1369
|
-
method: 'POST',
|
|
1370
|
-
headers: { 'content-type': 'application/json' },
|
|
1371
|
-
body: JSON.stringify({ emotionMode: next }),
|
|
1372
|
-
})
|
|
1373
|
-
setNotice(t('extra.emotionSaved'))
|
|
1374
|
-
} catch (error) {
|
|
1375
|
-
setNotice(humanError(t, error))
|
|
1376
|
-
}
|
|
1377
|
-
},
|
|
1601
|
+
disabled: !data || phase !== 'idle',
|
|
1602
|
+
onChange: (event) => changeEmotionMode(event.target.value),
|
|
1378
1603
|
},
|
|
1379
1604
|
h('option', { value: 'fixed' }, t('extra.emotionFixed')),
|
|
1380
1605
|
h('option', { value: 'infer' }, t('extra.emotionInfer')),
|
|
1381
1606
|
h('option', { value: 'marker' }, t('extra.emotionMarker'))),
|
|
1607
|
+
h('span', {
|
|
1608
|
+
role: 'status', style: { fontSize: 12, color: modeNote?.error ? COLOR.error : COLOR.secondary },
|
|
1609
|
+
}, modeNote?.text ?? t('extra.emotionImmediate')),
|
|
1382
1610
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } },
|
|
1383
1611
|
emotionMode === 'infer'
|
|
1384
1612
|
? t('extra.emotionInferHint')
|
|
@@ -1386,31 +1614,90 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1386
1614
|
? t('extra.emotionMarkerHint')
|
|
1387
1615
|
: t('extra.emotionFixedHint')),
|
|
1388
1616
|
emotionMode === 'marker'
|
|
1389
|
-
? h('div', { style: { flexBasis: '100%', fontSize: 12, color: COLOR.
|
|
1617
|
+
? h('div', { style: { flexBasis: '100%', fontSize: 12, color: COLOR.secondary, lineHeight: '18px' } }, t('extra.emotionMarkerNote'))
|
|
1390
1618
|
: null),
|
|
1391
1619
|
|
|
1392
1620
|
row(t('label.previewText'),
|
|
1393
1621
|
h('input', {
|
|
1394
1622
|
className: 'dsh-breeze-control',
|
|
1395
|
-
style: { flex: 1
|
|
1623
|
+
style: { flex: '1 1 180px', maxWidth: 420 },
|
|
1624
|
+
'aria-label': t('label.previewText'),
|
|
1396
1625
|
value: previewText,
|
|
1397
|
-
onChange: (event) =>
|
|
1626
|
+
onChange: (event) => editSetting('previewText', event.target.value),
|
|
1398
1627
|
}),
|
|
1399
1628
|
h('button', {
|
|
1400
1629
|
type: 'button',
|
|
1401
1630
|
className: 'dsh-breeze-play',
|
|
1402
1631
|
onClick: preview,
|
|
1403
|
-
disabled: phase
|
|
1404
|
-
}, phase === 'preview' ? Spinner(11) : PlayGlyph(11), h('span', null, t('label.preview')))
|
|
1632
|
+
disabled: phase !== 'idle',
|
|
1633
|
+
}, phase === 'preview' ? Spinner(11) : PlayGlyph(11), h('span', null, t('label.preview'))),
|
|
1634
|
+
notice ? h('span', { role: 'status', style: { flexBasis: '100%', fontSize: 12, color: COLOR.secondary } }, notice) : null),
|
|
1635
|
+
|
|
1636
|
+
row(t('extra.publicVoices'),
|
|
1637
|
+
h('button', {
|
|
1638
|
+
type: 'button',
|
|
1639
|
+
className: 'dsh-breeze-btn',
|
|
1640
|
+
onClick: () => setLibraryOpen(!libraryOpen),
|
|
1641
|
+
}, libraryOpen ? t('extra.collapseLibrary') : t('extra.openLibrary')),
|
|
1642
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.publicVoicesHint'))),
|
|
1643
|
+
|
|
1644
|
+
libraryOpen
|
|
1645
|
+
? h('div', {
|
|
1646
|
+
style: {
|
|
1647
|
+
border: '1px solid ' + COLOR.border, borderRadius: 10, background: COLOR.surface,
|
|
1648
|
+
padding: 12, margin: '2px 0 10px',
|
|
1649
|
+
},
|
|
1650
|
+
},
|
|
1651
|
+
h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 8 } },
|
|
1652
|
+
h('div', { style: { fontSize: 13, fontWeight: 600, color: COLOR.primary } }, t('extra.libraryTitle')),
|
|
1653
|
+
h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.librarySubtitle'))),
|
|
1654
|
+
h('input', {
|
|
1655
|
+
className: 'dsh-breeze-control',
|
|
1656
|
+
style: { width: '100%', marginBottom: 8 },
|
|
1657
|
+
placeholder: t('extra.librarySearch'),
|
|
1658
|
+
value: libraryQuery,
|
|
1659
|
+
onChange: (event) => setLibraryQuery(event.target.value),
|
|
1660
|
+
}),
|
|
1661
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, maxHeight: 260, overflowY: 'auto' } },
|
|
1662
|
+
publicVoices.map((voice) => h('div', {
|
|
1663
|
+
key: voice.voiceId,
|
|
1664
|
+
style: {
|
|
1665
|
+
display: 'flex', alignItems: 'center', gap: 10, padding: '6px 0',
|
|
1666
|
+
borderTop: '1px solid ' + COLOR.border,
|
|
1667
|
+
},
|
|
1668
|
+
},
|
|
1669
|
+
h('div', { style: { flex: 1, minWidth: 0 } },
|
|
1670
|
+
h('div', { style: { fontSize: 13, color: COLOR.primary } }, voice.name + ' · ' + (voice.language || '')),
|
|
1671
|
+
h('div', {
|
|
1672
|
+
style: {
|
|
1673
|
+
fontSize: 12, color: COLOR.secondary, lineHeight: '17px',
|
|
1674
|
+
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
1675
|
+
},
|
|
1676
|
+
}, voice.description || '')),
|
|
1677
|
+
h('button', {
|
|
1678
|
+
type: 'button', className: 'dsh-breeze-btn',
|
|
1679
|
+
disabled: phase !== 'idle',
|
|
1680
|
+
onClick: () => audioPreview(voice.voiceId),
|
|
1681
|
+
}, t('label.preview')),
|
|
1682
|
+
h('button', {
|
|
1683
|
+
type: 'button',
|
|
1684
|
+
className: 'dsh-breeze-btn',
|
|
1685
|
+
'data-primary': savedVoices.some((item) => item.voiceId === voice.voiceId) ? 'false' : 'true',
|
|
1686
|
+
disabled: phase !== 'idle' || savedVoices.some((item) => item.voiceId === voice.voiceId),
|
|
1687
|
+
onClick: () => loadPublicVoice(voice),
|
|
1688
|
+
}, savedVoices.some((item) => item.voiceId === voice.voiceId) ? t('extra.voiceLoadedTag') : t('extra.loadVoice'))))),
|
|
1689
|
+
publicVoices.length ? null : h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.libraryEmpty')))
|
|
1690
|
+
: null,
|
|
1405
1691
|
|
|
1406
1692
|
row(t('extra.autoSpeak'),
|
|
1407
1693
|
h('button', {
|
|
1408
1694
|
type: 'button',
|
|
1409
1695
|
role: 'switch',
|
|
1696
|
+
'aria-label': t('extra.autoSpeak'),
|
|
1410
1697
|
'aria-checked': autoSpeak ? 'true' : 'false',
|
|
1411
1698
|
className: 'dsh-breeze-switch',
|
|
1412
1699
|
'data-on': autoSpeak ? 'true' : 'false',
|
|
1413
|
-
onClick: () =>
|
|
1700
|
+
onClick: () => editSetting('autoSpeak', !autoSpeak),
|
|
1414
1701
|
}, h('span', { className: 'dsh-breeze-knob' })),
|
|
1415
1702
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.autoSpeakHint'))),
|
|
1416
1703
|
|
|
@@ -1418,26 +1705,29 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1418
1705
|
h('button', {
|
|
1419
1706
|
type: 'button',
|
|
1420
1707
|
role: 'switch',
|
|
1708
|
+
'aria-label': t('extra.backgroundPlay'),
|
|
1421
1709
|
'aria-checked': backgroundPlay ? 'true' : 'false',
|
|
1422
1710
|
className: 'dsh-breeze-switch',
|
|
1423
1711
|
'data-on': backgroundPlay ? 'true' : 'false',
|
|
1424
|
-
onClick: () =>
|
|
1712
|
+
onClick: () => editSetting('backgroundPlay', !backgroundPlay),
|
|
1425
1713
|
}, h('span', { className: 'dsh-breeze-knob' })),
|
|
1426
1714
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.backgroundPlayHint'))),
|
|
1427
1715
|
|
|
1428
1716
|
row(t('extra.autoMax'),
|
|
1429
1717
|
h('input', {
|
|
1430
1718
|
type: 'range', min: 0, max: 1000, step: 10,
|
|
1719
|
+
'aria-label': t('extra.autoMax'),
|
|
1431
1720
|
value: Math.min(1000, Math.max(0, Number(autoMax) || 0)),
|
|
1432
|
-
onChange: (event) =>
|
|
1721
|
+
onChange: (event) => editSetting('autoSpeakMaxChars', Number(event.target.value)),
|
|
1433
1722
|
style: { flex: 1, minWidth: 160, maxWidth: 320, accentColor: COLOR.brand },
|
|
1434
1723
|
}),
|
|
1435
1724
|
h('input', {
|
|
1436
1725
|
className: 'dsh-breeze-control',
|
|
1437
1726
|
style: { width: 96 },
|
|
1438
1727
|
type: 'number', min: 0, max: 99999, step: 1,
|
|
1728
|
+
'aria-label': t('extra.autoMax'),
|
|
1439
1729
|
value: autoMax,
|
|
1440
|
-
onChange: (event) =>
|
|
1730
|
+
onChange: (event) => editSetting('autoSpeakMaxChars', Math.max(0, Math.min(99999, Number(event.target.value) || 0))),
|
|
1441
1731
|
}),
|
|
1442
1732
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('status.chars')),
|
|
1443
1733
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.autoMaxHint')),
|
|
@@ -1452,8 +1742,9 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1452
1742
|
className: 'dsh-breeze-control',
|
|
1453
1743
|
style: { width: 110 },
|
|
1454
1744
|
type: 'number', min: 100, step: 100,
|
|
1745
|
+
'aria-label': t('label.dailyLimit'),
|
|
1455
1746
|
value: dailyChars,
|
|
1456
|
-
onChange: (event) =>
|
|
1747
|
+
onChange: (event) => editSetting('dailyChars', event.target.value),
|
|
1457
1748
|
}),
|
|
1458
1749
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('hint.limit'))),
|
|
1459
1750
|
|
|
@@ -1479,7 +1770,7 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1479
1770
|
type: 'button',
|
|
1480
1771
|
className: 'dsh-breeze-btn',
|
|
1481
1772
|
onClick: doRefresh,
|
|
1482
|
-
disabled: phase
|
|
1773
|
+
disabled: !hasKey || phase !== 'idle',
|
|
1483
1774
|
}, phase === 'refresh' ? Spinner(12) : t('label.refresh')),
|
|
1484
1775
|
refreshNote.text
|
|
1485
1776
|
? h('span', {
|
|
@@ -1490,19 +1781,8 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1490
1781
|
}, refreshNote.text)
|
|
1491
1782
|
: null)),
|
|
1492
1783
|
|
|
1493
|
-
h('div', {
|
|
1494
|
-
style: { marginTop: 14, fontSize: 12, lineHeight: '18px', color: COLOR.secondary },
|
|
1495
|
-
}, t('extra.cloneNotice')),
|
|
1496
|
-
|
|
1497
|
-
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginTop: 8 } },
|
|
1498
|
-
h('button', {
|
|
1499
|
-
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1500
|
-
onClick: save, disabled: phase === 'save',
|
|
1501
|
-
}, phase === 'save' ? t('label.saving') : t('label.save')),
|
|
1502
|
-
notice ? h('span', { style: { fontSize: 12, color: COLOR.secondary } }, notice) : null),
|
|
1503
|
-
data && data.ok === false ? h('p', { className: 'dsh-breeze-hint' }, t('hint.key')) : null,
|
|
1504
|
-
|
|
1505
1784
|
sectionTitle(t('extra.designTitle')),
|
|
1785
|
+
h('p', { className: 'dsh-breeze-hint' }, t('extra.cloneNotice')),
|
|
1506
1786
|
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10, marginTop: 4 } },
|
|
1507
1787
|
h('textarea', {
|
|
1508
1788
|
className: 'dsh-breeze-control',
|
|
@@ -1530,10 +1810,11 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1530
1810
|
}),
|
|
1531
1811
|
h('button', {
|
|
1532
1812
|
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1533
|
-
onClick: generate, disabled: phase
|
|
1813
|
+
onClick: generate, disabled: phase !== 'idle' || designDesc.trim().length < 3,
|
|
1534
1814
|
}, phase === 'design' ? t('extra.generating') : t('extra.generate')),
|
|
1535
1815
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.designCost'))),
|
|
1536
1816
|
h('p', { className: 'dsh-breeze-hint', style: { margin: 0 } }, t('extra.designHint')),
|
|
1817
|
+
designNote ? h('p', { className: 'dsh-breeze-hint', role: 'status' }, designNote) : null,
|
|
1537
1818
|
candidates.length
|
|
1538
1819
|
? h('div', { style: { display: 'flex', gap: 10, flexWrap: 'wrap', marginTop: 2 } },
|
|
1539
1820
|
candidates.map((candidate, index) => h('div', {
|
|
@@ -1553,9 +1834,17 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1553
1834
|
h('button', {
|
|
1554
1835
|
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1555
1836
|
onClick: () => saveCandidate(candidate),
|
|
1556
|
-
disabled: phase
|
|
1837
|
+
disabled: phase !== 'idle',
|
|
1557
1838
|
}, t('extra.saveVoice'))))))
|
|
1558
|
-
: null)
|
|
1839
|
+
: null),
|
|
1840
|
+
h('div', { className: 'dsh-breeze-savebar' },
|
|
1841
|
+
h('button', {
|
|
1842
|
+
type: 'button', className: 'dsh-breeze-btn', 'data-primary': dirty ? 'true' : 'false',
|
|
1843
|
+
onClick: save, disabled: !data || !dirty || phase !== 'idle',
|
|
1844
|
+
}, phase === 'save' ? t('label.saving') : t('label.save')),
|
|
1845
|
+
h('span', {
|
|
1846
|
+
role: 'status', style: { fontSize: 12, color: saveNote?.error ? COLOR.error : COLOR.secondary },
|
|
1847
|
+
}, saveNote?.error ? saveNote.text : dirty ? t('label.unsaved') : (saveNote?.text ?? ''))))
|
|
1559
1848
|
}
|
|
1560
1849
|
|
|
1561
1850
|
return {
|
|
@@ -1604,6 +1893,7 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1604
1893
|
locale: NS,
|
|
1605
1894
|
}, (props) => h(AutoSpeakChip, Object.assign({}, props, { t }))))
|
|
1606
1895
|
},
|
|
1896
|
+
__test: { decideAutoSpeak, createTurnTimer, AutoSpeakChip, SpeakButton, QuotaChip, speakRemotely, SettingsPage },
|
|
1607
1897
|
}
|
|
1608
1898
|
},
|
|
1609
1899
|
})
|