mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-11 20:28:56 +00:00
【人脸识别】 新增多种人脸识别模型
【底层优化】 支持自由选择 OpenCV 或 BufferedImage 作为图像引擎 【通用图像】 全部模型启用 Image 输入,支持各类图片格式与 Image 的互转 【模型管理】 优化模型生命周期,关闭后可重新创建 【人脸识别】 支持在人脸查询结果中绘制姓名标注 【人脸检测】 新增人脸裁剪功能 【修复】 修复若干已知问题,提升系统稳定性
This commit is contained in:
@@ -89,6 +89,7 @@ public class SpeechRecognizerFactory {
|
||||
throw new AsrException(e);
|
||||
}
|
||||
model.loadModel(config);
|
||||
model.setFromFactory(true);
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -100,4 +101,26 @@ public class SpeechRecognizerFactory {
|
||||
log.debug("缓存目录:{}", Config.getCachePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭所有已加载的模型
|
||||
*/
|
||||
public void closeAll() {
|
||||
modelMap.values().forEach(model -> {
|
||||
try {
|
||||
model.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
modelMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除缓存的模型
|
||||
* @param modelEnum
|
||||
*/
|
||||
public static void removeFromCache(AsrModelEnum modelEnum) {
|
||||
modelMap.remove(modelEnum);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,4 +45,7 @@ public interface SpeechRecognizer extends AutoCloseable{
|
||||
throw new UnsupportedOperationException("默认不支持该功能");
|
||||
}
|
||||
|
||||
default void setFromFactory(boolean fromFactory){
|
||||
throw new UnsupportedOperationException("默认不支持该功能");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import cn.smartjavaai.speech.asr.audio.SmartAudioFactory;
|
||||
import cn.smartjavaai.speech.asr.config.AsrModelConfig;
|
||||
import cn.smartjavaai.speech.asr.entity.*;
|
||||
import cn.smartjavaai.speech.asr.exception.AsrException;
|
||||
import cn.smartjavaai.speech.asr.factory.SpeechRecognizerFactory;
|
||||
import cn.smartjavaai.speech.asr.pool.WhisperStatePool;
|
||||
import cn.smartjavaai.speech.utils.AudioUtils;
|
||||
import com.google.gson.JsonArray;
|
||||
@@ -50,8 +51,11 @@ public class VoskRecognizer implements SpeechRecognizer{
|
||||
|
||||
private Model model;
|
||||
|
||||
private AsrModelConfig config;
|
||||
|
||||
@Override
|
||||
public void loadModel(AsrModelConfig config) {
|
||||
this.config = config;
|
||||
if(StringUtils.isBlank(config.getModelPath())){
|
||||
throw new AsrException("modelPath is null");
|
||||
}
|
||||
@@ -320,6 +324,9 @@ public class VoskRecognizer implements SpeechRecognizer{
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if (fromFactory) {
|
||||
SpeechRecognizerFactory.removeFromCache(config.getModelEnum());
|
||||
}
|
||||
if(model != null){
|
||||
model.close();
|
||||
}
|
||||
@@ -339,4 +346,13 @@ public class VoskRecognizer implements SpeechRecognizer{
|
||||
}
|
||||
|
||||
|
||||
private boolean fromFactory = false;
|
||||
|
||||
@Override
|
||||
public void setFromFactory(boolean fromFactory) {
|
||||
this.fromFactory = fromFactory;
|
||||
}
|
||||
public boolean isFromFactory() {
|
||||
return fromFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import cn.smartjavaai.speech.asr.entity.AsrSegment;
|
||||
import cn.smartjavaai.speech.asr.entity.RecParams;
|
||||
import cn.smartjavaai.speech.asr.entity.WhisperParams;
|
||||
import cn.smartjavaai.speech.asr.exception.AsrException;
|
||||
import cn.smartjavaai.speech.asr.factory.SpeechRecognizerFactory;
|
||||
import cn.smartjavaai.speech.asr.pool.WhisperStatePool;
|
||||
import io.github.givimad.whisperjni.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -41,8 +42,11 @@ public class WhisperRecognizer implements SpeechRecognizer{
|
||||
|
||||
private WhisperStatePool statePool;
|
||||
|
||||
private AsrModelConfig config;
|
||||
|
||||
@Override
|
||||
public void loadModel(AsrModelConfig config) {
|
||||
this.config = config;
|
||||
if(StringUtils.isBlank(config.getModelPath())){
|
||||
throw new AsrException("modelPath is null");
|
||||
}
|
||||
@@ -185,6 +189,9 @@ public class WhisperRecognizer implements SpeechRecognizer{
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
if (fromFactory) {
|
||||
SpeechRecognizerFactory.removeFromCache(config.getModelEnum());
|
||||
}
|
||||
if(statePool != null){
|
||||
statePool.close();
|
||||
}
|
||||
@@ -216,4 +223,14 @@ public class WhisperRecognizer implements SpeechRecognizer{
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private boolean fromFactory = false;
|
||||
|
||||
@Override
|
||||
public void setFromFactory(boolean fromFactory) {
|
||||
this.fromFactory = fromFactory;
|
||||
}
|
||||
public boolean isFromFactory() {
|
||||
return fromFactory;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user