Skip to content

Commit 4c4094a

Browse files
authored
Refine chunk estimation logic for text processing
Updated chunk estimation logic for different text lengths to provide more generous estimates. Adjusted bounds for current job estimation.
1 parent 69e5698 commit 4c4094a

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

main.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,18 @@ const onMessageReceived = async (e) => {
146146
const wordsLength = textLength.split(' ').length;
147147

148148
// Calculate estimation based on text characteristics
149+
// More generous estimates for semantic-split.js chunking
149150
let estimatedTotalChunks;
150151
if (textLength < 500) {
151-
estimatedTotalChunks = Math.max(5, Math.ceil(wordsLength * 0.8)); // Short text
152+
estimatedTotalChunks = Math.max(6, Math.ceil(wordsLength * 1.8)); // Short text - more generous
152153
} else if (textLength < 2000) {
153-
estimatedTotalChunks = Math.max(8, Math.ceil(wordsLength * 1.0)); // Medium text
154+
estimatedTotalChunks = Math.max(10, Math.ceil(wordsLength * 2.2)); // Medium text - more generous
154155
} else {
155-
estimatedTotalChunks = Math.max(12, Math.ceil(wordsLength * 1.2)); // Long text
156+
estimatedTotalChunks = Math.max(15, Math.ceil(wordsLength * 2.8)); // Long text - more generous
156157
}
157158

158159
// Ensure reasonable bounds
159-
currentJobEstimation = Math.min(estimatedTotalChunks, 150);
160+
currentJobEstimation = Math.min(Math.max(estimatedTotalChunks, 12), 200);
160161

161162
console.log(`Job ${currentQueueJobId}: ${textLength} chars, ${wordsLength} words → est. ${currentJobEstimation} chunks`);
162163
} else {
@@ -207,6 +208,10 @@ const onMessageReceived = async (e) => {
207208
// Queue job complete
208209
console.log(`Queue job ${currentQueueJobId} complete with ${audioChunksForQueue.length} chunks`);
209210

211+
// Update final progress to 100% before completing
212+
const finalChunkNum = audioChunksForQueue.length;
213+
await queueManager.updateJobProgress(currentQueueJobId, 100, finalChunkNum, currentJobEstimation);
214+
210215
// Mark job as complete with audio data
211216
await queueManager.jobComplete(currentQueueJobId, audioChunksForQueue, true);
212217

0 commit comments

Comments
 (0)