@eslaykey/dsh-breeze-tts 1.0.1 → 1.0.2
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/client.js +8 -1
- package/index.js +10 -5
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -13,6 +13,7 @@ window.__ModuleLoader__.load({
|
|
|
13
13
|
tone: { normal: '自然', warm: '温和', formal: '正式', lively: '活泼' },
|
|
14
14
|
|
|
15
15
|
err: {
|
|
16
|
+
server: 'Breeze 服务端暂时不可用或响应超时,请稍后重试',
|
|
16
17
|
auth: 'API key 无效或已失效,请重新填写',
|
|
17
18
|
rate: '请求太频繁,稍等几秒再试',
|
|
18
19
|
credits: '积分余额不足,请先充值或调低每日上限',
|
|
@@ -116,6 +117,7 @@ window.__ModuleLoader__.load({
|
|
|
116
117
|
tone: { normal: 'Natural', warm: 'Warm', formal: 'Formal', lively: 'Lively' },
|
|
117
118
|
|
|
118
119
|
err: {
|
|
120
|
+
server: 'The Breeze service is unavailable or timed out. Try again in a moment.',
|
|
119
121
|
auth: 'The API key is invalid or expired. Please enter it again.',
|
|
120
122
|
rate: 'Too many requests. Wait a few seconds and retry.',
|
|
121
123
|
credits: 'Not enough credits. Top up or lower the daily limit.',
|
|
@@ -274,6 +276,7 @@ window.__ModuleLoader__.load({
|
|
|
274
276
|
if (status === 401 || code === 'AUTH_REQUIRED') return t('err.auth')
|
|
275
277
|
if (status === 429) return t('err.rate')
|
|
276
278
|
if (status === 402 || /credit/i.test(code) || /insufficient/i.test(message)) return t('err.credits')
|
|
279
|
+
if (status >= 500 || /50[234]/.test(message)) return t('err.server')
|
|
277
280
|
if (/at least 3 characters/i.test(message)) return t('err.tooShort')
|
|
278
281
|
if (/daily limit/i.test(message)) return t('err.daily')
|
|
279
282
|
return message
|
|
@@ -759,13 +762,15 @@ function cleanForSpeech(text) {
|
|
|
759
762
|
setCustomMood(String(data.customMood || ''))
|
|
760
763
|
}, [state.data])
|
|
761
764
|
|
|
765
|
+
const hasKey = Boolean(state.data && state.data.hasKey)
|
|
762
766
|
React.useEffect(() => {
|
|
767
|
+
if (!hasKey) return undefined
|
|
763
768
|
let alive = true
|
|
764
769
|
api('/voices')
|
|
765
770
|
.then((data) => { if (alive) setVoices(data.voices || []) })
|
|
766
771
|
.catch(() => { if (alive) setVoices([]) })
|
|
767
772
|
return () => { alive = false }
|
|
768
|
-
}, [])
|
|
773
|
+
}, [hasKey])
|
|
769
774
|
|
|
770
775
|
const data = state.data
|
|
771
776
|
const presets = data && Array.isArray(data.voicePresets) ? data.voicePresets : []
|
|
@@ -794,6 +799,8 @@ function cleanForSpeech(text) {
|
|
|
794
799
|
text: t('extra.keyConnected') + (typeof result.balance === 'number' ? ' · ' + result.balance.toFixed(1) + ' ' + t('status.credits') : ''),
|
|
795
800
|
})
|
|
796
801
|
reload()
|
|
802
|
+
const freshVoices = await api('/voices').catch(() => null)
|
|
803
|
+
if (freshVoices && Array.isArray(freshVoices.voices)) setVoices(freshVoices.voices)
|
|
797
804
|
} catch (error) {
|
|
798
805
|
setConnectNote({ tone: 'error', text: humanError(t, error) })
|
|
799
806
|
}
|
package/index.js
CHANGED
|
@@ -288,11 +288,16 @@ async function callApi(pathname, options = {}) {
|
|
|
288
288
|
if (apiKey) headers['xi-api-key'] = apiKey
|
|
289
289
|
const isForm = typeof FormData !== 'undefined' && body instanceof FormData
|
|
290
290
|
if (body !== undefined && !isForm) headers['content-type'] = 'application/json'
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
291
|
+
let response
|
|
292
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
293
|
+
response = await fetch(url, {
|
|
294
|
+
method,
|
|
295
|
+
headers,
|
|
296
|
+
body: body === undefined ? undefined : isForm ? body : JSON.stringify(body),
|
|
297
|
+
})
|
|
298
|
+
if (response.ok || ![502, 503, 504].includes(response.status)) break
|
|
299
|
+
if (attempt === 0) await new Promise((resolve) => setTimeout(resolve, 1500))
|
|
300
|
+
}
|
|
296
301
|
if (!response.ok) {
|
|
297
302
|
const text = await response.text()
|
|
298
303
|
const parsed = parseJson(text) ?? {}
|
package/package.json
CHANGED