fix(voices): rename archetype say helper to avoid global collision
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2a06d0a488
commit
b7cfe056a3
2
static/dist/main.min.js
vendored
2
static/dist/main.min.js
vendored
File diff suppressed because one or more lines are too long
@ -17,7 +17,7 @@ const st = { gender: '', age: '', pitch: '', accent: '', language: '', category:
|
|||||||
let favs = new Set(), booted = false, token = 0, objUrl = '';
|
let favs = new Set(), booted = false, token = 0, objUrl = '';
|
||||||
try { favs = new Set(JSON.parse(localStorage.getItem(FAV_KEY) || '[]')); } catch (_) {}
|
try { favs = new Set(JSON.parse(localStorage.getItem(FAV_KEY) || '[]')); } catch (_) {}
|
||||||
const saveFavs = () => { try { localStorage.setItem(FAV_KEY, JSON.stringify([...favs])); } catch (_) {} };
|
const saveFavs = () => { try { localStorage.setItem(FAV_KEY, JSON.stringify([...favs])); } catch (_) {} };
|
||||||
const say = m => { $a('arch-status').textContent = m; };
|
const archSay = m => { $a('arch-status').textContent = m; };
|
||||||
const lang = () => (window.__APP_LANG__ === 'de' ? 'de' : 'en');
|
const lang = () => (window.__APP_LANG__ === 'de' ? 'de' : 'en');
|
||||||
|
|
||||||
function buildChips() {
|
function buildChips() {
|
||||||
@ -73,7 +73,7 @@ async function load(reset) {
|
|||||||
if (reset) { st.offset = 0; $a('arch-grid').textContent = ''; }
|
if (reset) { st.offset = 0; $a('arch-grid').textContent = ''; }
|
||||||
const q = new URLSearchParams({ offset: st.offset, limit: st.favOnly ? 100 : PAGE });
|
const q = new URLSearchParams({ offset: st.offset, limit: st.favOnly ? 100 : PAGE });
|
||||||
['gender', 'age', 'pitch', 'accent', 'language', 'category', 'q'].forEach(k => st[k] && q.set(k, st[k]));
|
['gender', 'age', 'pitch', 'accent', 'language', 'category', 'q'].forEach(k => st[k] && q.set(k, st[k]));
|
||||||
say(tr('Loading…'));
|
archSay(tr('Loading…'));
|
||||||
try {
|
try {
|
||||||
const r = await fetch('/api/archetypes?' + q);
|
const r = await fetch('/api/archetypes?' + q);
|
||||||
if (!r.ok) throw new Error(r.statusText);
|
if (!r.ok) throw new Error(r.statusText);
|
||||||
@ -88,30 +88,30 @@ async function load(reset) {
|
|||||||
items.forEach(a => grid.appendChild(card(a)));
|
items.forEach(a => grid.appendChild(card(a)));
|
||||||
st.offset += d.items.length; st.total = d.total;
|
st.offset += d.items.length; st.total = d.total;
|
||||||
$a('arch-more').hidden = st.favOnly || st.offset >= d.total;
|
$a('arch-more').hidden = st.favOnly || st.offset >= d.total;
|
||||||
say(grid.children.length ? grid.children.length + ' / ' + (st.favOnly ? grid.children.length : d.total) : tr('No voices match.'));
|
archSay(grid.children.length ? grid.children.length + ' / ' + (st.favOnly ? grid.children.length : d.total) : tr('No voices match.'));
|
||||||
} catch (e) { if (my === token) say(tr('Could not load the gallery.')); }
|
} catch (e) { if (my === token) archSay(tr('Could not load the gallery.')); }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function play(a, btn) {
|
async function play(a, btn) {
|
||||||
btn.disabled = true; say(tr('Rendering preview…'));
|
btn.disabled = true; archSay(tr('Rendering preview…'));
|
||||||
try {
|
try {
|
||||||
const r = await fetch('/api/archetypes/' + encodeURIComponent(a) + '/preview', { method: 'POST' });
|
const r = await fetch('/api/archetypes/' + encodeURIComponent(a) + '/preview', { method: 'POST' });
|
||||||
if (!r.ok) { const e = await r.json().catch(() => ({})); throw new Error(e.detail || r.statusText); }
|
if (!r.ok) { const e = await r.json().catch(() => ({})); throw new Error(e.detail || r.statusText); }
|
||||||
if (objUrl) URL.revokeObjectURL(objUrl);
|
if (objUrl) URL.revokeObjectURL(objUrl);
|
||||||
objUrl = URL.createObjectURL(await r.blob());
|
objUrl = URL.createObjectURL(await r.blob());
|
||||||
const au = $a('arch-audio'); au.src = objUrl; await au.play().catch(() => {});
|
const au = $a('arch-audio'); au.src = objUrl; await au.play().catch(() => {});
|
||||||
say(tr('Preview ready'));
|
archSay(tr('Preview ready'));
|
||||||
} catch (e) { say(tr('Preview failed') + ': ' + e.message); }
|
} catch (e) { archSay(tr('Preview failed') + ': ' + e.message); }
|
||||||
finally { btn.disabled = false; }
|
finally { btn.disabled = false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function use(id, btn) {
|
async function use(id, btn) {
|
||||||
btn.disabled = true; say(tr('Saving voice…'));
|
btn.disabled = true; archSay(tr('Saving voice…'));
|
||||||
try {
|
try {
|
||||||
const r = await fetch('/api/archetypes/' + encodeURIComponent(id) + '/use', { method: 'POST' });
|
const r = await fetch('/api/archetypes/' + encodeURIComponent(id) + '/use', { method: 'POST' });
|
||||||
if (!r.ok) { const e = await r.json().catch(() => ({})); throw new Error(e.detail || r.statusText); }
|
if (!r.ok) { const e = await r.json().catch(() => ({})); throw new Error(e.detail || r.statusText); }
|
||||||
const d = await r.json();
|
const d = await r.json();
|
||||||
say(tr('Voice saved') + ': ' + d.voice_id);
|
archSay(tr('Voice saved') + ': ' + d.voice_id);
|
||||||
if (typeof toast === 'function') toast(tr('Voice saved') + ': ' + d.voice_id, 'success');
|
if (typeof toast === 'function') toast(tr('Voice saved') + ': ' + d.voice_id, 'success');
|
||||||
if (!btn.parentNode.querySelector('.arch-open')) {
|
if (!btn.parentNode.querySelector('.arch-open')) {
|
||||||
const o = document.createElement('button'); o.type = 'button'; o.className = 'btn-secondary arch-open';
|
const o = document.createElement('button'); o.type = 'button'; o.className = 'btn-secondary arch-open';
|
||||||
@ -119,7 +119,7 @@ async function use(id, btn) {
|
|||||||
btn.parentNode.insertBefore(o, btn.nextSibling); o.focus();
|
btn.parentNode.insertBefore(o, btn.nextSibling); o.focus();
|
||||||
}
|
}
|
||||||
if (typeof loadVoiceLibrary === 'function') loadVoiceLibrary().catch(() => {});
|
if (typeof loadVoiceLibrary === 'function') loadVoiceLibrary().catch(() => {});
|
||||||
} catch (e) { say(tr('Save failed') + ': ' + e.message); if (typeof toast === 'function') toast(e.message, 'error'); }
|
} catch (e) { archSay(tr('Save failed') + ': ' + e.message); if (typeof toast === 'function') toast(e.message, 'error'); }
|
||||||
finally { btn.disabled = false; }
|
finally { btn.disabled = false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user