Commit 28a50d86 authored by 周亚武's avatar 周亚武

修改合并mp3文件规则

parent 90d6464f
...@@ -308,26 +308,26 @@ ...@@ -308,26 +308,26 @@
</configuration> </configuration>
</execution> </execution>
<execution> <!-- <execution>-->
<id>copy-sound</id> <!-- <id>copy-sound</id>-->
<phase>package</phase> <!-- <phase>package</phase>-->
<goals> <!-- <goals>-->
<goal>copy-resources</goal> <!-- <goal>copy-resources</goal>-->
</goals> <!-- </goals>-->
<configuration> <!-- <configuration>-->
<encoding>UTF-8</encoding> <!-- <encoding>UTF-8</encoding>-->
<outputDirectory>dist/${project.artifactId}/sound</outputDirectory> <!-- <outputDirectory>dist/${project.artifactId}/sound</outputDirectory>-->
<resources> <!-- <resources>-->
<resource> <!-- <resource>-->
<directory>src/main/resources/</directory> <!-- <directory>src/main/resources/</directory>-->
<includes> <!-- <includes>-->
<include>sound/**</include> <!-- <include>sound/**</include>-->
</includes> <!-- </includes>-->
<filtering>true</filtering> <!-- <filtering>true</filtering>-->
</resource> <!-- </resource>-->
</resources> <!-- </resources>-->
</configuration> <!-- </configuration>-->
</execution> <!-- </execution>-->
<execution> <execution>
......
...@@ -322,19 +322,19 @@ public class MainWindow { ...@@ -322,19 +322,19 @@ public class MainWindow {
while (true){ // while (true){
try { // try {
Thread.sleep(2000); // Thread.sleep(2000);
} catch (InterruptedException e) { // } catch (InterruptedException e) {
throw new RuntimeException(e); // throw new RuntimeException(e);
} // }
//
FlowNumBean flowNumBean = new FlowNumBean(6, "A00"+(msgIndex%100), "010", "010", System.currentTimeMillis()); // FlowNumBean flowNumBean = new FlowNumBean(6, "A00"+(msgIndex%100), "010", "010", System.currentTimeMillis());
pushRabbitMsg("请"+flowNumBean.getFlownum()+"号到"+flowNumBean.getWindowfromnum()+"号窗口"); // pushRabbitMsg("请"+flowNumBean.getFlownum()+"号到"+flowNumBean.getWindowfromnum()+"号窗口");
test(flowNumBean); // test(flowNumBean);
//
//
} // }
} }
private void initMQ(){ private void initMQ(){
......
package com.mortals.xhx.tts.utils;
import com.mpatric.mp3agic.InvalidDataException;
import com.mpatric.mp3agic.Mp3File;
import com.mpatric.mp3agic.MpegFrame;
import com.mpatric.mp3agic.UnsupportedTagException;
import org.apache.commons.io.FileUtils;
import javax.sound.sampled.*;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.List;
/**
* @author ZYW
* @date 2024-08-23 9:19
*/
public class AddMp3Util {
public static String mergeMp3s( List<String> inputPaths) throws IOException{
String outputPath = "/tmp/";
if(System.getProperty("os.name").startsWith("Windows")){ //windows电脑测试路径
outputPath= "F:\\\\";
}
File file = new File(outputPath+"new.mp3");
if (file.exists()) {
file.delete();
}
FileOutputStream fos = new FileOutputStream(outputPath+"new.mp3");
byte[] buffer = new byte[4096];
int length;
for (String inputPath : inputPaths) {
ClassLoader classLoader = AddMp3Util.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(inputPath);
while ((length = inputStream.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
inputStream.close();
}
fos.close();
return outputPath+"new.mp3";
}
}
package com.mortals.xhx.tts.utils;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
/**
* @author ZYW
* @date 2024-08-26 10:50
*/
public class ResourceExporter {
public static void exportResource(String resourcePath, String outputPath) throws IOException {
// 获取资源作为输入流
try (InputStream inputStream = ResourceExporter.class.getClassLoader().getResourceAsStream(resourcePath)) {
// 判断资源是否存在
if (inputStream == null) {
throw new FileNotFoundException("Resource " + resourcePath + " not found");
}
// 输出路径转换为Path对象
Path outputDir = Paths.get(outputPath);
// 确保输出目录存在
Files.createDirectories(outputDir);
// 输出文件的完整路径
Path outputFile = outputDir.resolve(resourcePath);
// 将资源复制到输出文件
Files.copy(inputStream, outputFile, StandardCopyOption.REPLACE_EXISTING);
}
}
}
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