@eslaykey/dsh-breeze-tts 0.0.0-stage → 1.0.1
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 +28 -0
- package/LICENSE +21 -0
- package/README.md +84 -2
- package/client.js +1556 -0
- package/cordis.patch.yml +4 -0
- package/icon.svg +12 -0
- package/index.js +1011 -0
- package/locale/en.json +35 -0
- package/locale/zh.json +35 -0
- package/package.json +49 -6
package/client.js
ADDED
|
@@ -0,0 +1,1556 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: '@eslaykey/dsh-breeze-tts',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const h = React.createElement
|
|
6
|
+
const NS = 'dsh-breeze-tts'
|
|
7
|
+
const ENDPOINT = '/breeze-tts'
|
|
8
|
+
|
|
9
|
+
const DICT = {
|
|
10
|
+
zh: {
|
|
11
|
+
meta: { title: 'Breeze 语音朗读', description: '用 Breeze Blue 把文字念出来。' },
|
|
12
|
+
section: { title: '语音朗读', subtitle: 'Breeze Blue · 文字转语音' },
|
|
13
|
+
tone: { normal: '自然', warm: '温和', formal: '正式', lively: '活泼' },
|
|
14
|
+
|
|
15
|
+
err: {
|
|
16
|
+
auth: 'API key 无效或已失效,请重新填写',
|
|
17
|
+
rate: '请求太频繁,稍等几秒再试',
|
|
18
|
+
credits: '积分余额不足,请先充值或调低每日上限',
|
|
19
|
+
tooShort: '音色描述和试听台词至少要 3 个字',
|
|
20
|
+
daily: '已到今日字数上限,可在设置中调高',
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
label: {
|
|
24
|
+
voice: '音色', mood: '情绪', previewText: '试听文案', dailyLimit: '每日字数上限',
|
|
25
|
+
balance: '剩余额度', todayUsage: '今日已用', preview: '试听', save: '保存设置',
|
|
26
|
+
saving: '保存中…', synthesizing: '合成中…', refresh: '刷新', designed: '自捏',
|
|
27
|
+
readAloud: '朗读这条', replay: '重播上一条', replayEmpty: '还没有可重播的音频', saved: '已保存 ✓',
|
|
28
|
+
},
|
|
29
|
+
status: { ready: '就绪', missingKey: '缺少 API key', credits: 'credits', chars: '字' },
|
|
30
|
+
hint: { key: '把 Breeze API key 写进 ~/.dsh/breeze.json 的 apiKey 字段。', limit: '超过上限会拒绝合成,避免意外烧额度。' },
|
|
31
|
+
extra: {
|
|
32
|
+
autoSpeak: '自动朗读',
|
|
33
|
+
autoSpeakHint: '对字数不超过设定值的新回复自动朗读,默认关闭',
|
|
34
|
+
renameBlocked: '内置音色和公开音色不能重命名',
|
|
35
|
+
voiceManageHint: '只有你自己生成的音色可以在这里改名或删除',
|
|
36
|
+
apiKey: 'API Key',
|
|
37
|
+
keyBound: '已连接',
|
|
38
|
+
keyMissing: '尚未连接,填入 Breeze 的 API key 后点连接',
|
|
39
|
+
keyRequired: '请先填入 API key',
|
|
40
|
+
keyConnected: '连接成功',
|
|
41
|
+
keyDisconnected: '已断开',
|
|
42
|
+
connect: '连接',
|
|
43
|
+
disconnect: '断开',
|
|
44
|
+
cloneNotice: '本插件不提供音色克隆。需要克隆自己的声音,请到 Breeze 官网的音色库创建,克隆好的音色会自动出现在上面的列表里。',
|
|
45
|
+
renameVoice: '重命名',
|
|
46
|
+
renamePlaceholder: '新的音色名称',
|
|
47
|
+
saveName: '保存名称',
|
|
48
|
+
voiceRenamed: '已重命名 ✓',
|
|
49
|
+
voiceLoadedTag: '已加载',
|
|
50
|
+
voiceNamePlaceholder: '新音色名称',
|
|
51
|
+
addedTag: '已添加',
|
|
52
|
+
voiceAdded: '已加入音色库',
|
|
53
|
+
voiceRemoved: '已从音色库移除',
|
|
54
|
+
emotionMode: '语气模式',
|
|
55
|
+
emotionSaved: '语气模式已切换',
|
|
56
|
+
emotionFixed: '固定',
|
|
57
|
+
emotionInfer: '智能推断',
|
|
58
|
+
emotionMarker: '模型标注',
|
|
59
|
+
emotionFixedHint: '全程使用上面选中的语气朗读,不做任何切换',
|
|
60
|
+
emotionInferHint: '按标点自动切换:问号→好奇、感叹号→兴奋、省略号→失落;分段变多会拖慢生成',
|
|
61
|
+
emotionMarkerHint: '由模型在回复里插入标记,指定某一段的语气;分段变多会拖慢生成',
|
|
62
|
+
emotionMarkerNote: '模型标注为实验性功能:由模型自行标注语气,可能出现标记显形或判断偏差。',
|
|
63
|
+
publicVoices: '公开音色',
|
|
64
|
+
publicVoicesHint: '插件默认只显示你自建的音色,公共目录另外浏览',
|
|
65
|
+
openLibrary: '更多公开音色',
|
|
66
|
+
collapseLibrary: '收起音色库',
|
|
67
|
+
libraryTitle: '官方音色库',
|
|
68
|
+
librarySubtitle: '默认以自然语气试听',
|
|
69
|
+
librarySearch: '按名称或描述搜索',
|
|
70
|
+
libraryEmpty: '没有匹配的音色',
|
|
71
|
+
loadVoice: '加载',
|
|
72
|
+
voiceLoaded: '已切换音色',
|
|
73
|
+
newTone: '新建语气',
|
|
74
|
+
editTone: '编辑',
|
|
75
|
+
deleteTone: '删除',
|
|
76
|
+
saveTone: '保存语气',
|
|
77
|
+
cancel: '取消',
|
|
78
|
+
customTag: '自定义',
|
|
79
|
+
deleteVoice: '删除音色',
|
|
80
|
+
toneNamePlaceholder: '语气名称,例如:哄睡',
|
|
81
|
+
tonePlaceholder: '描述这个语气怎么说话,例如:语速很慢,声音放轻,句尾拖长,像在哄人睡觉。',
|
|
82
|
+
toneIncomplete: '名称和描述都要填',
|
|
83
|
+
toneSaved: '语气已保存 ✓',
|
|
84
|
+
toneDeleted: '语气已删除',
|
|
85
|
+
voiceDeleted: '音色已删除',
|
|
86
|
+
customMood: '自定义语气',
|
|
87
|
+
customMoodHint: '填写后优先于上面的预设;留空则使用选中语气',
|
|
88
|
+
customMoodPlaceholder: '例如:像在跟小孩子说话,句尾轻轻上扬',
|
|
89
|
+
backgroundPlay: '后台播放',
|
|
90
|
+
backgroundPlayHint: '关闭时只在 DSH 位于前台时朗读;开启后窗口切到后台也会继续播报',
|
|
91
|
+
autoMax: '自动朗读字数',
|
|
92
|
+
autoMaxWarning: '每条回复都会被完整合成;当前字数较多,生成会更慢、积分消耗也更多,建议先用较小值试几条。',
|
|
93
|
+
autoMaxHint: '可输入 0–99999,滑条范围 0–1000',
|
|
94
|
+
refreshed: '已刷新',
|
|
95
|
+
refreshFailed: '刷新失败',
|
|
96
|
+
autoMaxHard: '朗读超长文本会明显拖慢生成速度,积分消耗也难以预估,建议同时设好每日字数上限。',
|
|
97
|
+
|
|
98
|
+
autoOn: '自动朗读开',
|
|
99
|
+
designTitle: '音色设计',
|
|
100
|
+
designPlaceholder: '描述你想要的音色本身,不要写台词。建议覆盖年龄、性别、音色质地、语速和情绪基调。例如二十多岁的女性,声音清亮略带鼻音,说话轻快,句尾微微上扬,整体亲切有活力。',
|
|
101
|
+
designSample: '试听台词(可选)',
|
|
102
|
+
designCost: '每轮约 3–8 credits',
|
|
103
|
+
designHint: '生成按试听台词长度计费一次;保存后占用一个音色槽,免费档只有 5 个。',
|
|
104
|
+
generate: '生成',
|
|
105
|
+
generating: '生成中…',
|
|
106
|
+
candidate: '候选',
|
|
107
|
+
saveVoice: '保存为音色',
|
|
108
|
+
voiceSaved: '已保存为新音色',
|
|
109
|
+
newVoice: '我的音色',
|
|
110
|
+
designEmpty: '没有拿到候选,稍后再试',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
en: {
|
|
114
|
+
meta: { title: 'Breeze Voice', description: 'Read text aloud with Breeze Blue.' },
|
|
115
|
+
section: { title: 'Voice', subtitle: 'Breeze Blue · text to speech' },
|
|
116
|
+
tone: { normal: 'Natural', warm: 'Warm', formal: 'Formal', lively: 'Lively' },
|
|
117
|
+
|
|
118
|
+
err: {
|
|
119
|
+
auth: 'The API key is invalid or expired. Please enter it again.',
|
|
120
|
+
rate: 'Too many requests. Wait a few seconds and retry.',
|
|
121
|
+
credits: 'Not enough credits. Top up or lower the daily limit.',
|
|
122
|
+
tooShort: 'Voice description and preview line need at least 3 characters.',
|
|
123
|
+
daily: 'Daily character limit reached. Raise it in settings.',
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
label: {
|
|
127
|
+
voice: 'Voice', mood: 'Mood', previewText: 'Preview line', dailyLimit: 'Daily character limit',
|
|
128
|
+
balance: 'Credits left', todayUsage: 'Used today', preview: 'Preview', save: 'Save settings',
|
|
129
|
+
saving: 'Saving…', synthesizing: 'Synthesizing…', refresh: 'Refresh', designed: 'Designed',
|
|
130
|
+
readAloud: 'Read aloud', replay: 'Replay', replayEmpty: 'Nothing to replay yet', saved: 'Saved ✓',
|
|
131
|
+
},
|
|
132
|
+
status: { ready: 'Ready', missingKey: 'Missing API key', credits: 'credits', chars: 'chars' },
|
|
133
|
+
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.' },
|
|
134
|
+
extra: {
|
|
135
|
+
apiKey: 'API key',
|
|
136
|
+
keyBound: 'Connected',
|
|
137
|
+
keyMissing: 'Not connected. Paste your Breeze API key and press Connect.',
|
|
138
|
+
keyRequired: 'Enter an API key first',
|
|
139
|
+
keyConnected: 'Connected',
|
|
140
|
+
keyDisconnected: 'Disconnected',
|
|
141
|
+
connect: 'Connect',
|
|
142
|
+
disconnect: 'Disconnect',
|
|
143
|
+
autoSpeak: 'Auto speak',
|
|
144
|
+
autoSpeakHint: 'Automatically read new replies within the configured character limit. Off by default.',
|
|
145
|
+
renameBlocked: 'Built-in and public voices cannot be renamed',
|
|
146
|
+
voiceManageHint: 'Only voices you created can be renamed or deleted here',
|
|
147
|
+
cloneNotice: 'Voice cloning is not part of this plugin. Create a clone on the Breeze website and it will show up in the list above.',
|
|
148
|
+
renameVoice: 'Rename',
|
|
149
|
+
renamePlaceholder: 'New voice name',
|
|
150
|
+
saveName: 'Save name',
|
|
151
|
+
voiceRenamed: 'Renamed',
|
|
152
|
+
voiceLoadedTag: 'Loaded',
|
|
153
|
+
voiceNamePlaceholder: 'New voice name',
|
|
154
|
+
addedTag: 'added',
|
|
155
|
+
voiceAdded: 'Added to your voices',
|
|
156
|
+
voiceRemoved: 'Removed from your voices',
|
|
157
|
+
emotionMode: 'Tone mode',
|
|
158
|
+
emotionSaved: 'Tone mode switched',
|
|
159
|
+
emotionFixed: 'Fixed',
|
|
160
|
+
emotionInfer: 'Infer',
|
|
161
|
+
emotionMarker: 'Model tagged',
|
|
162
|
+
emotionFixedHint: 'Speak everything with the tone selected above, no switching',
|
|
163
|
+
emotionInferHint: 'Switch by punctuation: question → curious, exclamation → excited, ellipsis → sad; more segments means slower synthesis',
|
|
164
|
+
emotionMarkerHint: 'The model inserts markers to pick the tone per segment; more segments means slower synthesis',
|
|
165
|
+
emotionMarkerNote: 'Model tagging is experimental: the model tags its own tone. Markers may appear in the text or be misjudged.',
|
|
166
|
+
publicVoices: 'Public voices',
|
|
167
|
+
publicVoicesHint: 'Only your own voices are listed by default; the public catalog is browsed separately',
|
|
168
|
+
openLibrary: 'Browse public voices',
|
|
169
|
+
collapseLibrary: 'Collapse library',
|
|
170
|
+
libraryTitle: 'Public voice library',
|
|
171
|
+
librarySubtitle: 'Previews use the natural tone',
|
|
172
|
+
librarySearch: 'Search by name or description',
|
|
173
|
+
libraryEmpty: 'No matching voices',
|
|
174
|
+
loadVoice: 'Load',
|
|
175
|
+
voiceLoaded: 'Voice switched',
|
|
176
|
+
newTone: 'New tone',
|
|
177
|
+
editTone: 'Edit',
|
|
178
|
+
deleteTone: 'Delete',
|
|
179
|
+
saveTone: 'Save tone',
|
|
180
|
+
cancel: 'Cancel',
|
|
181
|
+
customTag: 'custom',
|
|
182
|
+
deleteVoice: 'Delete voice',
|
|
183
|
+
toneNamePlaceholder: 'Tone name, e.g. bedtime',
|
|
184
|
+
tonePlaceholder: 'Describe how it should sound, e.g. very slow and soft, with a trailing lilt.',
|
|
185
|
+
toneIncomplete: 'Both name and description are required',
|
|
186
|
+
toneSaved: 'Tone saved',
|
|
187
|
+
toneDeleted: 'Tone deleted',
|
|
188
|
+
voiceDeleted: 'Voice deleted',
|
|
189
|
+
customMood: 'Custom tone',
|
|
190
|
+
customMoodHint: 'Overrides the preset above when filled; leave empty to use the selected tone',
|
|
191
|
+
customMoodPlaceholder: 'e.g. speak to a small child, with a light upward lilt',
|
|
192
|
+
backgroundPlay: 'Play in background',
|
|
193
|
+
backgroundPlayHint: 'Off: only speak while DSH is in the foreground. On: keep speaking when the window is in the background.',
|
|
194
|
+
autoMax: 'Auto speak up to',
|
|
195
|
+
autoMaxWarning: 'Every reply is synthesized in full; with this many characters synthesis gets slower and costs more credits. Try a smaller value first.',
|
|
196
|
+
autoMaxHint: '0-99999 allowed, slider covers 0-1000',
|
|
197
|
+
refreshed: 'Refreshed',
|
|
198
|
+
refreshFailed: 'Refresh failed',
|
|
199
|
+
autoMaxHard: 'Very long replies slow synthesis down and make credit use unpredictable. Set a daily limit alongside it.',
|
|
200
|
+
|
|
201
|
+
autoOn: 'auto on',
|
|
202
|
+
designTitle: 'Voice design',
|
|
203
|
+
designPlaceholder: 'Describe the voice itself, not a script: age and gender, texture, pace, emotional baseline. Example: a woman in her twenties, bright voice with a light nasal tone, quick and upbeat.',
|
|
204
|
+
designSample: 'Preview line (optional)',
|
|
205
|
+
designCost: 'about 3-8 credits per run',
|
|
206
|
+
designHint: 'Generation is billed once by the preview line length; saving a voice uses one voice slot (the free plan has 5).',
|
|
207
|
+
generate: 'Generate',
|
|
208
|
+
generating: 'Generating…',
|
|
209
|
+
candidate: 'Candidate',
|
|
210
|
+
saveVoice: 'Save voice',
|
|
211
|
+
voiceSaved: 'Saved as a new voice',
|
|
212
|
+
newVoice: 'My voice',
|
|
213
|
+
designEmpty: 'No candidates came back, try again later',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function lookup(dict, key) {
|
|
219
|
+
let current = dict
|
|
220
|
+
for (const part of key.split('.')) {
|
|
221
|
+
if (current && typeof current === 'object' && part in current) current = current[part]
|
|
222
|
+
else return key
|
|
223
|
+
}
|
|
224
|
+
return typeof current === 'string' ? current : key
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function flatten(dict, prefix, out) {
|
|
228
|
+
const target = out || {}
|
|
229
|
+
for (const key of Object.keys(dict)) {
|
|
230
|
+
const value = dict[key]
|
|
231
|
+
const next = prefix ? prefix + '.' + key : key
|
|
232
|
+
if (value && typeof value === 'object') flatten(value, next, target)
|
|
233
|
+
else target[next] = value
|
|
234
|
+
}
|
|
235
|
+
return target
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const FLAT = { zh: flatten(DICT.zh), en: flatten(DICT.en) }
|
|
239
|
+
|
|
240
|
+
const COLOR = {
|
|
241
|
+
primary: 'var(--dsw-alias-label-primary)',
|
|
242
|
+
secondary: 'var(--dsw-alias-label-secondary)',
|
|
243
|
+
border: 'var(--dsw-alias-border-l1)',
|
|
244
|
+
borderStrong: 'var(--dsw-alias-border-l2)',
|
|
245
|
+
surface: 'var(--dsw-alias-bg-layer-1)',
|
|
246
|
+
nested: 'var(--dsw-alias-bg-layer-2)',
|
|
247
|
+
brand: 'var(--dsw-alias-brand-primary)',
|
|
248
|
+
error: 'var(--dsw-alias-state-error-primary)',
|
|
249
|
+
success: 'var(--dsw-alias-state-success-primary)',
|
|
250
|
+
idle: 'var(--dsw-alias-state-idle-primary)',
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function api(route, options) {
|
|
254
|
+
const response = await fetch(ENDPOINT + route, options)
|
|
255
|
+
const type = response.headers.get('content-type') || ''
|
|
256
|
+
if (type.includes('application/json')) {
|
|
257
|
+
const data = await response.json()
|
|
258
|
+
if (!response.ok) {
|
|
259
|
+
const failure = new Error(data.error || `HTTP ${response.status}`)
|
|
260
|
+
failure.code = data.code || ''
|
|
261
|
+
failure.status = data.status || response.status
|
|
262
|
+
throw failure
|
|
263
|
+
}
|
|
264
|
+
return data
|
|
265
|
+
}
|
|
266
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
267
|
+
return response.blob()
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function humanError(t, error) {
|
|
271
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
272
|
+
const code = error && error.code ? String(error.code) : ''
|
|
273
|
+
const status = error && error.status ? Number(error.status) : 0
|
|
274
|
+
if (status === 401 || code === 'AUTH_REQUIRED') return t('err.auth')
|
|
275
|
+
if (status === 429) return t('err.rate')
|
|
276
|
+
if (status === 402 || /credit/i.test(code) || /insufficient/i.test(message)) return t('err.credits')
|
|
277
|
+
if (/at least 3 characters/i.test(message)) return t('err.tooShort')
|
|
278
|
+
if (/daily limit/i.test(message)) return t('err.daily')
|
|
279
|
+
return message
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
let currentAudio = null
|
|
283
|
+
|
|
284
|
+
function playUrl(url) {
|
|
285
|
+
return new Promise((resolve, reject) => {
|
|
286
|
+
const audio = new Audio(url)
|
|
287
|
+
currentAudio = audio
|
|
288
|
+
audio.onerror = () => reject(new Error('audio element failed'))
|
|
289
|
+
const started = audio.play()
|
|
290
|
+
if (started && typeof started.then === 'function') started.then(() => resolve(true), reject)
|
|
291
|
+
else resolve(true)
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async function speakRemotely(payload, options) {
|
|
296
|
+
const data = await api('/synth', {
|
|
297
|
+
method: 'POST',
|
|
298
|
+
headers: { 'content-type': 'application/json' },
|
|
299
|
+
body: JSON.stringify(payload),
|
|
300
|
+
})
|
|
301
|
+
const playOnHost = async () => {
|
|
302
|
+
await api('/play-file', {
|
|
303
|
+
method: 'POST',
|
|
304
|
+
headers: { 'content-type': 'application/json' },
|
|
305
|
+
body: JSON.stringify({ url: data.url }),
|
|
306
|
+
})
|
|
307
|
+
}
|
|
308
|
+
if (options && options.host) {
|
|
309
|
+
await playOnHost()
|
|
310
|
+
return data
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
await playUrl(data.url)
|
|
314
|
+
} catch (error) {
|
|
315
|
+
console.error('[breeze-tts] html audio failed, using host playback', error)
|
|
316
|
+
await playOnHost()
|
|
317
|
+
}
|
|
318
|
+
return data
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function PlayGlyph(size) {
|
|
322
|
+
const s = size || 11
|
|
323
|
+
return h("svg", {
|
|
324
|
+
width: s, height: s, viewBox: "0 0 12 12", "aria-hidden": true, style: { display: "block", shapeRendering: "geometricPrecision" },
|
|
325
|
+
}, h("path", { d: "M2.4 1.2 10.6 6 2.4 10.8z", fill: "currentColor" }))
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function PlayTriangle(size) {
|
|
329
|
+
const s = size || 12
|
|
330
|
+
return h('svg', {
|
|
331
|
+
width: s, height: s, viewBox: '0 0 12 12', 'aria-hidden': true, style: { display: 'block', shapeRendering: 'geometricPrecision' },
|
|
332
|
+
}, h('path', { d: 'M3.4 2.1 9.6 6 3.4 9.9z', fill: 'currentColor' }))
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async function playBlob(blob) {
|
|
336
|
+
const Ctx = window.AudioContext || window.webkitAudioContext
|
|
337
|
+
if (!Ctx) throw new Error('AudioContext unavailable')
|
|
338
|
+
const context = new Ctx()
|
|
339
|
+
try {
|
|
340
|
+
if (context.state === 'suspended') await context.resume()
|
|
341
|
+
} catch {
|
|
342
|
+
/* resume best effort */
|
|
343
|
+
}
|
|
344
|
+
const buffer = await context.decodeAudioData(await blob.arrayBuffer())
|
|
345
|
+
const source = context.createBufferSource()
|
|
346
|
+
source.buffer = buffer
|
|
347
|
+
source.connect(context.destination)
|
|
348
|
+
await new Promise((resolve, reject) => {
|
|
349
|
+
source.onended = () => {
|
|
350
|
+
context.close().catch(() => {})
|
|
351
|
+
resolve(true)
|
|
352
|
+
}
|
|
353
|
+
try {
|
|
354
|
+
source.start()
|
|
355
|
+
} catch (error) {
|
|
356
|
+
reject(error)
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
return true
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function SpeakerIcon(size) {
|
|
363
|
+
const s = size || 14
|
|
364
|
+
return h('svg', {
|
|
365
|
+
width: s, height: s, viewBox: '0 0 16 16', fill: 'none',
|
|
366
|
+
stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round',
|
|
367
|
+
strokeLinejoin: 'round', 'aria-hidden': true, style: { display: 'block', shapeRendering: 'geometricPrecision' },
|
|
368
|
+
},
|
|
369
|
+
h('path', { d: 'M8 2.5 4.5 5.5H2v5h2.5L8 13.5z' }),
|
|
370
|
+
h('path', { d: 'M11 5.5a3.5 3.5 0 0 1 0 5' }),
|
|
371
|
+
h('path', { d: 'M13 3.5a6 6 0 0 1 0 9' }))
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function Spinner(size) {
|
|
375
|
+
const s = size || 14
|
|
376
|
+
return h("svg", {
|
|
377
|
+
width: s, height: s, viewBox: "0 0 16 16", "aria-hidden": true, style: { display: "block", shapeRendering: "geometricPrecision" },
|
|
378
|
+
},
|
|
379
|
+
h("circle", {
|
|
380
|
+
cx: 8, cy: 8, r: 6, fill: "none", stroke: "currentColor",
|
|
381
|
+
strokeWidth: 1.7, strokeLinecap: "round", strokeDasharray: "9 29",
|
|
382
|
+
}, h("animateTransform", {
|
|
383
|
+
attributeName: "transform", type: "rotate", from: "0 8 8", to: "360 8 8",
|
|
384
|
+
dur: "0.9s", repeatCount: "indefinite",
|
|
385
|
+
})))
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function StyleSheet() {
|
|
389
|
+
return h('style', null,
|
|
390
|
+
'@keyframes dsh-breeze-spin{to{transform:rotate(360deg)}}',
|
|
391
|
+
'.dsh-breeze-row{display:flex;align-items:center;gap:12px;padding:10px 0;border-top:1px solid ' + COLOR.border + '}',
|
|
392
|
+
'.dsh-breeze-row:first-of-type{border-top:0}',
|
|
393
|
+
'.dsh-breeze-key{flex:0 0 132px;font-size:13px;color:' + COLOR.secondary + '}',
|
|
394
|
+
'.dsh-breeze-value{flex:1;min-width:0;display:flex;align-items:center;gap:8px;flex-wrap:wrap}',
|
|
395
|
+
'.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}',
|
|
396
|
+
'.dsh-breeze-control:focus-visible{outline:2px solid ' + COLOR.brand + ';outline-offset:1px}',
|
|
397
|
+
'.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}',
|
|
398
|
+
'.dsh-breeze-chip:hover{background:color-mix(in srgb,' + COLOR.primary + ' 16%,transparent)}',
|
|
399
|
+
'.dsh-breeze-chip[data-on="true"]{color:' + COLOR.brand + ';background:color-mix(in srgb,' + COLOR.brand + ' 16%,' + COLOR.nested + ')}',
|
|
400
|
+
'.dsh-breeze-btn{display:inline-flex;align-items:center;gap:6px;font:inherit;font-size:13px;height:30px;padding:0 12px;border-radius:8px;cursor:pointer;border:0;background:color-mix(in srgb,' + COLOR.primary + ' 9%,transparent);color:' + COLOR.primary + ';background-clip:padding-box}',
|
|
401
|
+
'.dsh-breeze-btn:hover{background:color-mix(in srgb,' + COLOR.primary + ' 16%,transparent)}',
|
|
402
|
+
'.dsh-breeze-btn:active{background:color-mix(in srgb,' + COLOR.primary + ' 22%,transparent)}',
|
|
403
|
+
'.dsh-breeze-btn[data-primary="true"]{background:' + COLOR.brand + ';border-color:' + COLOR.brand + ';color:#fff}',
|
|
404
|
+
'.dsh-breeze-btn:disabled{opacity:.55;cursor:default}',
|
|
405
|
+
'.dsh-breeze-play{display:inline-flex;align-items:center;gap:9px;font:inherit;font-size:13px;font-weight:500;height:34px;padding:0 18px 0 15px;border-radius:10px;cursor:pointer;border:0;background:' + COLOR.primary + ';color:' + COLOR.surface + ';background-clip:padding-box}',
|
|
406
|
+
'.dsh-breeze-play:hover{background:color-mix(in srgb,' + COLOR.primary + ' 86%,' + COLOR.surface + ')}',
|
|
407
|
+
'.dsh-breeze-play:disabled{opacity:.6;cursor:default}',
|
|
408
|
+
'.dsh-breeze-switch{position:relative;width:40px;height:22px;border-radius:999px;border:0;background:color-mix(in srgb,' + COLOR.primary + ' 18%,transparent);cursor:pointer;padding:0;flex:0 0 auto}',
|
|
409
|
+
'.dsh-breeze-switch[data-on="true"]{background:' + COLOR.brand + '}',
|
|
410
|
+
'.dsh-breeze-knob{position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:999px;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.25);transition:left .15s ease}',
|
|
411
|
+
'.dsh-breeze-switch[data-on="true"] .dsh-breeze-knob{left:20px}',
|
|
412
|
+
'.dsh-breeze-hint{margin:2px 0 0;font-size:12px;line-height:18px;color:' + COLOR.secondary + '}')
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function useStatus() {
|
|
416
|
+
const [state, setState] = React.useState({ loading: true, data: null, error: null })
|
|
417
|
+
const load = React.useCallback(async (rethrow) => {
|
|
418
|
+
try {
|
|
419
|
+
const data = await api('/status')
|
|
420
|
+
setState({ loading: false, data, error: null })
|
|
421
|
+
return data
|
|
422
|
+
} catch (error) {
|
|
423
|
+
setState({ loading: false, data: null, error: error instanceof Error ? error.message : String(error) })
|
|
424
|
+
if (rethrow) throw error
|
|
425
|
+
return null
|
|
426
|
+
}
|
|
427
|
+
}, [])
|
|
428
|
+
React.useEffect(() => { load() }, [load])
|
|
429
|
+
return [state, load]
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const SKIP_TYPES = ["reasoning", "thinking", "reasoning-delta", "thinking-delta", "redacted-thinking"]
|
|
433
|
+
|
|
434
|
+
function collectText(node, out, depth) {
|
|
435
|
+
if (!node || depth > 7) return out
|
|
436
|
+
if (typeof node !== "object") return out
|
|
437
|
+
if (Array.isArray(node)) {
|
|
438
|
+
for (const item of node) collectText(item, out, depth + 1)
|
|
439
|
+
return out
|
|
440
|
+
}
|
|
441
|
+
const type = typeof node.type === "string" ? node.type : (typeof node.kind === "string" ? node.kind : "")
|
|
442
|
+
if (SKIP_TYPES.includes(type)) return out
|
|
443
|
+
if (type === "text" && typeof node.text === "string" && node.text.trim()) {
|
|
444
|
+
out.push(node.text.trim())
|
|
445
|
+
return out
|
|
446
|
+
}
|
|
447
|
+
for (const key of ["content", "message", "blocks", "parts"]) {
|
|
448
|
+
if (node[key]) collectText(node[key], out, depth + 1)
|
|
449
|
+
}
|
|
450
|
+
return out
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function collectAnyText(node, out, depth) {
|
|
454
|
+
if (!node || depth > 6 || typeof node !== "object") return out
|
|
455
|
+
if (Array.isArray(node)) {
|
|
456
|
+
for (const item of node) collectAnyText(item, out, depth + 1)
|
|
457
|
+
return out
|
|
458
|
+
}
|
|
459
|
+
const type = typeof node.type === "string" ? node.type : (typeof node.kind === "string" ? node.kind : "")
|
|
460
|
+
if (SKIP_TYPES.includes(type)) return out
|
|
461
|
+
if (typeof node.text === "string" && node.text.trim()) out.push(node.text.trim())
|
|
462
|
+
for (const key of ["content", "message", "blocks", "parts"]) {
|
|
463
|
+
if (node[key]) collectAnyText(node[key], out, depth + 1)
|
|
464
|
+
}
|
|
465
|
+
return out
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function stripEmoji(text) {
|
|
469
|
+
let out = ''
|
|
470
|
+
for (const ch of String(text ?? '')) {
|
|
471
|
+
const cp = ch.codePointAt(0)
|
|
472
|
+
if (cp >= 0x1f000 && cp <= 0x1faff) continue
|
|
473
|
+
if (cp >= 0x2600 && cp <= 0x27bf) continue
|
|
474
|
+
if (cp === 0xfe0f || cp === 0x200d || cp === 0x2b50) continue
|
|
475
|
+
out += ch
|
|
476
|
+
}
|
|
477
|
+
return out
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function cleanForSpeech(text) {
|
|
481
|
+
let value = String(text ?? '')
|
|
482
|
+
value = value.replace(/<!--[\s\S]*?-->/g, ' ')
|
|
483
|
+
value = value.replace(/!\[[^\]]*\]\([^)]*\)/g, ' ')
|
|
484
|
+
value = value.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
485
|
+
value = value.replace(/https?:\/\/[^\s)]+/g, ' ')
|
|
486
|
+
value = value.replace(/`{1,3}[^`]*`{1,3}/g, ' ')
|
|
487
|
+
value = value.replace(/[*_~#>|]+/g, ' ')
|
|
488
|
+
value = stripEmoji(value)
|
|
489
|
+
value = value.replace(/\s+([:,。!?;、)】」》])/g, '$1')
|
|
490
|
+
value = value.replace(/([(【「《])\s+/g, '$1')
|
|
491
|
+
value = value.replace(/\s+/g, ' ')
|
|
492
|
+
return value.trim()
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function textBlocks(blocks, out) {
|
|
496
|
+
for (const block of Array.isArray(blocks) ? blocks : []) {
|
|
497
|
+
if (!block || typeof block !== "object") continue
|
|
498
|
+
const type = typeof block.type === "string" ? block.type : (typeof block.kind === "string" ? block.kind : "")
|
|
499
|
+
if (SKIP_TYPES.includes(type)) continue
|
|
500
|
+
if (type === "text" && typeof block.text === "string" && block.text.trim()) out.push(block.text.trim())
|
|
501
|
+
}
|
|
502
|
+
return out
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function pickText(snapshot, messageId) {
|
|
506
|
+
const nodes = snapshot && Array.isArray(snapshot.nodes) ? snapshot.nodes : []
|
|
507
|
+
const target = nodes.find((node) => node && (
|
|
508
|
+
node.id === messageId
|
|
509
|
+
|| node.messageId === messageId
|
|
510
|
+
|| (node.message && node.message.id === messageId)
|
|
511
|
+
))
|
|
512
|
+
if (!target) return ""
|
|
513
|
+
const message = target.message && typeof target.message === "object" ? target.message : target
|
|
514
|
+
const direct = textBlocks(message.content, [])
|
|
515
|
+
if (direct.length) return cleanForSpeech(direct.join(String.fromCharCode(10)))
|
|
516
|
+
const typed = collectText(message, [], 0).join(String.fromCharCode(10)).trim()
|
|
517
|
+
if (typed) return typed
|
|
518
|
+
return collectAnyText(message, [], 0).join(String.fromCharCode(10)).trim()
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function SpeakButton(props) {
|
|
522
|
+
const [phase, setPhase] = React.useState('idle')
|
|
523
|
+
const [fail, setFail] = React.useState('')
|
|
524
|
+
const snapshot = typeof props.useChat === 'function'
|
|
525
|
+
? props.useChat((state) => (state && typeof state === 'object' ? state.legacy : undefined))
|
|
526
|
+
: undefined
|
|
527
|
+
const text = React.useMemo(() => {
|
|
528
|
+
try {
|
|
529
|
+
return pickText(snapshot, props.messageId)
|
|
530
|
+
} catch {
|
|
531
|
+
return ''
|
|
532
|
+
}
|
|
533
|
+
}, [snapshot, props.messageId])
|
|
534
|
+
if (!text) return null
|
|
535
|
+
const speak = async () => {
|
|
536
|
+
setPhase('busy')
|
|
537
|
+
try {
|
|
538
|
+
const data = await speakRemotely({ text: text.slice(0, 600) })
|
|
539
|
+
setPhase('playing')
|
|
540
|
+
const wait = Math.max(1200, Number(data.chars || 0) * 260)
|
|
541
|
+
window.setTimeout(() => setPhase('idle'), wait)
|
|
542
|
+
} catch (error) {
|
|
543
|
+
setPhase('error')
|
|
544
|
+
setFail(error instanceof Error ? error.message : String(error))
|
|
545
|
+
console.error('[breeze-tts] play failed', error)
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return h('button', {
|
|
549
|
+
type: 'button',
|
|
550
|
+
title: phase === 'error' && fail ? fail : props.t('label.readAloud'),
|
|
551
|
+
'aria-label': props.t('label.readAloud'),
|
|
552
|
+
onClick: speak,
|
|
553
|
+
disabled: phase === 'busy',
|
|
554
|
+
style: {
|
|
555
|
+
display: 'inline-flex', alignItems: 'center', gap: 5, font: 'inherit', fontSize: 12,
|
|
556
|
+
height: 26, padding: '0 9px', borderRadius: 999, cursor: 'pointer',
|
|
557
|
+
border: 'none', background: 'color-mix(in srgb, ' + COLOR.primary + ' 9%, transparent)',
|
|
558
|
+
color: phase === 'error' ? COLOR.error : COLOR.secondary,
|
|
559
|
+
},
|
|
560
|
+
}, phase === 'busy' ? Spinner() : SpeakerIcon(13), h('span', null, props.t('label.readAloud')))
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function AutoSpeakChip(props) {
|
|
564
|
+
const t = props.t
|
|
565
|
+
const [state] = useStatus()
|
|
566
|
+
const played = React.useRef(null)
|
|
567
|
+
if (!played.current) {
|
|
568
|
+
const key = 'breeze-tts:spoken:' + (props.sessionId || 'global')
|
|
569
|
+
let stored = null
|
|
570
|
+
try {
|
|
571
|
+
stored = JSON.parse(window.localStorage.getItem(key) || 'null')
|
|
572
|
+
} catch {
|
|
573
|
+
stored = null
|
|
574
|
+
}
|
|
575
|
+
played.current = {
|
|
576
|
+
key,
|
|
577
|
+
ids: new Set(Array.isArray(stored) ? stored : []),
|
|
578
|
+
texts: new Map(),
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const markSpoken = (id, text) => {
|
|
582
|
+
played.current.ids.add(id)
|
|
583
|
+
if (text) played.current.texts.set(text.slice(0, 80), Date.now())
|
|
584
|
+
try {
|
|
585
|
+
const list = Array.from(played.current.ids).slice(-400)
|
|
586
|
+
window.localStorage.setItem(played.current.key, JSON.stringify(list))
|
|
587
|
+
} catch {
|
|
588
|
+
/* storage full or disabled */
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const primed = React.useRef(false)
|
|
592
|
+
const debounce = React.useRef(null)
|
|
593
|
+
const focused = React.useRef(true)
|
|
594
|
+
const snapshot = typeof props.useChat === 'function'
|
|
595
|
+
? props.useChat((value) => (value && typeof value === 'object' ? value.legacy : undefined))
|
|
596
|
+
: undefined
|
|
597
|
+
|
|
598
|
+
React.useEffect(() => {
|
|
599
|
+
const markFocused = () => {
|
|
600
|
+
focused.current = true
|
|
601
|
+
}
|
|
602
|
+
const markBlurred = () => {
|
|
603
|
+
focused.current = false
|
|
604
|
+
}
|
|
605
|
+
const onVisibility = () => {
|
|
606
|
+
if (document.visibilityState === 'hidden') markBlurred()
|
|
607
|
+
else markFocused()
|
|
608
|
+
}
|
|
609
|
+
window.addEventListener('focus', markFocused)
|
|
610
|
+
window.addEventListener('pointerdown', markFocused, true)
|
|
611
|
+
window.addEventListener('keydown', markFocused, true)
|
|
612
|
+
window.addEventListener('blur', markBlurred)
|
|
613
|
+
document.addEventListener('visibilitychange', onVisibility)
|
|
614
|
+
return () => {
|
|
615
|
+
window.removeEventListener('focus', markFocused)
|
|
616
|
+
window.removeEventListener('pointerdown', markFocused, true)
|
|
617
|
+
window.removeEventListener('keydown', markFocused, true)
|
|
618
|
+
window.removeEventListener('blur', markBlurred)
|
|
619
|
+
document.removeEventListener('visibilitychange', onVisibility)
|
|
620
|
+
}
|
|
621
|
+
}, [])
|
|
622
|
+
|
|
623
|
+
React.useEffect(() => {
|
|
624
|
+
const nodes = snapshot && Array.isArray(snapshot.nodes) ? snapshot.nodes : []
|
|
625
|
+
if (!snapshot) return
|
|
626
|
+
|
|
627
|
+
if (!primed.current) {
|
|
628
|
+
primed.current = true
|
|
629
|
+
for (const node of nodes) {
|
|
630
|
+
const id = node && (node.id || node.messageId || (node.message && node.message.id))
|
|
631
|
+
if (id) markSpoken(id, '')
|
|
632
|
+
}
|
|
633
|
+
return
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (debounce.current) window.clearTimeout(debounce.current)
|
|
637
|
+
debounce.current = window.setTimeout(evaluate, 600)
|
|
638
|
+
return
|
|
639
|
+
|
|
640
|
+
function evaluate() {
|
|
641
|
+
let text = ''
|
|
642
|
+
let id = ''
|
|
643
|
+
for (let index = nodes.length - 1; index >= 0; index -= 1) {
|
|
644
|
+
const node = nodes[index]
|
|
645
|
+
if (!node || typeof node !== 'object') continue
|
|
646
|
+
if (String(node.kind || '') !== 'assistant') continue
|
|
647
|
+
const candidateId = node.id || node.messageId || (node.message && node.message.id) || ''
|
|
648
|
+
if (!candidateId || played.current.ids.has(candidateId)) continue
|
|
649
|
+
let raw = ''
|
|
650
|
+
try {
|
|
651
|
+
raw = collectText(node, [], 0).join(' ')
|
|
652
|
+
if (!raw) raw = collectAnyText(node, [], 0).join(' ')
|
|
653
|
+
} catch {
|
|
654
|
+
raw = ''
|
|
655
|
+
}
|
|
656
|
+
const cleaned = cleanForSpeech(raw)
|
|
657
|
+
if (!cleaned) continue
|
|
658
|
+
const recent = played.current.texts.get(cleaned.slice(0, 80))
|
|
659
|
+
if (recent && Date.now() - recent < 60000) {
|
|
660
|
+
markSpoken(candidateId, '')
|
|
661
|
+
continue
|
|
662
|
+
}
|
|
663
|
+
text = cleaned
|
|
664
|
+
id = candidateId
|
|
665
|
+
break
|
|
666
|
+
}
|
|
667
|
+
if (!id) {
|
|
668
|
+
const last = nodes[nodes.length - 1]
|
|
669
|
+
const shape = last && typeof last === 'object' ? Object.keys(last).slice(0, 10).join(',') : 'none'
|
|
670
|
+
const kind = last && typeof last === 'object' ? String(last.kind || last.type || '?') : '?'
|
|
671
|
+
const blocks = last && Array.isArray(last.blocks) ? last.blocks : []
|
|
672
|
+
const probe = blocks[0] && typeof blocks[0] === 'object'
|
|
673
|
+
? Object.keys(blocks[0]).slice(0, 8).join(',') + '|type=' + String(blocks[0].type || blocks[0].kind || '?')
|
|
674
|
+
: 'none'
|
|
675
|
+
return
|
|
676
|
+
}
|
|
677
|
+
markSpoken(id, text)
|
|
678
|
+
|
|
679
|
+
api('/status')
|
|
680
|
+
.then((data) => {
|
|
681
|
+
const limit = Number((data && data.autoSpeakMaxChars) || 0)
|
|
682
|
+
if (!data || !data.autoSpeak) return null
|
|
683
|
+
if (limit <= 0) return null
|
|
684
|
+
if (text.length > limit) return null
|
|
685
|
+
if (!data.backgroundPlay && !focused.current) return null
|
|
686
|
+
return speakRemotely({ text }, { host: true })
|
|
687
|
+
})
|
|
688
|
+
.catch(() => {})
|
|
689
|
+
}
|
|
690
|
+
}, [snapshot])
|
|
691
|
+
|
|
692
|
+
const data = state.data
|
|
693
|
+
if (!data) return null
|
|
694
|
+
const used = data.today ? data.today.chars : 0
|
|
695
|
+
const limit = data.today ? data.today.limit : 0
|
|
696
|
+
const tone = data.ok ? COLOR.success : COLOR.error
|
|
697
|
+
const enabled = Boolean(data.autoSpeak)
|
|
698
|
+
const label = data.ok
|
|
699
|
+
? `${used} / ${limit} ${t('status.chars')}${enabled ? ' · ' + t('extra.autoOn') : ''}`
|
|
700
|
+
: t('status.missingKey')
|
|
701
|
+
|
|
702
|
+
return h('div', {
|
|
703
|
+
style: {
|
|
704
|
+
display: 'flex', alignItems: 'center', gap: 6, padding: '2px 2px 0',
|
|
705
|
+
fontSize: 11, lineHeight: '16px', color: COLOR.secondary,
|
|
706
|
+
},
|
|
707
|
+
},
|
|
708
|
+
h('span', { style: { width: 6, height: 6, borderRadius: 999, background: tone, flex: '0 0 auto' } }),
|
|
709
|
+
h('span', null, label))
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function SettingsPage(props) {
|
|
713
|
+
const t = props.t
|
|
714
|
+
const [state, reload] = useStatus()
|
|
715
|
+
const [voices, setVoices] = React.useState([])
|
|
716
|
+
const [voiceId, setVoiceId] = React.useState('')
|
|
717
|
+
const [moodId, setMoodId] = React.useState('normal')
|
|
718
|
+
const [emotionMode, setEmotionMode] = React.useState('fixed')
|
|
719
|
+
const [tones, setTones] = React.useState([])
|
|
720
|
+
const [savedVoices, setSavedVoices] = React.useState([])
|
|
721
|
+
const [voiceRenameOpen, setVoiceRenameOpen] = React.useState(false)
|
|
722
|
+
const [voiceNameDraft, setVoiceNameDraft] = React.useState('')
|
|
723
|
+
const [designName, setDesignName] = React.useState('')
|
|
724
|
+
const [apiKeyInput, setApiKeyInput] = React.useState('')
|
|
725
|
+
const [connectNote, setConnectNote] = React.useState(null)
|
|
726
|
+
const [voiceNames, setVoiceNames] = React.useState({})
|
|
727
|
+
const [libraryOpen, setLibraryOpen] = React.useState(false)
|
|
728
|
+
const [libraryQuery, setLibraryQuery] = React.useState('')
|
|
729
|
+
const [toneEditor, setToneEditor] = React.useState(false)
|
|
730
|
+
const [toneEditId, setToneEditId] = React.useState('')
|
|
731
|
+
const [toneDraftName, setToneDraftName] = React.useState('')
|
|
732
|
+
const [toneDraftText, setToneDraftText] = React.useState('')
|
|
733
|
+
const [previewText, setPreviewText] = React.useState('')
|
|
734
|
+
const [dailyChars, setDailyChars] = React.useState(1500)
|
|
735
|
+
const [autoSpeak, setAutoSpeak] = React.useState(false)
|
|
736
|
+
const [autoMax, setAutoMax] = React.useState(120)
|
|
737
|
+
const [backgroundPlay, setBackgroundPlay] = React.useState(false)
|
|
738
|
+
const [customMood, setCustomMood] = React.useState('')
|
|
739
|
+
const [designDesc, setDesignDesc] = React.useState('')
|
|
740
|
+
const [designText, setDesignText] = React.useState('')
|
|
741
|
+
const [candidates, setCandidates] = React.useState([])
|
|
742
|
+
const [phase, setPhase] = React.useState('idle')
|
|
743
|
+
const [notice, setNotice] = React.useState('')
|
|
744
|
+
const [refreshNote, setRefreshNote] = React.useState({ text: '', tone: 'muted' })
|
|
745
|
+
|
|
746
|
+
React.useEffect(() => {
|
|
747
|
+
const data = state.data
|
|
748
|
+
if (!data) return
|
|
749
|
+
setVoiceId(data.voiceId || '')
|
|
750
|
+
setMoodId(data.moodId || 'normal')
|
|
751
|
+
setEmotionMode(data.emotionMode || 'fixed')
|
|
752
|
+
setTones(Array.isArray(data.tones) ? data.tones : [])
|
|
753
|
+
setSavedVoices(Array.isArray(data.savedVoices) ? data.savedVoices : [])
|
|
754
|
+
setPreviewText(data.previewText || '')
|
|
755
|
+
setDailyChars(data.today ? data.today.limit : 1500)
|
|
756
|
+
setAutoSpeak(Boolean(data.autoSpeak))
|
|
757
|
+
setAutoMax(Number(data.autoSpeakMaxChars || 120))
|
|
758
|
+
setBackgroundPlay(Boolean(data.backgroundPlay))
|
|
759
|
+
setCustomMood(String(data.customMood || ''))
|
|
760
|
+
}, [state.data])
|
|
761
|
+
|
|
762
|
+
React.useEffect(() => {
|
|
763
|
+
let alive = true
|
|
764
|
+
api('/voices')
|
|
765
|
+
.then((data) => { if (alive) setVoices(data.voices || []) })
|
|
766
|
+
.catch(() => { if (alive) setVoices([]) })
|
|
767
|
+
return () => { alive = false }
|
|
768
|
+
}, [])
|
|
769
|
+
|
|
770
|
+
const data = state.data
|
|
771
|
+
const presets = data && Array.isArray(data.voicePresets) ? data.voicePresets : []
|
|
772
|
+
const extra = voices.filter((voice) => !presets.some((preset) => preset.voiceId === voice.voiceId))
|
|
773
|
+
const balance = data && typeof data.balance === 'number' ? data.balance : null
|
|
774
|
+
const used = data && data.today ? data.today.chars : 0
|
|
775
|
+
const limit = data && data.today ? data.today.limit : dailyChars
|
|
776
|
+
|
|
777
|
+
const connectKey = async () => {
|
|
778
|
+
const key = apiKeyInput.trim()
|
|
779
|
+
if (!key) {
|
|
780
|
+
setConnectNote({ tone: 'error', text: t('extra.keyRequired') })
|
|
781
|
+
return
|
|
782
|
+
}
|
|
783
|
+
setPhase('connect')
|
|
784
|
+
setConnectNote(null)
|
|
785
|
+
try {
|
|
786
|
+
const result = await api('/connect', {
|
|
787
|
+
method: 'POST',
|
|
788
|
+
headers: { 'content-type': 'application/json' },
|
|
789
|
+
body: JSON.stringify({ apiKey: key }),
|
|
790
|
+
})
|
|
791
|
+
setApiKeyInput('')
|
|
792
|
+
setConnectNote({
|
|
793
|
+
tone: 'ok',
|
|
794
|
+
text: t('extra.keyConnected') + (typeof result.balance === 'number' ? ' · ' + result.balance.toFixed(1) + ' ' + t('status.credits') : ''),
|
|
795
|
+
})
|
|
796
|
+
reload()
|
|
797
|
+
} catch (error) {
|
|
798
|
+
setConnectNote({ tone: 'error', text: humanError(t, error) })
|
|
799
|
+
}
|
|
800
|
+
setPhase('idle')
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
const disconnectKey = async () => {
|
|
804
|
+
setPhase('disconnect')
|
|
805
|
+
setConnectNote(null)
|
|
806
|
+
try {
|
|
807
|
+
await api('/disconnect', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' })
|
|
808
|
+
setConnectNote({ tone: 'muted', text: t('extra.keyDisconnected') })
|
|
809
|
+
reload()
|
|
810
|
+
} catch (error) {
|
|
811
|
+
setConnectNote({ tone: 'error', text: humanError(t, error) })
|
|
812
|
+
}
|
|
813
|
+
setPhase('idle')
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const preview = async () => {
|
|
817
|
+
setPhase('preview')
|
|
818
|
+
setNotice('')
|
|
819
|
+
try {
|
|
820
|
+
const result = await speakRemotely({ text: previewText || '你好', toneId: moodId, voiceId })
|
|
821
|
+
setPhase('idle')
|
|
822
|
+
setNotice((result.chars || 0) + ' ' + t('status.chars') + ' · ' + (result.credits || 0) + ' ' + t('status.credits'))
|
|
823
|
+
} catch (error) {
|
|
824
|
+
setPhase('idle')
|
|
825
|
+
setNotice(humanError(t, error))
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
const save = async () => {
|
|
830
|
+
setPhase('save')
|
|
831
|
+
setNotice('')
|
|
832
|
+
try {
|
|
833
|
+
await api('/settings', {
|
|
834
|
+
method: 'POST',
|
|
835
|
+
headers: { 'content-type': 'application/json' },
|
|
836
|
+
body: JSON.stringify({
|
|
837
|
+
voiceId,
|
|
838
|
+
moodId,
|
|
839
|
+
emotionMode,
|
|
840
|
+
tones: tones.filter((tone) => !tone.builtin),
|
|
841
|
+
previewText,
|
|
842
|
+
dailyChars: Number(dailyChars),
|
|
843
|
+
autoSpeak,
|
|
844
|
+
autoSpeakMaxChars: Number(autoMax),
|
|
845
|
+
backgroundPlay,
|
|
846
|
+
customMood,
|
|
847
|
+
}),
|
|
848
|
+
})
|
|
849
|
+
setPhase('idle')
|
|
850
|
+
setNotice(t('label.saved'))
|
|
851
|
+
reload()
|
|
852
|
+
} catch (error) {
|
|
853
|
+
setPhase('idle')
|
|
854
|
+
setNotice(humanError(t, error))
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
const doRefresh = async () => {
|
|
859
|
+
setPhase('refresh')
|
|
860
|
+
setRefreshNote({ text: '', tone: 'muted' })
|
|
861
|
+
try {
|
|
862
|
+
const fresh = await reload(true)
|
|
863
|
+
setPhase('idle')
|
|
864
|
+
const credits = fresh && typeof fresh.balance === 'number' ? ' · ' + fresh.balance.toFixed(1) + ' ' + t('status.credits') : ''
|
|
865
|
+
setRefreshNote({ text: t('extra.refreshed') + credits, tone: 'ok' })
|
|
866
|
+
} catch (error) {
|
|
867
|
+
setPhase('idle')
|
|
868
|
+
setRefreshNote({ text: t('extra.refreshFailed') + ': ' + humanError(t, error), tone: 'error' })
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
const generate = async () => {
|
|
873
|
+
setPhase('design')
|
|
874
|
+
setNotice('')
|
|
875
|
+
setCandidates([])
|
|
876
|
+
try {
|
|
877
|
+
const result = await api('/design', {
|
|
878
|
+
method: 'POST',
|
|
879
|
+
headers: { 'content-type': 'application/json' },
|
|
880
|
+
body: JSON.stringify({ description: designDesc, text: designText || previewText || '你好' }),
|
|
881
|
+
})
|
|
882
|
+
setCandidates(result.candidates || [])
|
|
883
|
+
setPhase('idle')
|
|
884
|
+
if (!result.candidates || !result.candidates.length) setNotice(t('extra.designEmpty'))
|
|
885
|
+
} catch (error) {
|
|
886
|
+
setPhase('idle')
|
|
887
|
+
setNotice(humanError(t, error))
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
const saveCandidate = async (candidate) => {
|
|
892
|
+
setPhase('saveVoice')
|
|
893
|
+
setNotice('')
|
|
894
|
+
try {
|
|
895
|
+
const result = await api('/save-voice', {
|
|
896
|
+
method: 'POST',
|
|
897
|
+
headers: { 'content-type': 'application/json' },
|
|
898
|
+
body: JSON.stringify({
|
|
899
|
+
generatedVoiceId: candidate.generatedVoiceId,
|
|
900
|
+
name: designName.trim() || candidate.name || t('extra.newVoice'),
|
|
901
|
+
description: designDesc,
|
|
902
|
+
}),
|
|
903
|
+
})
|
|
904
|
+
setPhase('idle')
|
|
905
|
+
if (result.voiceId) {
|
|
906
|
+
setVoiceId(result.voiceId)
|
|
907
|
+
setNotice(t('extra.voiceSaved'))
|
|
908
|
+
reload()
|
|
909
|
+
const fresh = await api('/voices').catch(() => null)
|
|
910
|
+
if (fresh && Array.isArray(fresh.voices)) setVoices(fresh.voices)
|
|
911
|
+
}
|
|
912
|
+
} catch (error) {
|
|
913
|
+
setPhase('idle')
|
|
914
|
+
setNotice(humanError(t, error))
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
const publicVoices = voices.filter((voice) => {
|
|
919
|
+
if (voice.private) return false
|
|
920
|
+
if (presets.some((preset) => preset.voiceId === voice.voiceId)) return false
|
|
921
|
+
const query = libraryQuery.trim().toLowerCase()
|
|
922
|
+
if (!query) return true
|
|
923
|
+
return (voice.name || '').toLowerCase().includes(query)
|
|
924
|
+
|| (voice.description || '').toLowerCase().includes(query)
|
|
925
|
+
})
|
|
926
|
+
|
|
927
|
+
const loadPublicVoice = async (voice) => {
|
|
928
|
+
const next = savedVoices.some((item) => item.voiceId === voice.voiceId)
|
|
929
|
+
? savedVoices
|
|
930
|
+
: savedVoices.concat([{
|
|
931
|
+
voiceId: voice.voiceId,
|
|
932
|
+
name: voice.name,
|
|
933
|
+
language: voice.language || '',
|
|
934
|
+
description: voice.description || '',
|
|
935
|
+
}])
|
|
936
|
+
setSavedVoices(next)
|
|
937
|
+
setVoiceId(voice.voiceId)
|
|
938
|
+
setNotice(t('extra.voiceAdded'))
|
|
939
|
+
try {
|
|
940
|
+
await api('/settings', {
|
|
941
|
+
method: 'POST',
|
|
942
|
+
headers: { 'content-type': 'application/json' },
|
|
943
|
+
body: JSON.stringify({ savedVoices: next }),
|
|
944
|
+
})
|
|
945
|
+
} catch (error) {
|
|
946
|
+
setNotice(humanError(t, error))
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
const audioPreview = async (id) => {
|
|
951
|
+
setPhase('voicePreview')
|
|
952
|
+
setNotice('')
|
|
953
|
+
try {
|
|
954
|
+
await speakRemotely({ text: previewText || '你好', toneId: 'normal', voiceId: id })
|
|
955
|
+
setPhase('idle')
|
|
956
|
+
} catch (error) {
|
|
957
|
+
setPhase('idle')
|
|
958
|
+
setNotice(humanError(t, error))
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
const activeTone = tones.find((tone) => tone.id === moodId) || tones[0] || null
|
|
963
|
+
const activeVoice = voices.find((voice) => voice.voiceId === voiceId) || null
|
|
964
|
+
const savedVoice = savedVoices.find((item) => item.voiceId === voiceId) || null
|
|
965
|
+
const canDeleteVoice = Boolean(!presets.some((preset) => preset.voiceId === voiceId)
|
|
966
|
+
&& (savedVoice || (activeVoice && activeVoice.private)))
|
|
967
|
+
const canRenameVoice = Boolean(voiceId)
|
|
968
|
+
&& !presets.some((preset) => preset.voiceId === voiceId)
|
|
969
|
+
&& !savedVoice
|
|
970
|
+
|
|
971
|
+
const startRenameVoice = () => {
|
|
972
|
+
if (!canRenameVoice) {
|
|
973
|
+
setNotice(t('extra.renameBlocked'))
|
|
974
|
+
return
|
|
975
|
+
}
|
|
976
|
+
setVoiceNameDraft((activeVoice && activeVoice.name) || '')
|
|
977
|
+
setVoiceRenameOpen(true)
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
const renameVoice = async () => {
|
|
981
|
+
const name = voiceNameDraft.trim()
|
|
982
|
+
if (!name) {
|
|
983
|
+
setNotice(t('extra.toneIncomplete'))
|
|
984
|
+
return
|
|
985
|
+
}
|
|
986
|
+
setPhase('renameVoice')
|
|
987
|
+
setNotice('')
|
|
988
|
+
try {
|
|
989
|
+
await api('/rename-voice', {
|
|
990
|
+
method: 'POST',
|
|
991
|
+
headers: { 'content-type': 'application/json' },
|
|
992
|
+
body: JSON.stringify({ voiceId, name }),
|
|
993
|
+
})
|
|
994
|
+
setVoiceNames((prev) => ({ ...prev, [voiceId]: name }))
|
|
995
|
+
setVoices((prev) => prev.map((voice) => (
|
|
996
|
+
voice.voiceId === voiceId ? { ...voice, name } : voice
|
|
997
|
+
)))
|
|
998
|
+
setPhase('idle')
|
|
999
|
+
setVoiceRenameOpen(false)
|
|
1000
|
+
setNotice(t('extra.voiceRenamed') + ' ' + name)
|
|
1001
|
+
const fresh = await api('/voices').catch(() => null)
|
|
1002
|
+
if (fresh && Array.isArray(fresh.voices)) {
|
|
1003
|
+
setVoices(fresh.voices.map((voice) => (
|
|
1004
|
+
voice.voiceId === voiceId ? { ...voice, name } : voice
|
|
1005
|
+
)))
|
|
1006
|
+
}
|
|
1007
|
+
} catch (error) {
|
|
1008
|
+
setPhase('idle')
|
|
1009
|
+
setNotice(humanError(t, error))
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
const startNewTone = () => {
|
|
1014
|
+
setToneEditId('')
|
|
1015
|
+
setToneDraftName('')
|
|
1016
|
+
setToneDraftText('')
|
|
1017
|
+
setToneEditor(true)
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
const startEditTone = () => {
|
|
1021
|
+
if (!activeTone || activeTone.builtin) return
|
|
1022
|
+
setToneEditId(activeTone.id)
|
|
1023
|
+
setToneDraftName(activeTone.name)
|
|
1024
|
+
setToneDraftText(activeTone.instructions)
|
|
1025
|
+
setToneEditor(true)
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
const cancelTone = () => setToneEditor(false)
|
|
1029
|
+
|
|
1030
|
+
const saveTone = async () => {
|
|
1031
|
+
const name = toneDraftName.trim()
|
|
1032
|
+
const text = toneDraftText.trim()
|
|
1033
|
+
if (!name || !text) {
|
|
1034
|
+
setNotice(t('extra.toneIncomplete'))
|
|
1035
|
+
return
|
|
1036
|
+
}
|
|
1037
|
+
setPhase('saveTone')
|
|
1038
|
+
setNotice('')
|
|
1039
|
+
const id = toneEditId || 'tone-' + Date.now().toString(36)
|
|
1040
|
+
const next = tones
|
|
1041
|
+
.filter((tone) => tone.builtin || tone.id !== id)
|
|
1042
|
+
.concat([{ id, name, instructions: text, builtin: false }])
|
|
1043
|
+
try {
|
|
1044
|
+
await api('/settings', {
|
|
1045
|
+
method: 'POST',
|
|
1046
|
+
headers: { 'content-type': 'application/json' },
|
|
1047
|
+
body: JSON.stringify({ moodId: id, tones: next.filter((tone) => !tone.builtin) }),
|
|
1048
|
+
})
|
|
1049
|
+
setTones(next)
|
|
1050
|
+
setMoodId(id)
|
|
1051
|
+
setToneEditor(false)
|
|
1052
|
+
setPhase('idle')
|
|
1053
|
+
setNotice(t('extra.toneSaved'))
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
setPhase('idle')
|
|
1056
|
+
setNotice(humanError(t, error))
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
const removeTone = async () => {
|
|
1061
|
+
if (!activeTone || activeTone.builtin) return
|
|
1062
|
+
setPhase('deleteTone')
|
|
1063
|
+
setNotice('')
|
|
1064
|
+
const next = tones.filter((tone) => tone.id !== activeTone.id)
|
|
1065
|
+
try {
|
|
1066
|
+
await api('/settings', {
|
|
1067
|
+
method: 'POST',
|
|
1068
|
+
headers: { 'content-type': 'application/json' },
|
|
1069
|
+
body: JSON.stringify({ moodId: 'normal', tones: next.filter((tone) => !tone.builtin) }),
|
|
1070
|
+
})
|
|
1071
|
+
setTones(next)
|
|
1072
|
+
setMoodId('normal')
|
|
1073
|
+
setPhase('idle')
|
|
1074
|
+
setNotice(t('extra.toneDeleted'))
|
|
1075
|
+
} catch (error) {
|
|
1076
|
+
setPhase('idle')
|
|
1077
|
+
setNotice(humanError(t, error))
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
const removeVoice = async () => {
|
|
1082
|
+
if (!canDeleteVoice) return
|
|
1083
|
+
setPhase('deleteVoice')
|
|
1084
|
+
setNotice('')
|
|
1085
|
+
try {
|
|
1086
|
+
await api('/delete-voice', {
|
|
1087
|
+
method: 'POST',
|
|
1088
|
+
headers: { 'content-type': 'application/json' },
|
|
1089
|
+
body: JSON.stringify({ voiceId }),
|
|
1090
|
+
})
|
|
1091
|
+
setPhase('idle')
|
|
1092
|
+
setNotice(savedVoice ? t('extra.voiceRemoved') : t('extra.voiceDeleted'))
|
|
1093
|
+
if (savedVoice) setSavedVoices(savedVoices.filter((item) => item.voiceId !== voiceId))
|
|
1094
|
+
setVoiceId(presets.length ? presets[0].voiceId : '')
|
|
1095
|
+
const fresh = await api('/voices').catch(() => null)
|
|
1096
|
+
if (fresh && Array.isArray(fresh.voices)) setVoices(fresh.voices)
|
|
1097
|
+
} catch (error) {
|
|
1098
|
+
setPhase('idle')
|
|
1099
|
+
setNotice(humanError(t, error))
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
const row = (key, ...children) => h('div', { className: 'dsh-breeze-row', key },
|
|
1104
|
+
h('div', { className: 'dsh-breeze-key' }, key),
|
|
1105
|
+
h('div', { className: 'dsh-breeze-value' }, children))
|
|
1106
|
+
|
|
1107
|
+
const sectionTitle = (key) => h('div', {
|
|
1108
|
+
key,
|
|
1109
|
+
style: { marginTop: 18, marginBottom: 4, fontSize: 13, fontWeight: 600, color: COLOR.primary },
|
|
1110
|
+
}, key)
|
|
1111
|
+
|
|
1112
|
+
const optionLabel = (voice) => {
|
|
1113
|
+
const isPreset = presets.some((preset) => preset.voiceId === voice.voiceId)
|
|
1114
|
+
const label = (voiceNames[voice.voiceId] || voice.name)
|
|
1115
|
+
if (isPreset) return label + ' · ' + (voice.tag || '')
|
|
1116
|
+
return (voice.designed ? '★ ' : '') + label
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
return h('div', { style: { padding: '4px 0 12px' } },
|
|
1120
|
+
h(StyleSheet),
|
|
1121
|
+
h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 6 } },
|
|
1122
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, color: COLOR.primary } }, t('section.title')),
|
|
1123
|
+
h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('section.subtitle'))),
|
|
1124
|
+
state.error ? h('p', { className: 'dsh-breeze-hint', style: { color: COLOR.error } }, state.error) : null,
|
|
1125
|
+
|
|
1126
|
+
h('div', { style: { display: 'flex', flexDirection: 'column' } },
|
|
1127
|
+
row(t('extra.apiKey'),
|
|
1128
|
+
h('input', {
|
|
1129
|
+
className: 'dsh-breeze-control',
|
|
1130
|
+
style: { flex: 1, minWidth: 220, maxWidth: 360 },
|
|
1131
|
+
type: 'password',
|
|
1132
|
+
placeholder: data && data.hasKey ? t('extra.keyBound') : 'brz_...',
|
|
1133
|
+
value: apiKeyInput,
|
|
1134
|
+
onChange: (event) => setApiKeyInput(event.target.value),
|
|
1135
|
+
}),
|
|
1136
|
+
h('button', {
|
|
1137
|
+
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1138
|
+
onClick: connectKey, disabled: phase === 'connect',
|
|
1139
|
+
}, phase === 'connect' ? Spinner(12) : t('extra.connect')),
|
|
1140
|
+
data && data.hasKey
|
|
1141
|
+
? h('button', {
|
|
1142
|
+
type: 'button', className: 'dsh-breeze-btn',
|
|
1143
|
+
onClick: disconnectKey, disabled: phase === 'disconnect',
|
|
1144
|
+
}, t('extra.disconnect'))
|
|
1145
|
+
: null,
|
|
1146
|
+
h('span', {
|
|
1147
|
+
style: {
|
|
1148
|
+
fontSize: 12,
|
|
1149
|
+
color: connectNote
|
|
1150
|
+
? (connectNote.tone === 'error' ? COLOR.error : connectNote.tone === 'ok' ? COLOR.success : COLOR.secondary)
|
|
1151
|
+
: COLOR.secondary,
|
|
1152
|
+
},
|
|
1153
|
+
}, connectNote ? connectNote.text : (data && data.hasKey ? t('extra.keyBound') : t('extra.keyMissing')))),
|
|
1154
|
+
|
|
1155
|
+
row(t('label.voice'),
|
|
1156
|
+
h('select', {
|
|
1157
|
+
className: 'dsh-breeze-control',
|
|
1158
|
+
style: { maxWidth: 340 },
|
|
1159
|
+
value: voiceId,
|
|
1160
|
+
onChange: (event) => setVoiceId(event.target.value),
|
|
1161
|
+
},
|
|
1162
|
+
presets.map((preset) => h('option', { key: preset.voiceId, value: preset.voiceId }, optionLabel(preset))),
|
|
1163
|
+
extra.filter((voice) => voice.private).map((voice) => h('option', { key: voice.voiceId, value: voice.voiceId }, optionLabel(voice))),
|
|
1164
|
+
savedVoices
|
|
1165
|
+
.filter((item) => !presets.some((preset) => preset.voiceId === item.voiceId))
|
|
1166
|
+
.map((item) => h('option', { key: item.voiceId, value: item.voiceId }, item.name)),
|
|
1167
|
+
voiceId && !presets.some((p) => p.voiceId === voiceId) && !extra.some((v) => v.voiceId === voiceId)
|
|
1168
|
+
? h('option', { key: voiceId, value: voiceId }, voiceId)
|
|
1169
|
+
: null),
|
|
1170
|
+
h('button', {
|
|
1171
|
+
type: 'button',
|
|
1172
|
+
className: 'dsh-breeze-btn',
|
|
1173
|
+
onClick: startRenameVoice,
|
|
1174
|
+
disabled: !canRenameVoice || phase === 'renameVoice',
|
|
1175
|
+
}, t('extra.renameVoice')),
|
|
1176
|
+
h('button', {
|
|
1177
|
+
type: 'button',
|
|
1178
|
+
className: 'dsh-breeze-btn',
|
|
1179
|
+
onClick: removeVoice,
|
|
1180
|
+
disabled: !canDeleteVoice || phase === 'deleteVoice',
|
|
1181
|
+
}, phase === 'deleteVoice' ? Spinner(12) : t('extra.deleteVoice'))),
|
|
1182
|
+
|
|
1183
|
+
voiceRenameOpen
|
|
1184
|
+
? h('div', { style: { display: 'flex', gap: 8, margin: '2px 0 8px 144px' } },
|
|
1185
|
+
h('input', {
|
|
1186
|
+
className: 'dsh-breeze-control',
|
|
1187
|
+
style: { maxWidth: 260 },
|
|
1188
|
+
placeholder: t('extra.renamePlaceholder'),
|
|
1189
|
+
value: voiceNameDraft,
|
|
1190
|
+
onChange: (event) => setVoiceNameDraft(event.target.value),
|
|
1191
|
+
}),
|
|
1192
|
+
h('button', {
|
|
1193
|
+
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1194
|
+
onClick: renameVoice, disabled: phase === 'renameVoice',
|
|
1195
|
+
}, phase === 'renameVoice' ? Spinner(12) : t('extra.saveName')),
|
|
1196
|
+
h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: () => setVoiceRenameOpen(false) }, t('extra.cancel')))
|
|
1197
|
+
: null,
|
|
1198
|
+
|
|
1199
|
+
row(t('extra.publicVoices'),
|
|
1200
|
+
h('button', {
|
|
1201
|
+
type: 'button',
|
|
1202
|
+
className: 'dsh-breeze-btn',
|
|
1203
|
+
onClick: () => setLibraryOpen(!libraryOpen),
|
|
1204
|
+
}, libraryOpen ? t('extra.collapseLibrary') : t('extra.openLibrary')),
|
|
1205
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.publicVoicesHint'))),
|
|
1206
|
+
|
|
1207
|
+
libraryOpen
|
|
1208
|
+
? h('div', {
|
|
1209
|
+
style: {
|
|
1210
|
+
border: '1px solid ' + COLOR.border, borderRadius: 10, background: COLOR.surface,
|
|
1211
|
+
padding: 12, margin: '2px 0 10px',
|
|
1212
|
+
},
|
|
1213
|
+
},
|
|
1214
|
+
h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 8, marginBottom: 8 } },
|
|
1215
|
+
h('div', { style: { fontSize: 13, fontWeight: 600, color: COLOR.primary } }, t('extra.libraryTitle')),
|
|
1216
|
+
h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.librarySubtitle'))),
|
|
1217
|
+
h('input', {
|
|
1218
|
+
className: 'dsh-breeze-control',
|
|
1219
|
+
style: { width: '100%', marginBottom: 8 },
|
|
1220
|
+
placeholder: t('extra.librarySearch'),
|
|
1221
|
+
value: libraryQuery,
|
|
1222
|
+
onChange: (event) => setLibraryQuery(event.target.value),
|
|
1223
|
+
}),
|
|
1224
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, maxHeight: 260, overflowY: 'auto' } },
|
|
1225
|
+
publicVoices.map((voice) => h('div', {
|
|
1226
|
+
key: voice.voiceId,
|
|
1227
|
+
style: {
|
|
1228
|
+
display: 'flex', alignItems: 'center', gap: 10, padding: '6px 0',
|
|
1229
|
+
borderTop: '1px solid ' + COLOR.border,
|
|
1230
|
+
},
|
|
1231
|
+
},
|
|
1232
|
+
h('div', { style: { flex: 1, minWidth: 0 } },
|
|
1233
|
+
h('div', { style: { fontSize: 13, color: COLOR.primary } }, voice.name + ' · ' + (voice.language || '')),
|
|
1234
|
+
h('div', {
|
|
1235
|
+
style: {
|
|
1236
|
+
fontSize: 12, color: COLOR.secondary, lineHeight: '17px',
|
|
1237
|
+
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
1238
|
+
},
|
|
1239
|
+
}, voice.description || '')),
|
|
1240
|
+
h('button', {
|
|
1241
|
+
type: 'button', className: 'dsh-breeze-btn',
|
|
1242
|
+
onClick: () => audioPreview(voice.voiceId),
|
|
1243
|
+
}, t('label.preview')),
|
|
1244
|
+
h('button', {
|
|
1245
|
+
type: 'button',
|
|
1246
|
+
className: 'dsh-breeze-btn',
|
|
1247
|
+
'data-primary': savedVoices.some((item) => item.voiceId === voice.voiceId) ? 'false' : 'true',
|
|
1248
|
+
disabled: savedVoices.some((item) => item.voiceId === voice.voiceId),
|
|
1249
|
+
onClick: () => loadPublicVoice(voice),
|
|
1250
|
+
}, savedVoices.some((item) => item.voiceId === voice.voiceId) ? t('extra.voiceLoadedTag') : t('extra.loadVoice'))))),
|
|
1251
|
+
publicVoices.length ? null : h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.libraryEmpty')))
|
|
1252
|
+
: null,
|
|
1253
|
+
|
|
1254
|
+
row(t('label.mood'),
|
|
1255
|
+
h('select', {
|
|
1256
|
+
className: 'dsh-breeze-control',
|
|
1257
|
+
style: { maxWidth: 240 },
|
|
1258
|
+
value: moodId,
|
|
1259
|
+
onChange: (event) => setMoodId(event.target.value),
|
|
1260
|
+
},
|
|
1261
|
+
tones.map((tone) => h('option', { key: tone.id, value: tone.id },
|
|
1262
|
+
(tone.builtin ? t('tone.' + tone.id) : tone.name)
|
|
1263
|
+
+ (tone.builtin ? '' : ' · ' + t('extra.customTag'))))),
|
|
1264
|
+
h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: startNewTone }, t('extra.newTone')),
|
|
1265
|
+
activeTone && !activeTone.builtin
|
|
1266
|
+
? h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: startEditTone }, t('extra.editTone'))
|
|
1267
|
+
: null,
|
|
1268
|
+
activeTone && !activeTone.builtin
|
|
1269
|
+
? h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: removeTone, disabled: phase === 'deleteTone' }, t('extra.deleteTone'))
|
|
1270
|
+
: null),
|
|
1271
|
+
|
|
1272
|
+
activeTone
|
|
1273
|
+
? h('div', {
|
|
1274
|
+
style: {
|
|
1275
|
+
marginTop: -4, marginBottom: 6, fontSize: 12, lineHeight: '18px',
|
|
1276
|
+
color: COLOR.secondary, paddingLeft: 144,
|
|
1277
|
+
},
|
|
1278
|
+
}, activeTone.instructions)
|
|
1279
|
+
: null,
|
|
1280
|
+
|
|
1281
|
+
toneEditor
|
|
1282
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 8, margin: '4px 0 10px 144px' } },
|
|
1283
|
+
h('input', {
|
|
1284
|
+
className: 'dsh-breeze-control',
|
|
1285
|
+
style: { maxWidth: 300 },
|
|
1286
|
+
placeholder: t('extra.toneNamePlaceholder'),
|
|
1287
|
+
value: toneDraftName,
|
|
1288
|
+
onChange: (event) => setToneDraftName(event.target.value),
|
|
1289
|
+
}),
|
|
1290
|
+
h('textarea', {
|
|
1291
|
+
className: 'dsh-breeze-control',
|
|
1292
|
+
style: { minHeight: 62, padding: '8px 10px', resize: 'vertical', lineHeight: '20px' },
|
|
1293
|
+
placeholder: t('extra.tonePlaceholder'),
|
|
1294
|
+
maxLength: 500,
|
|
1295
|
+
value: toneDraftText,
|
|
1296
|
+
onChange: (event) => setToneDraftText(event.target.value),
|
|
1297
|
+
}),
|
|
1298
|
+
h('div', { style: { display: 'flex', gap: 8 } },
|
|
1299
|
+
h('button', {
|
|
1300
|
+
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1301
|
+
onClick: saveTone, disabled: phase === 'saveTone',
|
|
1302
|
+
}, phase === 'saveTone' ? Spinner(12) : t('extra.saveTone')),
|
|
1303
|
+
h('button', { type: 'button', className: 'dsh-breeze-btn', onClick: cancelTone }, t('extra.cancel'))))
|
|
1304
|
+
: null,
|
|
1305
|
+
|
|
1306
|
+
row(t('extra.emotionMode'),
|
|
1307
|
+
h('select', {
|
|
1308
|
+
className: 'dsh-breeze-control',
|
|
1309
|
+
style: { maxWidth: 200 },
|
|
1310
|
+
value: emotionMode,
|
|
1311
|
+
onChange: async (event) => {
|
|
1312
|
+
const next = event.target.value
|
|
1313
|
+
setEmotionMode(next)
|
|
1314
|
+
try {
|
|
1315
|
+
await api('/settings', {
|
|
1316
|
+
method: 'POST',
|
|
1317
|
+
headers: { 'content-type': 'application/json' },
|
|
1318
|
+
body: JSON.stringify({ emotionMode: next }),
|
|
1319
|
+
})
|
|
1320
|
+
setNotice(t('extra.emotionSaved'))
|
|
1321
|
+
} catch (error) {
|
|
1322
|
+
setNotice(humanError(t, error))
|
|
1323
|
+
}
|
|
1324
|
+
},
|
|
1325
|
+
},
|
|
1326
|
+
h('option', { value: 'fixed' }, t('extra.emotionFixed')),
|
|
1327
|
+
h('option', { value: 'infer' }, t('extra.emotionInfer')),
|
|
1328
|
+
h('option', { value: 'marker' }, t('extra.emotionMarker'))),
|
|
1329
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } },
|
|
1330
|
+
emotionMode === 'infer'
|
|
1331
|
+
? t('extra.emotionInferHint')
|
|
1332
|
+
: emotionMode === 'marker'
|
|
1333
|
+
? t('extra.emotionMarkerHint')
|
|
1334
|
+
: t('extra.emotionFixedHint')),
|
|
1335
|
+
emotionMode === 'marker'
|
|
1336
|
+
? h('div', { style: { flexBasis: '100%', fontSize: 12, color: COLOR.error, lineHeight: '18px' } }, t('extra.emotionMarkerNote'))
|
|
1337
|
+
: null),
|
|
1338
|
+
|
|
1339
|
+
row(t('label.previewText'),
|
|
1340
|
+
h('input', {
|
|
1341
|
+
className: 'dsh-breeze-control',
|
|
1342
|
+
style: { flex: 1, minWidth: 220, maxWidth: 420 },
|
|
1343
|
+
value: previewText,
|
|
1344
|
+
onChange: (event) => setPreviewText(event.target.value),
|
|
1345
|
+
}),
|
|
1346
|
+
h('button', {
|
|
1347
|
+
type: 'button',
|
|
1348
|
+
className: 'dsh-breeze-play',
|
|
1349
|
+
onClick: preview,
|
|
1350
|
+
disabled: phase === 'preview',
|
|
1351
|
+
}, phase === 'preview' ? Spinner(11) : PlayGlyph(11), h('span', null, t('label.preview')))),
|
|
1352
|
+
|
|
1353
|
+
row(t('extra.autoSpeak'),
|
|
1354
|
+
h('button', {
|
|
1355
|
+
type: 'button',
|
|
1356
|
+
role: 'switch',
|
|
1357
|
+
'aria-checked': autoSpeak ? 'true' : 'false',
|
|
1358
|
+
className: 'dsh-breeze-switch',
|
|
1359
|
+
'data-on': autoSpeak ? 'true' : 'false',
|
|
1360
|
+
onClick: () => setAutoSpeak(!autoSpeak),
|
|
1361
|
+
}, h('span', { className: 'dsh-breeze-knob' })),
|
|
1362
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.autoSpeakHint'))),
|
|
1363
|
+
|
|
1364
|
+
row(t('extra.backgroundPlay'),
|
|
1365
|
+
h('button', {
|
|
1366
|
+
type: 'button',
|
|
1367
|
+
role: 'switch',
|
|
1368
|
+
'aria-checked': backgroundPlay ? 'true' : 'false',
|
|
1369
|
+
className: 'dsh-breeze-switch',
|
|
1370
|
+
'data-on': backgroundPlay ? 'true' : 'false',
|
|
1371
|
+
onClick: () => setBackgroundPlay(!backgroundPlay),
|
|
1372
|
+
}, h('span', { className: 'dsh-breeze-knob' })),
|
|
1373
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.backgroundPlayHint'))),
|
|
1374
|
+
|
|
1375
|
+
row(t('extra.autoMax'),
|
|
1376
|
+
h('input', {
|
|
1377
|
+
type: 'range', min: 0, max: 1000, step: 10,
|
|
1378
|
+
value: Math.min(1000, Math.max(0, Number(autoMax) || 0)),
|
|
1379
|
+
onChange: (event) => setAutoMax(Number(event.target.value)),
|
|
1380
|
+
style: { flex: 1, minWidth: 160, maxWidth: 320, accentColor: COLOR.brand },
|
|
1381
|
+
}),
|
|
1382
|
+
h('input', {
|
|
1383
|
+
className: 'dsh-breeze-control',
|
|
1384
|
+
style: { width: 96 },
|
|
1385
|
+
type: 'number', min: 0, max: 99999, step: 1,
|
|
1386
|
+
value: autoMax,
|
|
1387
|
+
onChange: (event) => setAutoMax(Math.max(0, Math.min(99999, Number(event.target.value) || 0))),
|
|
1388
|
+
}),
|
|
1389
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('status.chars')),
|
|
1390
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.autoMaxHint')),
|
|
1391
|
+
autoMax > 1000
|
|
1392
|
+
? h('div', { style: { flexBasis: '100%', fontSize: 12, fontWeight: 600, color: COLOR.error, lineHeight: '18px' } }, t('extra.autoMaxHard'))
|
|
1393
|
+
: autoMax > 300
|
|
1394
|
+
? h('div', { style: { flexBasis: '100%', fontSize: 12, color: COLOR.error, lineHeight: '18px' } }, t('extra.autoMaxWarning'))
|
|
1395
|
+
: null),
|
|
1396
|
+
|
|
1397
|
+
row(t('label.dailyLimit'),
|
|
1398
|
+
h('input', {
|
|
1399
|
+
className: 'dsh-breeze-control',
|
|
1400
|
+
style: { width: 110 },
|
|
1401
|
+
type: 'number', min: 100, step: 100,
|
|
1402
|
+
value: dailyChars,
|
|
1403
|
+
onChange: (event) => setDailyChars(event.target.value),
|
|
1404
|
+
}),
|
|
1405
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('hint.limit'))),
|
|
1406
|
+
|
|
1407
|
+
row(t('label.todayUsage'),
|
|
1408
|
+
h('span', { style: { fontSize: 13, color: COLOR.primary } }, used + ' / ' + limit + ' ' + t('status.chars')),
|
|
1409
|
+
h('span', {
|
|
1410
|
+
style: {
|
|
1411
|
+
flex: '1 1 120px', maxWidth: 220, height: 5, borderRadius: 999,
|
|
1412
|
+
background: COLOR.border, overflow: 'hidden', display: 'block',
|
|
1413
|
+
},
|
|
1414
|
+
}, h('span', {
|
|
1415
|
+
style: {
|
|
1416
|
+
display: 'block', height: '100%', borderRadius: 999,
|
|
1417
|
+
width: Math.min(100, limit ? Math.round((used / limit) * 100) : 0) + '%',
|
|
1418
|
+
background: COLOR.brand,
|
|
1419
|
+
},
|
|
1420
|
+
}))),
|
|
1421
|
+
|
|
1422
|
+
row(t('label.balance'),
|
|
1423
|
+
h('span', { style: { fontSize: 13, color: COLOR.primary } }, balance === null ? '-' : balance.toFixed(1)),
|
|
1424
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('status.credits')),
|
|
1425
|
+
h('button', {
|
|
1426
|
+
type: 'button',
|
|
1427
|
+
className: 'dsh-breeze-btn',
|
|
1428
|
+
onClick: doRefresh,
|
|
1429
|
+
disabled: phase === 'refresh',
|
|
1430
|
+
}, phase === 'refresh' ? Spinner(12) : t('label.refresh')),
|
|
1431
|
+
refreshNote.text
|
|
1432
|
+
? h('span', {
|
|
1433
|
+
style: {
|
|
1434
|
+
fontSize: 12,
|
|
1435
|
+
color: refreshNote.tone === 'error' ? COLOR.error : refreshNote.tone === 'ok' ? COLOR.success : COLOR.secondary,
|
|
1436
|
+
},
|
|
1437
|
+
}, refreshNote.text)
|
|
1438
|
+
: null)),
|
|
1439
|
+
|
|
1440
|
+
h('div', {
|
|
1441
|
+
style: { marginTop: 14, fontSize: 12, lineHeight: '18px', color: COLOR.secondary },
|
|
1442
|
+
}, t('extra.cloneNotice')),
|
|
1443
|
+
|
|
1444
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginTop: 8 } },
|
|
1445
|
+
h('button', {
|
|
1446
|
+
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1447
|
+
onClick: save, disabled: phase === 'save',
|
|
1448
|
+
}, phase === 'save' ? t('label.saving') : t('label.save')),
|
|
1449
|
+
notice ? h('span', { style: { fontSize: 12, color: COLOR.secondary } }, notice) : null),
|
|
1450
|
+
data && data.ok === false ? h('p', { className: 'dsh-breeze-hint' }, t('hint.key')) : null,
|
|
1451
|
+
|
|
1452
|
+
sectionTitle(t('extra.designTitle')),
|
|
1453
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10, marginTop: 4 } },
|
|
1454
|
+
h('textarea', {
|
|
1455
|
+
className: 'dsh-breeze-control',
|
|
1456
|
+
style: { minHeight: 88, padding: '8px 10px', resize: 'vertical', lineHeight: '20px' },
|
|
1457
|
+
placeholder: t('extra.designPlaceholder'),
|
|
1458
|
+
maxLength: 500,
|
|
1459
|
+
value: designDesc,
|
|
1460
|
+
onChange: (event) => setDesignDesc(event.target.value),
|
|
1461
|
+
}),
|
|
1462
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
|
|
1463
|
+
h('input', {
|
|
1464
|
+
className: 'dsh-breeze-control',
|
|
1465
|
+
style: { flex: 1, minWidth: 200, maxWidth: 420 },
|
|
1466
|
+
placeholder: t('extra.designSample'),
|
|
1467
|
+
maxLength: 500,
|
|
1468
|
+
value: designText,
|
|
1469
|
+
onChange: (event) => setDesignText(event.target.value),
|
|
1470
|
+
}),
|
|
1471
|
+
h('input', {
|
|
1472
|
+
className: 'dsh-breeze-control',
|
|
1473
|
+
style: { width: 160 },
|
|
1474
|
+
placeholder: t('extra.voiceNamePlaceholder'),
|
|
1475
|
+
value: designName,
|
|
1476
|
+
onChange: (event) => setDesignName(event.target.value),
|
|
1477
|
+
}),
|
|
1478
|
+
h('button', {
|
|
1479
|
+
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1480
|
+
onClick: generate, disabled: phase === 'design' || designDesc.trim().length < 3,
|
|
1481
|
+
}, phase === 'design' ? t('extra.generating') : t('extra.generate')),
|
|
1482
|
+
h('span', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.designCost'))),
|
|
1483
|
+
h('p', { className: 'dsh-breeze-hint', style: { margin: 0 } }, t('extra.designHint')),
|
|
1484
|
+
candidates.length
|
|
1485
|
+
? h('div', { style: { display: 'flex', gap: 10, flexWrap: 'wrap', marginTop: 2 } },
|
|
1486
|
+
candidates.map((candidate, index) => h('div', {
|
|
1487
|
+
key: candidate.generatedVoiceId,
|
|
1488
|
+
style: {
|
|
1489
|
+
border: '1px solid ' + COLOR.border, borderRadius: 10, padding: 10,
|
|
1490
|
+
background: COLOR.nested, minWidth: 150, display: 'flex',
|
|
1491
|
+
flexDirection: 'column', gap: 8,
|
|
1492
|
+
},
|
|
1493
|
+
},
|
|
1494
|
+
h('div', { style: { fontSize: 12, color: COLOR.secondary } }, t('extra.candidate') + ' ' + (index + 1)),
|
|
1495
|
+
h('div', { style: { display: 'flex', gap: 8 } },
|
|
1496
|
+
h('button', {
|
|
1497
|
+
type: 'button', className: 'dsh-breeze-btn',
|
|
1498
|
+
onClick: () => playUrl(candidate.url).catch(() => {}),
|
|
1499
|
+
}, PlayGlyph(10), t('label.preview')),
|
|
1500
|
+
h('button', {
|
|
1501
|
+
type: 'button', className: 'dsh-breeze-btn', 'data-primary': 'true',
|
|
1502
|
+
onClick: () => saveCandidate(candidate),
|
|
1503
|
+
disabled: phase === 'saveVoice',
|
|
1504
|
+
}, t('extra.saveVoice'))))))
|
|
1505
|
+
: null))
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
return {
|
|
1509
|
+
inject: ['slots', 'locale'],
|
|
1510
|
+
apply(ctx) {
|
|
1511
|
+
let t = (key) => lookup(DICT.zh, key)
|
|
1512
|
+
try {
|
|
1513
|
+
ctx.effect(() => ctx.locale.register(NS, FLAT), 'dsh-breeze-tts: dictionaries')
|
|
1514
|
+
const bound = ctx.locale.bind(NS)
|
|
1515
|
+
if (typeof bound === 'function') {
|
|
1516
|
+
t = (key) => {
|
|
1517
|
+
let value
|
|
1518
|
+
try {
|
|
1519
|
+
value = bound(key)
|
|
1520
|
+
} catch {
|
|
1521
|
+
value = undefined
|
|
1522
|
+
}
|
|
1523
|
+
if (typeof value === 'string' && value && value !== key) return value
|
|
1524
|
+
const flat = FLAT.zh[key]
|
|
1525
|
+
return typeof flat === 'string' ? flat : lookup(DICT.zh, key)
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
} catch {
|
|
1529
|
+
t = (key) => lookup(DICT.zh, key)
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
1533
|
+
name: 'settings.section',
|
|
1534
|
+
id: 'breeze-tts',
|
|
1535
|
+
order: 60,
|
|
1536
|
+
locale: NS,
|
|
1537
|
+
label: () => t('section.title'),
|
|
1538
|
+
}, (props) => h(SettingsPage, Object.assign({}, props, { t }))))
|
|
1539
|
+
|
|
1540
|
+
ctx.slots.inject('conversation.chat.assistant-actions', () => ctx.slots.register({
|
|
1541
|
+
name: 'conversation.chat.assistant-actions',
|
|
1542
|
+
id: 'breeze-tts-speak',
|
|
1543
|
+
order: 30,
|
|
1544
|
+
locale: NS,
|
|
1545
|
+
}, (props) => h(SpeakButton, Object.assign({}, props, { t }))))
|
|
1546
|
+
|
|
1547
|
+
ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register({
|
|
1548
|
+
name: 'conversation.composer.dock',
|
|
1549
|
+
id: 'breeze-tts-status',
|
|
1550
|
+
order: 30,
|
|
1551
|
+
locale: NS,
|
|
1552
|
+
}, (props) => h(AutoSpeakChip, Object.assign({}, props, { t }))))
|
|
1553
|
+
},
|
|
1554
|
+
}
|
|
1555
|
+
},
|
|
1556
|
+
})
|