Export split setting
Avoids the 1GB file limit imposed by browsers and also lowers memory requirements per exported block.
This commit is contained in:
1 parent
70d385133d
commit
c1bc1f26cd
1 file changed
+55
-30
@@ -602,6 +602,15 @@
|
|||||||
<button onclick="exportToJSON()" style="margin-right: 10px;">Export List as JSON</button>
|
<button onclick="exportToJSON()" style="margin-right: 10px;">Export List as JSON</button>
|
||||||
<button onclick="importFromJSON()" style="margin-right: 10px;">Import JSON to list</button>
|
<button onclick="importFromJSON()" style="margin-right: 10px;">Import JSON to list</button>
|
||||||
<button onclick="exportMP3()" style="margin-right: 10px;">Export to Wav</button>
|
<button onclick="exportMP3()" style="margin-right: 10px;">Export to Wav</button>
|
||||||
|
<label for="splitEvery">Split every:</label>
|
||||||
|
<select id="splitEvery" name="splitEvery">
|
||||||
|
<option value="100">100</option>
|
||||||
|
<option value="200">200</option>
|
||||||
|
<option value="300">300</option>
|
||||||
|
<option value="400">400</option>
|
||||||
|
<option value="500" selected>500</option>
|
||||||
|
<option value="600">600</option>
|
||||||
|
</select>
|
||||||
<div id="paginationControls">
|
<div id="paginationControls">
|
||||||
<button id="prevPage" class="pagination-btn">Previous</button>
|
<button id="prevPage" class="pagination-btn">Previous</button>
|
||||||
<span id="pageIndicator">Page 1 of X</span>
|
<span id="pageIndicator">Page 1 of X</span>
|
||||||
@@ -625,45 +634,61 @@
|
|||||||
<!-- Howler.js script inclusion -->
|
<!-- Howler.js script inclusion -->
|
||||||
<script src="./howler.min.js"></script>
|
<script src="./howler.min.js"></script>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
// Import Crunker from the CDN
|
|
||||||
import Crunker from './crunker.esm.js';
|
import Crunker from './crunker.esm.js';
|
||||||
|
|
||||||
async function exportMP3() {
|
async function exportMP3() {
|
||||||
const crunker = new Crunker();
|
const crunker = new Crunker();
|
||||||
const fileUrls = ttsList.map(item => item.fileUrl);
|
const fileUrls = ttsList.map(item => item.fileUrl);
|
||||||
const progressIndicator = document.getElementById('progressIndicator');
|
const splitEvery = parseInt(document.getElementById('splitEvery').value) || 500;
|
||||||
const progressText = document.getElementById('progressText');
|
const progressIndicator = document.getElementById('progressIndicator');
|
||||||
|
const progressText = document.getElementById('progressText');
|
||||||
|
|
||||||
// Show progress indicator and update text
|
if (progressIndicator && progressText) {
|
||||||
if (progressIndicator && progressText) {
|
progressIndicator.style.display = 'block';
|
||||||
progressText.textContent = 'Export';
|
progressText.textContent = 'Starting export...';
|
||||||
progressText.style.color = 'black'; // Set the text color to black
|
|
||||||
progressIndicator.style.display = 'block';
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const audioBuffers = await crunker.fetchAudio(...fileUrls);
|
|
||||||
const combined = crunker.concatAudio(audioBuffers);
|
|
||||||
const output = crunker.export(combined, "audio/wav");
|
|
||||||
crunker.download(output.blob, "combined_audio"); // This will download the file as 'combined_audio.mp3'
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error combining files:', error);
|
|
||||||
if (progressText) {
|
|
||||||
progressText.textContent = 'Error during export!';
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
// Hide progress indicator after completion or error
|
|
||||||
if (progressIndicator) {
|
|
||||||
progressIndicator.style.display = 'none';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach exportMP3 to the window object to make it globally accessible
|
try {
|
||||||
window.exportMP3 = exportMP3;
|
for (let i = 0; i < fileUrls.length; i += splitEvery) {
|
||||||
|
const currentBatch = Math.floor(i / splitEvery) + 1;
|
||||||
|
const totalBatches = Math.ceil(fileUrls.length / splitEvery);
|
||||||
|
if (progressText) {
|
||||||
|
progressText.textContent = `Processing batch ${currentBatch} of ${totalBatches}`;
|
||||||
|
progressText.style.color = 'black'; // Set the text color to black
|
||||||
|
}
|
||||||
|
|
||||||
|
const batchUrls = fileUrls.slice(i, Math.min(i + splitEvery, fileUrls.length));
|
||||||
|
const audioBuffers = await crunker.fetchAudio(...batchUrls);
|
||||||
|
const combined = crunker.concatAudio(audioBuffers);
|
||||||
|
const output = crunker.export(combined, "audio/wav");
|
||||||
|
crunker.download(output.blob, `combined_audio_part_${currentBatch}.wav`);
|
||||||
|
|
||||||
|
// Clear audioBuffers array to free up memory
|
||||||
|
audioBuffers.length = 0;
|
||||||
|
|
||||||
|
console.log(`Exported batch ${currentBatch} of ${totalBatches}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error combining files:', error);
|
||||||
|
if (progressText) {
|
||||||
|
progressText.textContent = 'Error during export!';
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (progressIndicator && progressText) {
|
||||||
|
progressIndicator.style.display = 'none';
|
||||||
|
progressText.textContent = ''; // Reset progress text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.exportMP3 = exportMP3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
|||||||
Reference in new issue
Block a user