把python代码转为Java, 涉及功能主要是音频转文本

This commit is contained in:
2026-05-02 23:05:30 +08:00
parent 9b791fabd1
commit 7b2691b98f
12 changed files with 519 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
package com.rj.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
/**
* 显式扩大 {@code @Scheduled} 线程池,避免单个耗时任务(如长时间 HTTP占满默认单线程后拖死全部定时任务。
* <p>与 {@code spring.task.scheduling.pool.size} 配置互补;此处代码保证至少 8 个调度线程。
*/
@Configuration
public class AppSchedulingConfiguration implements SchedulingConfigurer {
private static final int SCHEDULER_POOL_SIZE = 8;
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(SCHEDULER_POOL_SIZE);
scheduler.setThreadNamePrefix("app-scheduling-");
scheduler.setWaitForTasksToCompleteOnShutdown(true);
scheduler.setAwaitTerminationSeconds(120);
scheduler.setRemoveOnCancelPolicy(true);
scheduler.initialize();
taskRegistrar.setTaskScheduler(scheduler);
}
}

View File

@@ -0,0 +1,23 @@
package com.rj.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
/**
* 说明 {@link com.rj.scheduler.YihangyiVllmAsrScheduler} 的加载条件,避免与根节点 {@code asr.*} 混淆。
*/
@Slf4j
@Component
@ConditionalOnProperty(name = "app.audio.upload.yihangyi.asr.enabled", havingValue = "false", matchIfMissing = true)
public class YihangyiVllmAsrEnablementListener {
@EventListener(ApplicationReadyEvent.class)
public void onReady() {
log.info(
"YihangyiVllmAsrScheduler 未启用:需设置 app.audio.upload.yihangyi.asr.enabled=true当前为 false 或未配置)。"
+ "根配置 asr.enabled 用于其它 ASR 能力,不会加载本调度类。");
}
}

View File

@@ -0,0 +1,11 @@
package com.rj.config;
/**
* yihangyi 目录轮询 ASR单线程顺序处理或线程池并行处理本批文件。
*/
public enum YihangyiVllmAsrExecutorMode {
/** 同批文件逐个处理(与 Python 脚本一致)。 */
SINGLE,
/** 同批文件提交到固定大小线程池并行处理。 */
POOL
}

View File

@@ -0,0 +1,42 @@
package com.rj.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* vLLM OpenAI 兼容 ASR 轮询配置(对应 Python {@code audio_toText_qwen3_asr_17b_vllm_interface.py})。
*/
@Data
@ConfigurationProperties(prefix = "app.audio.upload.yihangyi.asr")
public class YihangyiVllmAsrProperties {
/** 是否启用定时轮询(默认关闭,避免本地/Windows 误扫生产目录)。 */
private boolean enabled = false;
private String watchDir = "/home/lizh/java_env/AIDriverEEBackend/audio/yihangyi";
private String doneDir = "/home/lizh/java_env/AIDriverEEBackend/audio/yihangyi_finish";
/** 转写 txt 输出目录,与 {@link com.rj.scheduler.AudioStatisticsScheduler} 扫描目录一致。 */
private String txtDir = "/home/lizh/java_env/AIDriverEEBackend/audio/yihangyi_txt";
/** OpenAI 兼容 base-url须含 /v1例如 {@code http://host:17001/v1} */
private String baseUrl = "http://101.35.52.237:17001/v1";
private String apiKey = "EMPTY";
private String model = "Qwen3-ASR-1.7B";
/** 与 Python POLL_INTERVAL_SEC 一致(毫秒)。 */
private long pollIntervalMs = 50000L;
private int maxBatch = 5;
private YihangyiVllmAsrExecutorMode executorMode = YihangyiVllmAsrExecutorMode.SINGLE;
/** executorMode=POOL 时的工作线程数。 */
private int poolSize = 4;
/** 是否在 Windows 上跳过执行(与其它 yihangyi 定时任务一致)。 */
private boolean skipOnWindows = true;
}