otherContent如果content内容是图片,存宽高
This commit is contained in:
@@ -21,35 +21,8 @@ public class BaiduVoicesUtils {
|
||||
// 填写申请百度语音申请的appkey 申请地址:百度AI开放平台
|
||||
private final static String appKey = "WOKN473V1o1gL8WMsAkfJZIY";
|
||||
private final static String secretKey = "CpgbKdB9aZu2esnq5lMdqRZG37Jn3a76";
|
||||
//http://aipe-speech.bj.bcebos.com/text_to_speech/2024-12-06/6752c65ee615a10001435c06/speech/0.null?authorization=bce-auth-v1%2FALTAKjI91nE52nvtDNRgFlUCVz%2F2024-12-06T09%3A41%3A51Z%2F259200%2F%2F08aed96bc0e5808a83c1a80ee3a925866a2a7ac5b017e29670fe7951f713bbf6
|
||||
|
||||
public static void main(String[] arg){
|
||||
try {
|
||||
System.out.println(new Date().getTime());
|
||||
// File audioFile = new File("F:\\111.wav");// 创建一个文件对象
|
||||
// AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(audioFile);// 获音频文件格式
|
||||
// float sampleRate = fileFormat.getFormat().getSampleRate();
|
||||
// int samplesizeInBits = fileFormat.getFormat().getSampleSizeInBits();
|
||||
// int aaa = fileFormat.getByteLength();
|
||||
// System.out.println("sampleRate: " + sampleRate);
|
||||
// System.out.println("samplesizeInBits: " + samplesizeInBits);
|
||||
// System.out.println("aaa: " + aaa);
|
||||
String text = "天地之道者 ,理也 ; 万物之始者 , 气也 ; 气之聚散者 , 象也; 物之终始者 ,数也 。为 医者尤需明理 ,理不明则法不清 , 法不清则 方药无凭 。 医之理者 ,病理也 , 然欲明病理 ,先知生理 ,故太湖无 中医基础理论课程而有生理 、病理 。生之理者 ,《 内经》 所谓人事 也 ,至于天人之学 , 尚需于太湖国学院求之 。经谓精光之论 , 大圣";
|
||||
// shortText("补充一点,桂枝的主要有效成分是挥发油,大概占桂枝 重量的0.7%左右,不到1%。桂枝挥发油有一个特点,它由呼 吸道排出,对呼吸道炎症有明显的抗炎、祛痰、止咳作用,所 以在麻黄汤里,桂枝既增强了麻黄的发汗作用,又增强了杏仁 的化痰止咳平喘作用。");
|
||||
// System.out.println(JacobUtil.toVoice(text));
|
||||
|
||||
// MP3File file = new MP3File("F:/a.mp3");
|
||||
// MP3AudioHeader audioHeader = (MP3AudioHeader)file.getAudioHeader();
|
||||
// int intLen = audioHeader.getTrackLength();
|
||||
// System.out.println(intLen);
|
||||
|
||||
System.out.println(new Date().getTime());
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//语音合并
|
||||
public static String mergeVoices(List<String> urls){
|
||||
try {
|
||||
File outFile = File.createTempFile(UUID.randomUUID().toString(),".mp3",new File("..\\"));
|
||||
|
||||
@@ -28,35 +28,24 @@ import java.util.UUID;
|
||||
//文字转语音离线工具,windows平台
|
||||
public class JacobUtil {
|
||||
|
||||
public static String toVoice(String text) {
|
||||
public static void toVoice(String text,File file) {
|
||||
try {
|
||||
//生成wav音频文件 直接生成MP3文件,获取不到文件头,转换一下才可以
|
||||
File wavFile = File.createTempFile(UUID.randomUUID().toString(),".wav",new File("..\\"));
|
||||
text(wavFile.getAbsolutePath(),text,100,0);
|
||||
//wav转mp3文件
|
||||
byte[] bytes = encodeToMp3(wavFile);
|
||||
File file = File.createTempFile(UUID.randomUUID().toString(),".mp3",new File("..\\"));
|
||||
FileCopyUtils.copy(bytes,file);
|
||||
|
||||
String fileUrl = uploadFile(file,".mp3");
|
||||
if (StringUtils.isNotBlank(fileUrl)){
|
||||
MP3File mp3File = new MP3File(file);
|
||||
MP3AudioHeader audioHeader = (MP3AudioHeader)mp3File.getAudioHeader();
|
||||
double intLen = audioHeader.getPreciseTrackLength();
|
||||
BigDecimal bd = new BigDecimal(intLen);
|
||||
bd = bd.setScale(4, BigDecimal.ROUND_HALF_UP);
|
||||
file.delete();
|
||||
fileUrl+=","+bd.toString();
|
||||
}
|
||||
file.delete();
|
||||
return fileUrl;
|
||||
wavFile.delete();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
//wav转mp3工具,在项目resources-lib下有jar包
|
||||
public static byte[] encodeToMp3(File wavFile) throws Exception {
|
||||
InputStream wavTestFileInputStream = new BufferedInputStream(new FileInputStream(wavFile));
|
||||
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(wavTestFileInputStream);
|
||||
// LameEncoder encoder = new LameEncoder(audioInputStream.getFormat(), 256, MPEGMode.STEREO, Lame.QUALITY_HIGHEST, false);
|
||||
LameEncoder encoder = new LameEncoder(audioInputStream.getFormat(), 128, MPEGMode.STEREO, Lame.QUALITY_HIGHEST, false);
|
||||
ByteArrayOutputStream mp3 = new ByteArrayOutputStream();
|
||||
byte[] inputBuffer = new byte[encoder.getPCMBufferSize()];
|
||||
@@ -70,27 +59,6 @@ public class JacobUtil {
|
||||
encoder.close();
|
||||
return mp3.toByteArray();
|
||||
}
|
||||
public static String uploadFile(File file, String fileName) {
|
||||
String endpoint = ConstantPropertiesUtils.END_POIND;
|
||||
String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID;
|
||||
String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET;
|
||||
String bucketName = ConstantPropertiesUtils.BUCKET_NAME;
|
||||
try {
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
fileName = uuid + fileName;
|
||||
String datePath = new DateTime().toString("yyyy/MM/dd");
|
||||
fileName = datePath + "/" + fileName;
|
||||
ossClient.putObject(bucketName, fileName, file);
|
||||
ossClient.shutdown();
|
||||
String url = "https://" + bucketName + "." + endpoint + "/" + fileName;
|
||||
return url;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean text(String path, String text, int volume, int speed) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user