fix: voice upload Base64 conversion (chunked, no stack overflow)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+26
-7
@@ -1252,30 +1252,49 @@
|
|||||||
sendToRVS_raw({ type: 'xtts_list_voices', payload: {}, timestamp: Date.now() });
|
sendToRVS_raw({ type: 'xtts_list_voices', payload: {}, timestamp: Date.now() });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function arrayBufferToBase64(buffer) {
|
||||||
|
const bytes = new Uint8Array(buffer);
|
||||||
|
let binary = '';
|
||||||
|
for (let i = 0; i < bytes.length; i += 8192) {
|
||||||
|
binary += String.fromCharCode.apply(null, bytes.subarray(i, i + 8192));
|
||||||
|
}
|
||||||
|
return btoa(binary);
|
||||||
|
}
|
||||||
|
|
||||||
async function uploadVoiceSamples() {
|
async function uploadVoiceSamples() {
|
||||||
const name = document.getElementById('xtts-clone-name').value.trim();
|
const name = document.getElementById('xtts-clone-name').value.trim();
|
||||||
const files = document.getElementById('xtts-clone-files').files;
|
const files = document.getElementById('xtts-clone-files').files;
|
||||||
if (!name) { alert('Bitte einen Namen eingeben'); return; }
|
if (!name) { alert('Bitte einen Namen eingeben'); return; }
|
||||||
if (!files || files.length === 0) { alert('Bitte Audio-Dateien auswaehlen'); return; }
|
if (!files || files.length === 0) { alert('Bitte Audio-Dateien auswaehlen'); return; }
|
||||||
|
if (files.length > 10) { alert('Maximal 10 Dateien'); return; }
|
||||||
|
|
||||||
document.getElementById('xtts-clone-status').textContent = `Lade ${files.length} Datei(en) hoch...`;
|
const status = document.getElementById('xtts-clone-status');
|
||||||
|
status.textContent = `Lade ${files.length} Datei(en)...`;
|
||||||
|
status.style.color = '#FFD60A';
|
||||||
|
|
||||||
|
try {
|
||||||
const samples = [];
|
const samples = [];
|
||||||
for (const file of files) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const buffer = await file.arrayBuffer();
|
status.textContent = `Lese Datei ${i + 1}/${files.length}: ${files[i].name}...`;
|
||||||
const base64 = btoa(String.fromCharCode(...new Uint8Array(buffer)));
|
const buffer = await files[i].arrayBuffer();
|
||||||
samples.push({ base64, name: file.name, size: file.size });
|
const base64 = arrayBufferToBase64(buffer);
|
||||||
|
samples.push({ base64, name: files[i].name, size: files[i].size });
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalSize = samples.reduce((s, f) => s + f.size, 0);
|
const totalSize = samples.reduce((s, f) => s + f.size, 0);
|
||||||
document.getElementById('xtts-clone-status').textContent =
|
status.textContent = `Sende ${samples.length} Sample(s) (${(totalSize / 1024).toFixed(0)}KB)...`;
|
||||||
`Sende ${samples.length} Sample(s) (${(totalSize / 1024).toFixed(0)}KB) an XTTS-Server...`;
|
|
||||||
|
|
||||||
sendToRVS_raw({
|
sendToRVS_raw({
|
||||||
type: 'voice_upload',
|
type: 'voice_upload',
|
||||||
payload: { name, samples },
|
payload: { name, samples },
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
status.textContent = `Gesendet — warte auf Bestaetigung vom XTTS-Server...`;
|
||||||
|
} catch (err) {
|
||||||
|
status.textContent = `Fehler: ${err.message}`;
|
||||||
|
status.style.color = '#FF3B30';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Abbrechen ──────────────────────────────
|
// ── Abbrechen ──────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user