Skip to content

Commit

Permalink
change counting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 31, 2024
1 parent 8ac85b2 commit 4c758df
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions server/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,31 +1100,40 @@ export class Room {
// The parallelism should ideally depend on the server configuration
// But we just need a value that won't take more than 5 minutes between start and stop because fetch will timeout
// No good way of configuring it right now without switching to undici
const results = Array(items.length);
Array(numWorkers).fill('').forEach(async () => {
let success = 0;
let count = 0;
Array(numWorkers).fill('').forEach(async (_, workerIndex) => {
for (let [i, text] of cursor) {
const url = await genAITextToSpeech(rvcHost, text ?? '');
// Report progress back in chat messages
if (url) {
this.addChatMessage(undefined, {
id: '',
name: 'System',
msg: 'generated ai voice ' + i + ': ' + url,
});
redisCount('aiVoice');
results[i] = url;
try {
const url = await genAITextToSpeech(rvcHost, text ?? '');
// Report progress back in chat messages
if (url) {
this.addChatMessage(undefined, {
id: '',
name: 'System',
msg: 'generated ai voice ' + i + ': ' + url,
});
redisCount('aiVoice');
success += 1;
}
count += 1;
} catch (e) {
// Log errors, but continue iterating
console.log(e);
}
}
});
const end = Date.now();
this.addChatMessage(undefined, {
id: '',
name: 'System',
msg:
results.filter(Boolean).length +
'/' +
results.length +
' voices generated in ' + (end - start) + ' ms',
if (workerIndex === 0) {
const end = Date.now();
this.addChatMessage(undefined, {
id: '',
name: 'System',
msg:
success +
'/' +
count +
' voices generated in ' + (end - start) + 'ms',
});
}
});
}
}
Expand Down

0 comments on commit 4c758df

Please sign in to comment.