Skip to content

Commit

Permalink
fix(bukkit): create queue based on thread count
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Oct 9, 2024
1 parent 8bf8ed8 commit e843b53
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.givimad.whisperjni.WhisperJNI;
import io.wdsj.asw.bukkit.AdvancedSensitiveWords;
import io.wdsj.asw.bukkit.setting.PluginSettings;
import io.wdsj.asw.bukkit.util.VirtualThreadUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -46,14 +47,16 @@ public WhisperVoiceTranscribeTool() {
LOGGER.info("Using " + maxThread + " thread(s) for voice transcription");
whisperCtx = whisper.init(Paths.get(dataFolder.getPath(), settingsManager.getProperty(PluginSettings.VOICE_MODEL_NAME)));
RejectedExecutionHandler handler = (r, executor) -> LOGGER.info("Rejected execution of transcription task, thread pool is full");
threadPool = new ThreadPoolExecutor(Math.min(coreCount, maxThread),
threadPool = new ThreadPoolExecutor(
maxThread / 2,
maxThread,
settingsManager.getProperty(PluginSettings.VOICE_REALTIME_TRANSCRIBING_THREAD_KEEP_ALIVE),
TimeUnit.SECONDS,
new LinkedBlockingQueue<>(100),
new LinkedBlockingQueue<>(maxThread * 2),
new ThreadFactoryBuilder()
.setNameFormat("ASW Whisper Transcribe Thread-%d")
.setDaemon(true)
.setThreadFactory(VirtualThreadUtils.newVirtualThreadFactoryOrDefault())
.build(),
handler);
threadPool.allowCoreThreadTimeOut(true);
Expand All @@ -67,7 +70,7 @@ public CompletableFuture<String> transcribe(float[] data) {
WhisperFullParams params = new WhisperFullParams();
int result = whisper.full(whisperCtx, params, data, data.length);
if (result != 0) {
throw new RuntimeException("Transcription failed with code " + result);
LOGGER.warning("Transcription failed with code " + result);
}
whisper.fullNSegments(whisperCtx);
return whisper.fullGetSegmentText(whisperCtx,0);
Expand Down

0 comments on commit e843b53

Please sign in to comment.