|
@@ -3,14 +3,25 @@ package com.wj.utils;
|
|
|
import com.wj.DTO.RecordingInfo;
|
|
import com.wj.DTO.RecordingInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.bytedeco.javacpp.Loader;
|
|
import org.bytedeco.javacpp.Loader;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
|
|
+@Component
|
|
|
public class AudioTransferWavUtils {
|
|
public class AudioTransferWavUtils {
|
|
|
|
|
+ private static String audioSamplerRate;
|
|
|
|
|
+ private static String audioChannel;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ public void setMyProperty(@Value("${transfer.audio.samplerRate:8000}") String audioSamplerRateTemp,@Value("${transfer.audio.channel:1}") String audioChannelTemp) {
|
|
|
|
|
+ audioSamplerRate = audioSamplerRateTemp;
|
|
|
|
|
+ audioChannel = audioChannelTemp;
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 根据RecordingInfo信息转换音频为标准wav格式
|
|
* 根据RecordingInfo信息转换音频为标准wav格式
|
|
|
*
|
|
*
|
|
@@ -45,7 +56,7 @@ public class AudioTransferWavUtils {
|
|
|
public static Optional<String> transferWavStandard(String oldFilePath, String newFilePath) {
|
|
public static Optional<String> transferWavStandard(String oldFilePath, String newFilePath) {
|
|
|
String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class); // 加载ffmpeg
|
|
String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class); // 加载ffmpeg
|
|
|
ProcessBuilder transferBuilder = new ProcessBuilder(
|
|
ProcessBuilder transferBuilder = new ProcessBuilder(
|
|
|
- ffmpeg, "-i", oldFilePath, "-f", "wav", "-ar", "16000", "-ac", "1", "-y", newFilePath);
|
|
|
|
|
|
|
+ ffmpeg, "-i", oldFilePath, "-f", "wav", "-ar", audioSamplerRate, "-ac", audioChannel, "-y", newFilePath);
|
|
|
try {
|
|
try {
|
|
|
transferBuilder.inheritIO().start().waitFor(); // 执行转换命令
|
|
transferBuilder.inheritIO().start().waitFor(); // 执行转换命令
|
|
|
} catch (InterruptedException | IOException e) {
|
|
} catch (InterruptedException | IOException e) {
|