|
@@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.util.Optional;
|
|
|
|
|
@@ -34,12 +36,28 @@ public class VideoTextServiceImpl implements VideoTextService {
|
|
|
//本地文件内容
|
|
|
String filePath = FileUtil.writeFiles(localPath.toString(), url, split[split.length - 1]);
|
|
|
|
|
|
+ Path path = Paths.get(filePath);
|
|
|
+ Path pcmPath = Paths.get(localPath.toString());
|
|
|
+
|
|
|
// 获取 PCM path
|
|
|
- Optional<String> paths = VideoToPCMTool.convertMP4toPCM(Paths.get(filePath), Paths.get(localPath.toString()));
|
|
|
+ Optional<String> paths = VideoToPCMTool.convertMP4toPCM(path, pcmPath);
|
|
|
+ String videoText = null;
|
|
|
if (!Check.isNull(paths)) {
|
|
|
- return ResultResponse.success(VoiceTool.getVideoText(paths.get()));
|
|
|
+ videoText = VoiceTool.getVideoText(paths.get());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ File file = path.toFile();
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ File pcmFile = pcmPath.toFile();
|
|
|
+ if (pcmFile.exists()) {
|
|
|
+ pcmFile.delete();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- return ResultResponse.error("转文本失败");
|
|
|
+ return ResultResponse.success(videoText);
|
|
|
}
|
|
|
|
|
|
}
|