@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/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,99 +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) {
|
|
852
|
+
if (!nodes.length) return undefined
|
|
643
853
|
primed.current = true
|
|
644
854
|
for (const node of nodes) {
|
|
645
855
|
const id = node && (node.id || node.messageId || (node.message && node.message.id))
|
|
646
|
-
if (id) markSpoken(id,
|
|
856
|
+
if (id) markSpoken(id, "")
|
|
647
857
|
}
|
|
648
|
-
return
|
|
858
|
+
return undefined
|
|
649
859
|
}
|
|
650
860
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
try {
|
|
667
|
-
raw = collectText(node, [], 0).join(' ')
|
|
668
|
-
if (!raw) raw = collectAnyText(node, [], 0).join(' ')
|
|
669
|
-
} catch {
|
|
670
|
-
raw = ''
|
|
671
|
-
}
|
|
672
|
-
const spokenText = cleanForSpeech(raw, true)
|
|
673
|
-
const plain = cleanForSpeech(raw)
|
|
674
|
-
if (!plain) continue
|
|
675
|
-
const recent = played.current.texts.get(plain.slice(0, 80))
|
|
676
|
-
if (recent && Date.now() - recent < 60000) {
|
|
677
|
-
markSpoken(candidateId, '')
|
|
678
|
-
continue
|
|
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 */
|
|
875
|
+
}
|
|
679
876
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
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
|
|
685
927
|
return
|
|
686
928
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
929
|
+
|
|
930
|
+
loading = true
|
|
931
|
+
queued = false
|
|
932
|
+
try {
|
|
933
|
+
const usage = await api('/usage', { cache: 'no-store', signal: AbortSignal.timeout(5000) })
|
|
934
|
+
if (active) setData(usage)
|
|
935
|
+
} catch {
|
|
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
|
+
}
|
|
691
943
|
}
|
|
692
|
-
pendingRef.current = null
|
|
693
|
-
text = spokenText
|
|
694
|
-
measure = plain
|
|
695
|
-
id = candidateId
|
|
696
|
-
break
|
|
697
944
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
api('/status')
|
|
711
|
-
.then((data) => {
|
|
712
|
-
const limit = Number((data && data.autoSpeakMaxChars) || 0)
|
|
713
|
-
if (!data || !data.autoSpeak) return null
|
|
714
|
-
if (limit <= 0) return null
|
|
715
|
-
if (measure.length > limit) return null
|
|
716
|
-
if (!data.backgroundPlay && !focused.current) return null
|
|
717
|
-
return speakRemotely({ text }, { host: true })
|
|
718
|
-
})
|
|
719
|
-
.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)
|
|
720
956
|
}
|
|
721
|
-
}, [
|
|
957
|
+
}, [])
|
|
722
958
|
|
|
723
|
-
const data = state.data
|
|
724
959
|
if (!data) return null
|
|
725
|
-
const
|
|
726
|
-
const
|
|
727
|
-
|
|
728
|
-
const enabled = Boolean(data.autoSpeak)
|
|
729
|
-
const label = data.ok
|
|
730
|
-
? `${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') : ''}`
|
|
731
963
|
: t('status.missingKey')
|
|
732
964
|
|
|
733
965
|
return h('div', {
|
|
@@ -742,17 +974,14 @@ function cleanForSpeech(text, keepTags) {
|
|
|
742
974
|
|
|
743
975
|
function SettingsPage(props) {
|
|
744
976
|
const t = props.t
|
|
745
|
-
const [state, reload] = useStatus()
|
|
977
|
+
const [state, reload, updateStatus] = useStatus()
|
|
746
978
|
const [voices, setVoices] = React.useState([])
|
|
747
|
-
const [
|
|
748
|
-
const [moodId, setMoodId] = React.useState('normal')
|
|
749
|
-
const [emotionMode, setEmotionMode] = React.useState('fixed')
|
|
750
|
-
const [tones, setTones] = React.useState([])
|
|
751
|
-
const [savedVoices, setSavedVoices] = React.useState([])
|
|
979
|
+
const [draft, setDraft] = React.useState({})
|
|
752
980
|
const [voiceRenameOpen, setVoiceRenameOpen] = React.useState(false)
|
|
753
981
|
const [voiceNameDraft, setVoiceNameDraft] = React.useState('')
|
|
754
982
|
const [designName, setDesignName] = React.useState('')
|
|
755
983
|
const [apiKeyInput, setApiKeyInput] = React.useState('')
|
|
984
|
+
const [manageKeyOpen, setManageKeyOpen] = React.useState(false)
|
|
756
985
|
const [connectNote, setConnectNote] = React.useState(null)
|
|
757
986
|
const [voiceNames, setVoiceNames] = React.useState({})
|
|
758
987
|
const [libraryOpen, setLibraryOpen] = React.useState(false)
|
|
@@ -761,38 +990,60 @@ function cleanForSpeech(text, keepTags) {
|
|
|
761
990
|
const [toneEditId, setToneEditId] = React.useState('')
|
|
762
991
|
const [toneDraftName, setToneDraftName] = React.useState('')
|
|
763
992
|
const [toneDraftText, setToneDraftText] = React.useState('')
|
|
764
|
-
const [previewText, setPreviewText] = React.useState('')
|
|
765
|
-
const [dailyChars, setDailyChars] = React.useState(1500)
|
|
766
|
-
const [autoSpeak, setAutoSpeak] = React.useState(false)
|
|
767
|
-
const [autoMax, setAutoMax] = React.useState(120)
|
|
768
|
-
const [backgroundPlay, setBackgroundPlay] = React.useState(false)
|
|
769
|
-
const [customMood, setCustomMood] = React.useState('')
|
|
770
993
|
const [designDesc, setDesignDesc] = React.useState('')
|
|
771
994
|
const [designText, setDesignText] = React.useState('')
|
|
772
995
|
const [candidates, setCandidates] = React.useState([])
|
|
773
996
|
const [phase, setPhase] = React.useState('idle')
|
|
774
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('')
|
|
775
1001
|
const [refreshNote, setRefreshNote] = React.useState({ text: '', tone: 'muted' })
|
|
776
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
|
+
|
|
777
1042
|
React.useEffect(() => {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
setEmotionMode(data.emotionMode || 'fixed')
|
|
783
|
-
setTones(Array.isArray(data.tones) ? data.tones : [])
|
|
784
|
-
setSavedVoices(Array.isArray(data.savedVoices) ? data.savedVoices : [])
|
|
785
|
-
setPreviewText(data.previewText || '')
|
|
786
|
-
setDailyChars(data.today ? data.today.limit : 1500)
|
|
787
|
-
setAutoSpeak(Boolean(data.autoSpeak))
|
|
788
|
-
setAutoMax(Number(data.autoSpeakMaxChars || 120))
|
|
789
|
-
setBackgroundPlay(Boolean(data.backgroundPlay))
|
|
790
|
-
setCustomMood(String(data.customMood || ''))
|
|
791
|
-
}, [state.data])
|
|
792
|
-
|
|
793
|
-
const hasKey = Boolean(state.data && state.data.hasKey)
|
|
794
|
-
React.useEffect(() => {
|
|
795
|
-
if (!hasKey) return undefined
|
|
1043
|
+
if (!hasKey) {
|
|
1044
|
+
setVoices([])
|
|
1045
|
+
return undefined
|
|
1046
|
+
}
|
|
796
1047
|
let alive = true
|
|
797
1048
|
api('/voices')
|
|
798
1049
|
.then((data) => { if (alive) setVoices(data.voices || []) })
|
|
@@ -800,12 +1051,11 @@ function cleanForSpeech(text, keepTags) {
|
|
|
800
1051
|
return () => { alive = false }
|
|
801
1052
|
}, [hasKey])
|
|
802
1053
|
|
|
803
|
-
const data = state.data
|
|
804
1054
|
const presets = data && Array.isArray(data.voicePresets) ? data.voicePresets : []
|
|
805
1055
|
const extra = voices.filter((voice) => !presets.some((preset) => preset.voiceId === voice.voiceId))
|
|
806
1056
|
const balance = data && typeof data.balance === 'number' ? data.balance : null
|
|
807
1057
|
const used = data && data.today ? data.today.chars : 0
|
|
808
|
-
const limit = data
|
|
1058
|
+
const limit = data?.today?.limit ?? Number(storedSettings.dailyChars)
|
|
809
1059
|
|
|
810
1060
|
const connectKey = async () => {
|
|
811
1061
|
const key = apiKeyInput.trim()
|
|
@@ -822,13 +1072,16 @@ function cleanForSpeech(text, keepTags) {
|
|
|
822
1072
|
body: JSON.stringify({ apiKey: key }),
|
|
823
1073
|
})
|
|
824
1074
|
setApiKeyInput('')
|
|
1075
|
+
setManageKeyOpen(false)
|
|
825
1076
|
setConnectNote({
|
|
826
1077
|
tone: 'ok',
|
|
827
1078
|
text: t('extra.keyConnected') + (typeof result.balance === 'number' ? ' · ' + result.balance.toFixed(1) + ' ' + t('status.credits') : ''),
|
|
828
1079
|
})
|
|
829
|
-
reload()
|
|
830
|
-
|
|
831
|
-
|
|
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
|
+
}
|
|
832
1085
|
} catch (error) {
|
|
833
1086
|
setConnectNote({ tone: 'error', text: humanError(t, error) })
|
|
834
1087
|
}
|
|
@@ -840,8 +1093,10 @@ function cleanForSpeech(text, keepTags) {
|
|
|
840
1093
|
setConnectNote(null)
|
|
841
1094
|
try {
|
|
842
1095
|
await api('/disconnect', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' })
|
|
1096
|
+
setApiKeyInput('')
|
|
1097
|
+
setManageKeyOpen(false)
|
|
843
1098
|
setConnectNote({ tone: 'muted', text: t('extra.keyDisconnected') })
|
|
844
|
-
reload()
|
|
1099
|
+
await reload()
|
|
845
1100
|
} catch (error) {
|
|
846
1101
|
setConnectNote({ tone: 'error', text: humanError(t, error) })
|
|
847
1102
|
}
|
|
@@ -862,31 +1117,34 @@ function cleanForSpeech(text, keepTags) {
|
|
|
862
1117
|
}
|
|
863
1118
|
|
|
864
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
|
+
}
|
|
865
1130
|
setPhase('save')
|
|
866
|
-
|
|
1131
|
+
setSaveNote(null)
|
|
867
1132
|
try {
|
|
868
|
-
await api('/settings', {
|
|
1133
|
+
const result = await api('/settings', {
|
|
869
1134
|
method: 'POST',
|
|
870
1135
|
headers: { 'content-type': 'application/json' },
|
|
871
|
-
body: JSON.stringify(
|
|
872
|
-
voiceId,
|
|
873
|
-
moodId,
|
|
874
|
-
emotionMode,
|
|
875
|
-
tones: tones.filter((tone) => !tone.builtin),
|
|
876
|
-
previewText,
|
|
877
|
-
dailyChars: Number(dailyChars),
|
|
878
|
-
autoSpeak,
|
|
879
|
-
autoSpeakMaxChars: Number(autoMax),
|
|
880
|
-
backgroundPlay,
|
|
881
|
-
customMood,
|
|
882
|
-
}),
|
|
1136
|
+
body: JSON.stringify(patch),
|
|
883
1137
|
})
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
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 })
|
|
887
1144
|
} catch (error) {
|
|
1145
|
+
setSaveNote({ text: humanError(t, error), error: true })
|
|
1146
|
+
} finally {
|
|
888
1147
|
setPhase('idle')
|
|
889
|
-
setNotice(humanError(t, error))
|
|
890
1148
|
}
|
|
891
1149
|
}
|
|
892
1150
|
|
|
@@ -894,19 +1152,39 @@ function cleanForSpeech(text, keepTags) {
|
|
|
894
1152
|
setPhase('refresh')
|
|
895
1153
|
setRefreshNote({ text: '', tone: 'muted' })
|
|
896
1154
|
try {
|
|
897
|
-
const fresh = await
|
|
898
|
-
|
|
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)
|
|
899
1158
|
const credits = fresh && typeof fresh.balance === 'number' ? ' · ' + fresh.balance.toFixed(1) + ' ' + t('status.credits') : ''
|
|
900
1159
|
setRefreshNote({ text: t('extra.refreshed') + credits, tone: 'ok' })
|
|
901
1160
|
} catch (error) {
|
|
902
|
-
setPhase('idle')
|
|
903
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')
|
|
904
1182
|
}
|
|
905
1183
|
}
|
|
906
1184
|
|
|
907
1185
|
const generate = async () => {
|
|
908
1186
|
setPhase('design')
|
|
909
|
-
|
|
1187
|
+
setDesignNote('')
|
|
910
1188
|
setCandidates([])
|
|
911
1189
|
try {
|
|
912
1190
|
const result = await api('/design', {
|
|
@@ -916,16 +1194,16 @@ function cleanForSpeech(text, keepTags) {
|
|
|
916
1194
|
})
|
|
917
1195
|
setCandidates(result.candidates || [])
|
|
918
1196
|
setPhase('idle')
|
|
919
|
-
if (!result.candidates || !result.candidates.length)
|
|
1197
|
+
if (!result.candidates || !result.candidates.length) setDesignNote(t('extra.designEmpty'))
|
|
920
1198
|
} catch (error) {
|
|
921
1199
|
setPhase('idle')
|
|
922
|
-
|
|
1200
|
+
setDesignNote(humanError(t, error))
|
|
923
1201
|
}
|
|
924
1202
|
}
|
|
925
1203
|
|
|
926
1204
|
const saveCandidate = async (candidate) => {
|
|
927
1205
|
setPhase('saveVoice')
|
|
928
|
-
|
|
1206
|
+
setDesignNote('')
|
|
929
1207
|
try {
|
|
930
1208
|
const result = await api('/save-voice', {
|
|
931
1209
|
method: 'POST',
|
|
@@ -936,17 +1214,18 @@ function cleanForSpeech(text, keepTags) {
|
|
|
936
1214
|
description: designDesc,
|
|
937
1215
|
}),
|
|
938
1216
|
})
|
|
939
|
-
setPhase('idle')
|
|
940
1217
|
if (result.voiceId) {
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1218
|
+
updateStatus({ voiceId: result.voiceId })
|
|
1219
|
+
clearDraftField('voiceId')
|
|
1220
|
+
setDesignNote(t('extra.voiceSaved'))
|
|
1221
|
+
await reload()
|
|
944
1222
|
const fresh = await api('/voices').catch(() => null)
|
|
945
1223
|
if (fresh && Array.isArray(fresh.voices)) setVoices(fresh.voices)
|
|
946
1224
|
}
|
|
947
1225
|
} catch (error) {
|
|
1226
|
+
setDesignNote(humanError(t, error))
|
|
1227
|
+
} finally {
|
|
948
1228
|
setPhase('idle')
|
|
949
|
-
setNotice(humanError(t, error))
|
|
950
1229
|
}
|
|
951
1230
|
}
|
|
952
1231
|
|
|
@@ -968,17 +1247,21 @@ function cleanForSpeech(text, keepTags) {
|
|
|
968
1247
|
language: voice.language || '',
|
|
969
1248
|
description: voice.description || '',
|
|
970
1249
|
}])
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
setNotice(t('extra.voiceAdded'))
|
|
1250
|
+
setPhase('loadVoice')
|
|
1251
|
+
setNotice('')
|
|
974
1252
|
try {
|
|
975
|
-
await api('/settings', {
|
|
1253
|
+
const result = await api('/settings', {
|
|
976
1254
|
method: 'POST',
|
|
977
1255
|
headers: { 'content-type': 'application/json' },
|
|
978
1256
|
body: JSON.stringify({ savedVoices: next }),
|
|
979
1257
|
})
|
|
1258
|
+
updateStatus({ savedVoices: result.saved.savedVoices })
|
|
1259
|
+
editSetting('voiceId', voice.voiceId)
|
|
1260
|
+
setNotice(t('extra.voiceAdded'))
|
|
980
1261
|
} catch (error) {
|
|
981
1262
|
setNotice(humanError(t, error))
|
|
1263
|
+
} finally {
|
|
1264
|
+
setPhase('idle')
|
|
982
1265
|
}
|
|
983
1266
|
}
|
|
984
1267
|
|
|
@@ -1081,8 +1364,8 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1081
1364
|
headers: { 'content-type': 'application/json' },
|
|
1082
1365
|
body: JSON.stringify({ moodId: id, tones: next.filter((tone) => !tone.builtin) }),
|
|
1083
1366
|
})
|
|
1084
|
-
|
|
1085
|
-
|
|
1367
|
+
updateStatus({ tones: next, moodId: id })
|
|
1368
|
+
clearDraftField('moodId')
|
|
1086
1369
|
setToneEditor(false)
|
|
1087
1370
|
setPhase('idle')
|
|
1088
1371
|
setNotice(t('extra.toneSaved'))
|
|
@@ -1103,8 +1386,8 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1103
1386
|
headers: { 'content-type': 'application/json' },
|
|
1104
1387
|
body: JSON.stringify({ moodId: 'normal', tones: next.filter((tone) => !tone.builtin) }),
|
|
1105
1388
|
})
|
|
1106
|
-
|
|
1107
|
-
|
|
1389
|
+
updateStatus({ tones: next, moodId: 'normal' })
|
|
1390
|
+
clearDraftField('moodId')
|
|
1108
1391
|
setPhase('idle')
|
|
1109
1392
|
setNotice(t('extra.toneDeleted'))
|
|
1110
1393
|
} catch (error) {
|
|
@@ -1125,8 +1408,16 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1125
1408
|
})
|
|
1126
1409
|
setPhase('idle')
|
|
1127
1410
|
setNotice(savedVoice ? t('extra.voiceRemoved') : t('extra.voiceDeleted'))
|
|
1128
|
-
|
|
1129
|
-
|
|
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)
|
|
1130
1421
|
const fresh = await api('/voices').catch(() => null)
|
|
1131
1422
|
if (fresh && Array.isArray(fresh.voices)) setVoices(fresh.voices)
|
|
1132
1423
|
} catch (error) {
|
|
@@ -1160,39 +1451,56 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1160
1451
|
|
|
1161
1452
|
h('div', { style: { display: 'flex', flexDirection: 'column' } },
|
|
1162
1453
|
row(t('extra.apiKey'),
|
|
1163
|
-
h('
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
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)
|
|
1180
1486
|
: null,
|
|
1181
|
-
h('span', {
|
|
1487
|
+
connectNote || (!hasKey && !state.loading) ? h('span', {
|
|
1488
|
+
role: 'status',
|
|
1182
1489
|
style: {
|
|
1183
1490
|
fontSize: 12,
|
|
1184
1491
|
color: connectNote
|
|
1185
1492
|
? (connectNote.tone === 'error' ? COLOR.error : connectNote.tone === 'ok' ? COLOR.success : COLOR.secondary)
|
|
1186
1493
|
: COLOR.secondary,
|
|
1187
1494
|
},
|
|
1188
|
-
}, connectNote ? connectNote.text :
|
|
1495
|
+
}, connectNote ? connectNote.text : t('extra.keyMissing')) : null),
|
|
1189
1496
|
|
|
1190
1497
|
row(t('label.voice'),
|
|
1191
1498
|
h('select', {
|
|
1192
1499
|
className: 'dsh-breeze-control',
|
|
1193
|
-
style: { maxWidth:
|
|
1500
|
+
style: { maxWidth: 'min(100%, 340px)' },
|
|
1501
|
+
'aria-label': t('label.voice'),
|
|
1194
1502
|
value: voiceId,
|
|
1195
|
-
onChange: (event) =>
|
|
1503
|
+
onChange: (event) => editSetting('voiceId', event.target.value),
|
|
1196
1504
|
},
|
|
1197
1505
|
presets.map((preset) => h('option', { key: preset.voiceId, value: preset.voiceId }, optionLabel(preset))),
|
|
1198
1506
|
extra.filter((voice) => voice.private).map((voice) => h('option', { key: voice.voiceId, value: voice.voiceId }, optionLabel(voice))),
|
|
@@ -1206,13 +1514,13 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1206
1514
|
type: 'button',
|
|
1207
1515
|
className: 'dsh-breeze-btn',
|
|
1208
1516
|
onClick: startRenameVoice,
|
|
1209
|
-
disabled: !canRenameVoice || phase
|
|
1517
|
+
disabled: !canRenameVoice || phase !== 'idle',
|
|
1210
1518
|
}, t('extra.renameVoice')),
|
|
1211
1519
|
h('button', {
|
|
1212
1520
|
type: 'button',
|
|
1213
1521
|
className: 'dsh-breeze-btn',
|
|
1214
1522
|
onClick: removeVoice,
|
|
1215
|
-
disabled: !canDeleteVoice || phase
|
|
1523
|
+
disabled: !canDeleteVoice || phase !== 'idle',
|
|
1216
1524
|
}, phase === 'deleteVoice' ? Spinner(12) : t('extra.deleteVoice'))),
|
|
1217
1525
|
|
|
1218
1526
|
voiceRenameOpen
|
|
@@ -1226,72 +1534,18 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1226
1534
|
}),
|
|
1227
1535
|
h('button', {
|
|
1228
1536
|
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1229
|
-
onClick: renameVoice, disabled: phase
|
|
1537
|
+
onClick: renameVoice, disabled: phase !== 'idle',
|
|
1230
1538
|
}, phase === 'renameVoice' ? Spinner(12) : t('extra.saveName')),
|
|
1231
1539
|
h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: () => setVoiceRenameOpen(false) }, t('extra.cancel')))
|
|
1232
1540
|
: null,
|
|
1233
1541
|
|
|
1234
|
-
row(t('extra.publicVoices'),
|
|
1235
|
-
h('button', {
|
|
1236
|
-
type: 'button',
|
|
1237
|
-
className: 'dsh-breeze-btn',
|
|
1238
|
-
onClick: () => setLibraryOpen(!libraryOpen),
|
|
1239
|
-
}, libraryOpen ? t('extra.collapseLibrary') : t('extra.openLibrary')),
|
|
1240
|
-
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.publicVoicesHint'))),
|
|
1241
|
-
|
|
1242
|
-
libraryOpen
|
|
1243
|
-
? h('div', {
|
|
1244
|
-
style: {
|
|
1245
|
-
border: '1px solid ' + COLOR.border, borderRadius: 10, background: COLOR.surface,
|
|
1246
|
-
padding: 12, margin: '2px 0 10px',
|
|
1247
|
-
},
|
|
1248
|
-
},
|
|
1249
|
-
h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 8 } },
|
|
1250
|
-
h('div', { style: { fontSize: 13, fontWeight: 600, color: COLOR.primary } }, t('extra.libraryTitle')),
|
|
1251
|
-
h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.librarySubtitle'))),
|
|
1252
|
-
h('input', {
|
|
1253
|
-
className: 'dsh-breeze-control',
|
|
1254
|
-
style: { width: '100%', marginBottom: 8 },
|
|
1255
|
-
placeholder: t('extra.librarySearch'),
|
|
1256
|
-
value: libraryQuery,
|
|
1257
|
-
onChange: (event) => setLibraryQuery(event.target.value),
|
|
1258
|
-
}),
|
|
1259
|
-
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, maxHeight: 260, overflowY: 'auto' } },
|
|
1260
|
-
publicVoices.map((voice) => h('div', {
|
|
1261
|
-
key: voice.voiceId,
|
|
1262
|
-
style: {
|
|
1263
|
-
display: 'flex', alignItems: 'center', gap: 10, padding: '6px 0',
|
|
1264
|
-
borderTop: '1px solid ' + COLOR.border,
|
|
1265
|
-
},
|
|
1266
|
-
},
|
|
1267
|
-
h('div', { style: { flex: 1, minWidth: 0 } },
|
|
1268
|
-
h('div', { style: { fontSize: 13, color: COLOR.primary } }, voice.name + ' · ' + (voice.language || '')),
|
|
1269
|
-
h('div', {
|
|
1270
|
-
style: {
|
|
1271
|
-
fontSize: 12, color: COLOR.secondary, lineHeight: '17px',
|
|
1272
|
-
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
1273
|
-
},
|
|
1274
|
-
}, voice.description || '')),
|
|
1275
|
-
h('button', {
|
|
1276
|
-
type: 'button', className: 'dsh-breeze-btn',
|
|
1277
|
-
onClick: () => audioPreview(voice.voiceId),
|
|
1278
|
-
}, t('label.preview')),
|
|
1279
|
-
h('button', {
|
|
1280
|
-
type: 'button',
|
|
1281
|
-
className: 'dsh-breeze-btn',
|
|
1282
|
-
'data-primary': savedVoices.some((item) => item.voiceId === voice.voiceId) ? 'false' : 'true',
|
|
1283
|
-
disabled: savedVoices.some((item) => item.voiceId === voice.voiceId),
|
|
1284
|
-
onClick: () => loadPublicVoice(voice),
|
|
1285
|
-
}, savedVoices.some((item) => item.voiceId === voice.voiceId) ? t('extra.voiceLoadedTag') : t('extra.loadVoice'))))),
|
|
1286
|
-
publicVoices.length ? null : h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.libraryEmpty')))
|
|
1287
|
-
: null,
|
|
1288
|
-
|
|
1289
1542
|
row(t('label.mood'),
|
|
1290
1543
|
h('select', {
|
|
1291
1544
|
className: 'dsh-breeze-control',
|
|
1292
1545
|
style: { maxWidth: 240 },
|
|
1546
|
+
'aria-label': t('label.mood'),
|
|
1293
1547
|
value: moodId,
|
|
1294
|
-
onChange: (event) =>
|
|
1548
|
+
onChange: (event) => editSetting('moodId', event.target.value),
|
|
1295
1549
|
},
|
|
1296
1550
|
tones.map((tone) => h('option', { key: tone.id, value: tone.id },
|
|
1297
1551
|
(tone.builtin ? t('tone.' + tone.id) : tone.name)
|
|
@@ -1301,7 +1555,7 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1301
1555
|
? h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: startEditTone }, t('extra.editTone'))
|
|
1302
1556
|
: null,
|
|
1303
1557
|
activeTone && !activeTone.builtin
|
|
1304
|
-
? 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'))
|
|
1305
1559
|
: null),
|
|
1306
1560
|
|
|
1307
1561
|
activeTone
|
|
@@ -1333,7 +1587,7 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1333
1587
|
h('div', { style: { display: 'flex', gap: 8 } },
|
|
1334
1588
|
h('button', {
|
|
1335
1589
|
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1336
|
-
onClick: saveTone, disabled: phase
|
|
1590
|
+
onClick: saveTone, disabled: phase !== 'idle',
|
|
1337
1591
|
}, phase === 'saveTone' ? Spinner(12) : t('extra.saveTone')),
|
|
1338
1592
|
h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: cancelTone }, t('extra.cancel'))))
|
|
1339
1593
|
: null,
|
|
@@ -1342,25 +1596,17 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1342
1596
|
h('select', {
|
|
1343
1597
|
className: 'dsh-breeze-control',
|
|
1344
1598
|
style: { maxWidth: 200 },
|
|
1599
|
+
'aria-label': t('extra.emotionMode'),
|
|
1345
1600
|
value: emotionMode,
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
setEmotionMode(next)
|
|
1349
|
-
try {
|
|
1350
|
-
await api('/settings', {
|
|
1351
|
-
method: 'POST',
|
|
1352
|
-
headers: { 'content-type': 'application/json' },
|
|
1353
|
-
body: JSON.stringify({ emotionMode: next }),
|
|
1354
|
-
})
|
|
1355
|
-
setNotice(t('extra.emotionSaved'))
|
|
1356
|
-
} catch (error) {
|
|
1357
|
-
setNotice(humanError(t, error))
|
|
1358
|
-
}
|
|
1359
|
-
},
|
|
1601
|
+
disabled: !data || phase !== 'idle',
|
|
1602
|
+
onChange: (event) => changeEmotionMode(event.target.value),
|
|
1360
1603
|
},
|
|
1361
1604
|
h('option', { value: 'fixed' }, t('extra.emotionFixed')),
|
|
1362
1605
|
h('option', { value: 'infer' }, t('extra.emotionInfer')),
|
|
1363
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')),
|
|
1364
1610
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } },
|
|
1365
1611
|
emotionMode === 'infer'
|
|
1366
1612
|
? t('extra.emotionInferHint')
|
|
@@ -1368,31 +1614,90 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1368
1614
|
? t('extra.emotionMarkerHint')
|
|
1369
1615
|
: t('extra.emotionFixedHint')),
|
|
1370
1616
|
emotionMode === 'marker'
|
|
1371
|
-
? 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'))
|
|
1372
1618
|
: null),
|
|
1373
1619
|
|
|
1374
1620
|
row(t('label.previewText'),
|
|
1375
1621
|
h('input', {
|
|
1376
1622
|
className: 'dsh-breeze-control',
|
|
1377
|
-
style: { flex: 1
|
|
1623
|
+
style: { flex: '1 1 180px', maxWidth: 420 },
|
|
1624
|
+
'aria-label': t('label.previewText'),
|
|
1378
1625
|
value: previewText,
|
|
1379
|
-
onChange: (event) =>
|
|
1626
|
+
onChange: (event) => editSetting('previewText', event.target.value),
|
|
1380
1627
|
}),
|
|
1381
1628
|
h('button', {
|
|
1382
1629
|
type: 'button',
|
|
1383
1630
|
className: 'dsh-breeze-play',
|
|
1384
1631
|
onClick: preview,
|
|
1385
|
-
disabled: phase
|
|
1386
|
-
}, 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,
|
|
1387
1691
|
|
|
1388
1692
|
row(t('extra.autoSpeak'),
|
|
1389
1693
|
h('button', {
|
|
1390
1694
|
type: 'button',
|
|
1391
1695
|
role: 'switch',
|
|
1696
|
+
'aria-label': t('extra.autoSpeak'),
|
|
1392
1697
|
'aria-checked': autoSpeak ? 'true' : 'false',
|
|
1393
1698
|
className: 'dsh-breeze-switch',
|
|
1394
1699
|
'data-on': autoSpeak ? 'true' : 'false',
|
|
1395
|
-
onClick: () =>
|
|
1700
|
+
onClick: () => editSetting('autoSpeak', !autoSpeak),
|
|
1396
1701
|
}, h('span', { className: 'dsh-breeze-knob' })),
|
|
1397
1702
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.autoSpeakHint'))),
|
|
1398
1703
|
|
|
@@ -1400,26 +1705,29 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1400
1705
|
h('button', {
|
|
1401
1706
|
type: 'button',
|
|
1402
1707
|
role: 'switch',
|
|
1708
|
+
'aria-label': t('extra.backgroundPlay'),
|
|
1403
1709
|
'aria-checked': backgroundPlay ? 'true' : 'false',
|
|
1404
1710
|
className: 'dsh-breeze-switch',
|
|
1405
1711
|
'data-on': backgroundPlay ? 'true' : 'false',
|
|
1406
|
-
onClick: () =>
|
|
1712
|
+
onClick: () => editSetting('backgroundPlay', !backgroundPlay),
|
|
1407
1713
|
}, h('span', { className: 'dsh-breeze-knob' })),
|
|
1408
1714
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.backgroundPlayHint'))),
|
|
1409
1715
|
|
|
1410
1716
|
row(t('extra.autoMax'),
|
|
1411
1717
|
h('input', {
|
|
1412
1718
|
type: 'range', min: 0, max: 1000, step: 10,
|
|
1719
|
+
'aria-label': t('extra.autoMax'),
|
|
1413
1720
|
value: Math.min(1000, Math.max(0, Number(autoMax) || 0)),
|
|
1414
|
-
onChange: (event) =>
|
|
1721
|
+
onChange: (event) => editSetting('autoSpeakMaxChars', Number(event.target.value)),
|
|
1415
1722
|
style: { flex: 1, minWidth: 160, maxWidth: 320, accentColor: COLOR.brand },
|
|
1416
1723
|
}),
|
|
1417
1724
|
h('input', {
|
|
1418
1725
|
className: 'dsh-breeze-control',
|
|
1419
1726
|
style: { width: 96 },
|
|
1420
1727
|
type: 'number', min: 0, max: 99999, step: 1,
|
|
1728
|
+
'aria-label': t('extra.autoMax'),
|
|
1421
1729
|
value: autoMax,
|
|
1422
|
-
onChange: (event) =>
|
|
1730
|
+
onChange: (event) => editSetting('autoSpeakMaxChars', Math.max(0, Math.min(99999, Number(event.target.value) || 0))),
|
|
1423
1731
|
}),
|
|
1424
1732
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('status.chars')),
|
|
1425
1733
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.autoMaxHint')),
|
|
@@ -1434,8 +1742,9 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1434
1742
|
className: 'dsh-breeze-control',
|
|
1435
1743
|
style: { width: 110 },
|
|
1436
1744
|
type: 'number', min: 100, step: 100,
|
|
1745
|
+
'aria-label': t('label.dailyLimit'),
|
|
1437
1746
|
value: dailyChars,
|
|
1438
|
-
onChange: (event) =>
|
|
1747
|
+
onChange: (event) => editSetting('dailyChars', event.target.value),
|
|
1439
1748
|
}),
|
|
1440
1749
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('hint.limit'))),
|
|
1441
1750
|
|
|
@@ -1461,7 +1770,7 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1461
1770
|
type: 'button',
|
|
1462
1771
|
className: 'dsh-breeze-btn',
|
|
1463
1772
|
onClick: doRefresh,
|
|
1464
|
-
disabled: phase
|
|
1773
|
+
disabled: !hasKey || phase !== 'idle',
|
|
1465
1774
|
}, phase === 'refresh' ? Spinner(12) : t('label.refresh')),
|
|
1466
1775
|
refreshNote.text
|
|
1467
1776
|
? h('span', {
|
|
@@ -1472,19 +1781,8 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1472
1781
|
}, refreshNote.text)
|
|
1473
1782
|
: null)),
|
|
1474
1783
|
|
|
1475
|
-
h('div', {
|
|
1476
|
-
style: { marginTop: 14, fontSize: 12, lineHeight: '18px', color: COLOR.secondary },
|
|
1477
|
-
}, t('extra.cloneNotice')),
|
|
1478
|
-
|
|
1479
|
-
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginTop: 8 } },
|
|
1480
|
-
h('button', {
|
|
1481
|
-
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1482
|
-
onClick: save, disabled: phase === 'save',
|
|
1483
|
-
}, phase === 'save' ? t('label.saving') : t('label.save')),
|
|
1484
|
-
notice ? h('span', { style: { fontSize: 12, color: COLOR.secondary } }, notice) : null),
|
|
1485
|
-
data && data.ok === false ? h('p', { className: 'dsh-breeze-hint' }, t('hint.key')) : null,
|
|
1486
|
-
|
|
1487
1784
|
sectionTitle(t('extra.designTitle')),
|
|
1785
|
+
h('p', { className: 'dsh-breeze-hint' }, t('extra.cloneNotice')),
|
|
1488
1786
|
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10, marginTop: 4 } },
|
|
1489
1787
|
h('textarea', {
|
|
1490
1788
|
className: 'dsh-breeze-control',
|
|
@@ -1512,10 +1810,11 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1512
1810
|
}),
|
|
1513
1811
|
h('button', {
|
|
1514
1812
|
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1515
|
-
onClick: generate, disabled: phase
|
|
1813
|
+
onClick: generate, disabled: phase !== 'idle' || designDesc.trim().length < 3,
|
|
1516
1814
|
}, phase === 'design' ? t('extra.generating') : t('extra.generate')),
|
|
1517
1815
|
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.designCost'))),
|
|
1518
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,
|
|
1519
1818
|
candidates.length
|
|
1520
1819
|
? h('div', { style: { display: 'flex', gap: 10, flexWrap: 'wrap', marginTop: 2 } },
|
|
1521
1820
|
candidates.map((candidate, index) => h('div', {
|
|
@@ -1535,9 +1834,17 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1535
1834
|
h('button', {
|
|
1536
1835
|
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1537
1836
|
onClick: () => saveCandidate(candidate),
|
|
1538
|
-
disabled: phase
|
|
1837
|
+
disabled: phase !== 'idle',
|
|
1539
1838
|
}, t('extra.saveVoice'))))))
|
|
1540
|
-
: 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 ?? ''))))
|
|
1541
1848
|
}
|
|
1542
1849
|
|
|
1543
1850
|
return {
|
|
@@ -1586,6 +1893,7 @@ function cleanForSpeech(text, keepTags) {
|
|
|
1586
1893
|
locale: NS,
|
|
1587
1894
|
}, (props) => h(AutoSpeakChip, Object.assign({}, props, { t }))))
|
|
1588
1895
|
},
|
|
1896
|
+
__test: { decideAutoSpeak, createTurnTimer, AutoSpeakChip, SpeakButton, QuotaChip, speakRemotely, SettingsPage },
|
|
1589
1897
|
}
|
|
1590
1898
|
},
|
|
1591
1899
|
})
|