Commit 0b5beb36 authored by 李秀明's avatar 李秀明

fix: 使用硬编码文件分隔符会导致可移植性问题。

parent 93eaef2b
...@@ -16,7 +16,7 @@ import java.io.*; ...@@ -16,7 +16,7 @@ import java.io.*;
/** /**
* 文档转换工具 * 文档转换工具
* *
* @date * @date
* @author nihuanshan * @author nihuanshan
* *
...@@ -26,11 +26,11 @@ public class WordConverterUtils { ...@@ -26,11 +26,11 @@ public class WordConverterUtils {
/** /**
* 图片存储相对文档路径 * 图片存储相对文档路径
*/ */
private static String imgPath = "\\image\\"; private static String imgPath = File.separator + "image" + File.separator;
/** /**
* word文档转html文档 * word文档转html文档
* *
* @author: nihuanshan * @author: nihuanshan
* @date: 2018年12月6日 下午2:55:32 * @date: 2018年12月6日 下午2:55:32
* @param srcFile 原文档 * @param srcFile 原文档
...@@ -50,7 +50,7 @@ public class WordConverterUtils { ...@@ -50,7 +50,7 @@ public class WordConverterUtils {
} }
} }
} }
/** /**
* word转html字符串 * word转html字符串
* @param srcFile * @param srcFile
...@@ -69,7 +69,7 @@ public class WordConverterUtils { ...@@ -69,7 +69,7 @@ public class WordConverterUtils {
/** /**
* .doc文档转换成html * .doc文档转换成html
* *
* @author: nihuanshan * @author: nihuanshan
* @date: 2018年12月6日 下午2:53:43 * @date: 2018年12月6日 下午2:53:43
* @param srcFile * @param srcFile
...@@ -114,7 +114,7 @@ public class WordConverterUtils { ...@@ -114,7 +114,7 @@ public class WordConverterUtils {
} }
} }
/** /**
* doc转htmlString * doc转htmlString
* @param srcFile * @param srcFile
...@@ -156,7 +156,7 @@ public class WordConverterUtils { ...@@ -156,7 +156,7 @@ public class WordConverterUtils {
serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, streamResult); serializer.transform(domSource, streamResult);
return stringWriter.toString(); return stringWriter.toString();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -205,9 +205,9 @@ public class WordConverterUtils { ...@@ -205,9 +205,9 @@ public class WordConverterUtils {
} }
} }
/** /**
*docx转htmlString *docx转htmlString
* @param srcFile * @param srcFile
* @param readUrl * @param readUrl
* @return * @return
......
...@@ -24,7 +24,7 @@ public class WordConverterUtils { ...@@ -24,7 +24,7 @@ public class WordConverterUtils {
/** /**
* 图片存储相对文档路径 * 图片存储相对文档路径
*/ */
private static String imgPath = "\\image\\"; private static String imgPath = File.separator + "image" + File.separator;
/** /**
* word文档转html文档 * word文档转html文档
......
...@@ -16,7 +16,7 @@ import java.io.*; ...@@ -16,7 +16,7 @@ import java.io.*;
/** /**
* 文档转换工具 * 文档转换工具
* *
* @date * @date
* @author nihuanshan * @author nihuanshan
* *
...@@ -26,11 +26,11 @@ public class WordConverterUtils { ...@@ -26,11 +26,11 @@ public class WordConverterUtils {
/** /**
* 图片存储相对文档路径 * 图片存储相对文档路径
*/ */
private static String imgPath = "\\image\\"; private static String imgPath = File.separator + "image" + File.separator;
/** /**
* word文档转html文档 * word文档转html文档
* *
* @author: nihuanshan * @author: nihuanshan
* @date: 2018年12月6日 下午2:55:32 * @date: 2018年12月6日 下午2:55:32
* @param srcFile 原文档 * @param srcFile 原文档
...@@ -50,7 +50,7 @@ public class WordConverterUtils { ...@@ -50,7 +50,7 @@ public class WordConverterUtils {
} }
} }
} }
/** /**
* word转html字符串 * word转html字符串
* @param srcFile * @param srcFile
...@@ -69,7 +69,7 @@ public class WordConverterUtils { ...@@ -69,7 +69,7 @@ public class WordConverterUtils {
/** /**
* .doc文档转换成html * .doc文档转换成html
* *
* @author: nihuanshan * @author: nihuanshan
* @date: 2018年12月6日 下午2:53:43 * @date: 2018年12月6日 下午2:53:43
* @param srcFile * @param srcFile
...@@ -114,7 +114,7 @@ public class WordConverterUtils { ...@@ -114,7 +114,7 @@ public class WordConverterUtils {
} }
} }
/** /**
* doc转htmlString * doc转htmlString
* @param srcFile * @param srcFile
...@@ -156,7 +156,7 @@ public class WordConverterUtils { ...@@ -156,7 +156,7 @@ public class WordConverterUtils {
serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, streamResult); serializer.transform(domSource, streamResult);
return stringWriter.toString(); return stringWriter.toString();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -205,9 +205,9 @@ public class WordConverterUtils { ...@@ -205,9 +205,9 @@ public class WordConverterUtils {
} }
} }
/** /**
*docx转htmlString *docx转htmlString
* @param srcFile * @param srcFile
* @param readUrl * @param readUrl
* @return * @return
......
...@@ -5,7 +5,6 @@ import org.slf4j.LoggerFactory; ...@@ -5,7 +5,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.*; import java.net.*;
...@@ -20,9 +19,9 @@ import static com.yeejoin.amos.boot.module.jcs.biz.audioToText.util.SpeechTransc ...@@ -20,9 +19,9 @@ import static com.yeejoin.amos.boot.module.jcs.biz.audioToText.util.SpeechTransc
public class SocketClient { public class SocketClient {
private static final Logger logger = LoggerFactory.getLogger(SocketClient.class); private static final Logger logger = LoggerFactory.getLogger(SocketClient.class);
private static final String[] testFilePath = { private static final String[] testFilePath = {
"C:\\Users\\DELL\\Desktop\\yuyin\\out1.pcm", // * 此处写的文件路径地址不要提交到git, 国网电科院SCA扫描会报告为漏洞: 存在“便携性缺陷”
"C:\\Users\\DELL\\Desktop\\yuyin\\out.pcm",
}; };
private static final String filePath = ""; // * 此处写的文件路径地址不要提交到git, 国网电科院SCA扫描会报告为漏洞: 存在“便携性缺陷”
public static void main(String[] args) throws SocketException { public static void main(String[] args) throws SocketException {
SocketClient socketClient = new SocketClient(); SocketClient socketClient = new SocketClient();
...@@ -35,15 +34,15 @@ public class SocketClient { ...@@ -35,15 +34,15 @@ public class SocketClient {
if (type >= testFilePath.length) type -= 1; if (type >= testFilePath.length) type -= 1;
try (DatagramSocket datagramSocket = new DatagramSocket(); try (DatagramSocket datagramSocket = new DatagramSocket();
FileInputStream fis = new FileInputStream(new File("C:\\Users\\DELL\\Desktop\\ffmpeg-4.4-full_build-shared\\bin\\out.pcm"));) { FileInputStream fis = new FileInputStream(filePath);) {
byte[] b = new byte[1280]; byte[] b = new byte[1280];
int len; int len;
while ((len = fis.read(b)) > 0) { while ((len = fis.read(b)) > 0) {
String logs= String.format("send data pack length: %s",len); String logs = String.format("send data pack length: %s", len);
logger.error( logs); logger.error(logs);
datagramSocket.send(new DatagramPacket(b, b.length,InetAddress.getLocalHost(), port)); datagramSocket.send(new DatagramPacket(b, b.length, InetAddress.getLocalHost(), port));
int deltaSleep = getSleepDelta(len, 16000); int deltaSleep = getSleepDelta(len, 16000);
Thread.sleep(deltaSleep); Thread.sleep(deltaSleep);
TimeUnit.MILLISECONDS.sleep(100); TimeUnit.MILLISECONDS.sleep(100);
...@@ -60,17 +59,14 @@ public class SocketClient { ...@@ -60,17 +59,14 @@ public class SocketClient {
if (type >= testFilePath.length) type -= 1; if (type >= testFilePath.length) type -= 1;
try (Socket socket = new Socket(); try (Socket socket = new Socket();
FileInputStream fis = new FileInputStream(new File(testFilePath[type]));) { FileInputStream fis = new FileInputStream(testFilePath[type]);) {
socket.connect(new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port)); socket.connect(new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port));
OutputStream outputStream = socket.getOutputStream(); OutputStream outputStream = socket.getOutputStream();
byte[] b = new byte[4096]; byte[] b = new byte[4096];
int len; int len;
while ((len = fis.read(b)) > 0) { while ((len = fis.read(b)) > 0) {
String logs = String.format("send data pack length: %s", len);
logger.error(logs);
String logs= String.format("send data pack length: %s",len);
logger.error( logs);
outputStream.write(b); outputStream.write(b);
TimeUnit.MILLISECONDS.sleep(200); TimeUnit.MILLISECONDS.sleep(200);
} }
......
...@@ -220,7 +220,7 @@ public class SpeechTranscriberDemo { ...@@ -220,7 +220,7 @@ public class SpeechTranscriberDemo {
System.exit(-1); System.exit(-1);
}*/ }*/
//本案例使用本地文件模拟发送实时流数据。您在实际使用时,可以实时采集或接收语音流并发送到ASR服务端。 //本案例使用本地文件模拟发送实时流数据。您在实际使用时,可以实时采集或接收语音流并发送到ASR服务端。
String filepath = "C:\\Users\\DELL\\Desktop\\ffmpeg-4.4-full_build-shared\\bin\\1839.pcm"; String filepath = ""; // * 此处写的文件路径地址不要提交到git, 国网电科院SCA扫描会报告为漏洞: 存在“便携性缺陷”
SpeechTranscriberDemo demo = new SpeechTranscriberDemo(appKey, id, secret, url); SpeechTranscriberDemo demo = new SpeechTranscriberDemo(appKey, id, secret, url);
demo.process(filepath); demo.process(filepath);
demo.shutdown(); demo.shutdown();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment